mirror of
https://github.com/garrytan/gstack.git
synced 2026-07-07 00:27:56 +02:00
66e1f44a86
Brings the branch up to date with main (v1.40.0.2 -> v1.58.1.0). Conflict resolutions: - VERSION: take main's 1.58.1.0 (branch re-bumps at /ship time). - CHANGELOG.md: keep main's full history; slot the branch's unique v1.40.0.2 entry into descending-order position (no content lost). - browse/src/browser-manager.ts: keep main's GSTACK_CHROMIUM_NO_SANDBOX override and onDisconnect(exitCode) signature; branch's buildGStackLaunchArgs / STEALTH_IGNORE_DEFAULT_ARGS wiring preserved. - browse/test/browser-manager-unit.test.ts: keep main's override + exit-code propagation tests alongside the branch's Cmd+Q cause-resolver tests. - browse/src/stealth.ts: blend the two stealth designs. Layer C (buildStealthScript) is the always-on consistency-first default; main's GSTACK_STEALTH=extended (EXTENDED_STEALTH_SCRIPT) remains an opt-in layer applied on top. Both public APIs and both test suites (stealth-layer-c + stealth-extended) preserved; the two applyStealth wiring assertions updated to reflect the Layer C default. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
123 lines
4.5 KiB
TypeScript
123 lines
4.5 KiB
TypeScript
/**
|
|
* Tests for the opt-in extended stealth mode (#1112 rebased into the
|
|
* v1.41 wave).
|
|
*
|
|
* Pins:
|
|
* 1. Default mode applies the always-on Layer C stealth script (and NOT
|
|
* the extended script) — the consistency-first default.
|
|
* 2. GSTACK_STEALTH=extended adds EXTENDED_STEALTH_SCRIPT on top of Layer C.
|
|
* 3. EXTENDED_STEALTH_SCRIPT contains the six detection-vector patches.
|
|
* 4. Apply order: Layer C first, extended second (so the extended
|
|
* delete-from-prototype path layers on top of Layer C's getter without
|
|
* silently overriding it if delete fails).
|
|
*
|
|
* Live SannySoft pass-rate verification is a periodic-tier E2E test
|
|
* (gated behind external network + Chromium); this file pins the
|
|
* static + applyStealth semantics that run on every commit.
|
|
*/
|
|
|
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
import {
|
|
EXTENDED_STEALTH_SCRIPT,
|
|
isExtendedStealthEnabled,
|
|
applyStealth,
|
|
} from '../src/stealth';
|
|
|
|
let originalEnv: string | undefined;
|
|
|
|
beforeEach(() => {
|
|
originalEnv = process.env.GSTACK_STEALTH;
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (originalEnv === undefined) delete process.env.GSTACK_STEALTH;
|
|
else process.env.GSTACK_STEALTH = originalEnv;
|
|
});
|
|
|
|
describe('extended stealth — opt-in mode flag', () => {
|
|
test('default mode is OFF (consistency-first contract)', () => {
|
|
delete process.env.GSTACK_STEALTH;
|
|
expect(isExtendedStealthEnabled()).toBe(false);
|
|
});
|
|
|
|
test('GSTACK_STEALTH=extended enables extended mode', () => {
|
|
process.env.GSTACK_STEALTH = 'extended';
|
|
expect(isExtendedStealthEnabled()).toBe(true);
|
|
});
|
|
|
|
test('GSTACK_STEALTH=1 also enables (env-style boolean)', () => {
|
|
process.env.GSTACK_STEALTH = '1';
|
|
expect(isExtendedStealthEnabled()).toBe(true);
|
|
});
|
|
|
|
test('GSTACK_STEALTH=anything-else does NOT enable', () => {
|
|
process.env.GSTACK_STEALTH = 'verbose';
|
|
expect(isExtendedStealthEnabled()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('EXTENDED_STEALTH_SCRIPT — six detection-vector patches', () => {
|
|
test('1. deletes navigator.webdriver from prototype', () => {
|
|
expect(EXTENDED_STEALTH_SCRIPT).toMatch(/delete.*Object\.getPrototypeOf\(navigator\)\.webdriver/);
|
|
});
|
|
|
|
test('2. spoofs WebGL renderer to Apple M1 Pro', () => {
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('Apple M1 Pro');
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('UNMASKED_VENDOR_WEBGL');
|
|
});
|
|
|
|
test('3. installs PluginArray-prototype-passing navigator.plugins', () => {
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('PluginArray');
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('MimeType');
|
|
});
|
|
|
|
test('4. populates window.chrome with app, runtime, loadTimes, csi', () => {
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('chrome.app');
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('chrome.runtime');
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('chrome.loadTimes');
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('chrome.csi');
|
|
});
|
|
|
|
test('5. backfills navigator.mediaDevices when missing', () => {
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('mediaDevices');
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain('enumerateDevices');
|
|
});
|
|
|
|
test('6. clears CDP cdc_* property names from window', () => {
|
|
expect(EXTENDED_STEALTH_SCRIPT).toContain("startsWith('cdc_')");
|
|
});
|
|
});
|
|
|
|
describe('applyStealth — script wiring', () => {
|
|
test('default mode applies ONLY the Layer C script (not extended)', async () => {
|
|
delete process.env.GSTACK_STEALTH;
|
|
const calls: string[] = [];
|
|
const fakeCtx = {
|
|
addInitScript: async (opts: { content: string }) => {
|
|
calls.push(opts.content);
|
|
},
|
|
} as unknown as Parameters<typeof applyStealth>[0];
|
|
await applyStealth(fakeCtx);
|
|
expect(calls).toHaveLength(1);
|
|
// Layer C signatures: toString-proxy native-code lie + webdriver mask.
|
|
expect(calls[0]).toContain('[native code]');
|
|
expect(calls[0]).toContain('webdriver');
|
|
expect(calls[0]).not.toBe(EXTENDED_STEALTH_SCRIPT);
|
|
});
|
|
|
|
test('extended mode applies BOTH scripts in order (Layer C first, extended second)', async () => {
|
|
process.env.GSTACK_STEALTH = 'extended';
|
|
const calls: string[] = [];
|
|
const fakeCtx = {
|
|
addInitScript: async (opts: { content: string }) => {
|
|
calls.push(opts.content);
|
|
},
|
|
} as unknown as Parameters<typeof applyStealth>[0];
|
|
await applyStealth(fakeCtx);
|
|
expect(calls).toHaveLength(2);
|
|
// Layer C first (its native-code lie), extended second.
|
|
expect(calls[0]).toContain('[native code]');
|
|
expect(calls[1]).toBe(EXTENDED_STEALTH_SCRIPT);
|
|
});
|
|
});
|