Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions browse/src/stealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ export function buildStealthScript(hw: HostProfile): string {
MAC: 'mac', OPENBSD: 'openbsd', WIN: 'win' },
RequestUpdateCheckStatus: { NO_UPDATE: 'no_update', THROTTLED: 'throttled',
UPDATE_AVAILABLE: 'update_available' },
connect: markNative(function connect() {
throw new TypeError('Error in invocation of runtime.connect: No matching signature.');
}, 'connect'),
sendMessage: markNative(function sendMessage() {
throw new TypeError('Error in invocation of runtime.sendMessage: No matching signature.');
}, 'sendMessage'),
// No connect/sendMessage here. Real Chrome only exposes callable
// chrome.runtime methods to a web page when an installed extension
// lists that origin in externally_connectable; on an ordinary page
// they are undefined. Faking them is itself an inconsistency, and
// sites that probe chrome.runtime.sendMessage to detect their own
// companion extension misfire (they assume the extension is
// installed and route auth through it). The enum shape alone
// satisfies the presence checks detectors actually run.
id: undefined,
};
}
Expand Down
20 changes: 15 additions & 5 deletions browse/test/stealth-layer-c.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,19 @@ describe('buildStealthScript — T3 Layer C', () => {
expect(s).toContain('PlatformArch');
expect(s).toContain('PlatformOs');
expect(s).toContain('RequestUpdateCheckStatus');
// sendMessage / connect must throw native-shaped errors
expect(s).toContain('runtime.connect');
expect(s).toContain('runtime.sendMessage');
});

test('window.chrome.runtime does NOT fake connect / sendMessage', () => {
// Real Chrome exposes callable runtime.connect / runtime.sendMessage to a
// web page only when an installed extension lists that origin in
// externally_connectable. On an ordinary page they are undefined, and
// sites probe `chrome.runtime.sendMessage` to detect their own companion
// extension — a fake makes them think it is installed.
const s = buildStealthScript(hw);
expect(s).not.toMatch(/\bconnect:\s*markNative/);
expect(s).not.toMatch(/\bsendMessage:\s*markNative/);
expect(s).not.toContain('runtime.sendMessage: No matching signature');
expect(s).not.toContain('runtime.connect: No matching signature');
});

test('chrome.csi and chrome.loadTimes provide method bodies', () => {
Expand Down Expand Up @@ -106,9 +116,9 @@ describe('buildStealthScript — T3 Layer C', () => {
// Every getter (hardwareConcurrency, deviceMemory, webdriver, Notification.permission)
// should be wrapped through markNative so the toString Proxy covers it.
const markNativeMatches = s.match(/markNative\(/g) || [];
// At least 8 markNative wrappings (webdriver, csi, loadTimes, connect, sendMessage,
// At least 6 markNative wrappings (webdriver, csi, loadTimes,
// notification permission, hwConcurrency, deviceMemory)
expect(markNativeMatches.length).toBeGreaterThanOrEqual(7);
expect(markNativeMatches.length).toBeGreaterThanOrEqual(6);
});

test('script does not include "GStackBrowser" branding string', () => {
Expand Down
19 changes: 12 additions & 7 deletions browse/test/stealth-webdriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,25 +170,30 @@ describe('applyStealth — context level', () => {
}
});

test('chrome.csi() and chrome.loadTimes() execute, runtime.connect() throws native-shaped', async () => {
test('chrome.csi() and chrome.loadTimes() execute; runtime.connect / sendMessage are absent', async () => {
// Presence (typeof === 'function') is not enough — a real detector calls
// them. loadTimes() dereferences performance.timing; connect() must throw
// the native "No matching signature" TypeError.
// them. loadTimes() dereferences performance.timing. runtime.connect and
// runtime.sendMessage must NOT exist: real Chrome only exposes them to a
// page when an installed extension declares that origin in
// externally_connectable, and sites use `chrome.runtime.sendMessage` to
// detect their own companion extension.
const page = await context.newPage();
try {
const r = await page.evaluate(() => {
const c = (window as any).chrome;
let connectErr = '';
try { c.runtime.connect(); } catch (e) { connectErr = String(e); }
return {
csiOk: typeof c.csi().onloadT === 'number',
loadTimesOk: typeof c.loadTimes().wasFetchedViaSpdy === 'boolean',
connectErr,
runtimePresent: typeof c.runtime === 'object',
connectType: typeof c.runtime.connect,
sendMessageType: typeof c.runtime.sendMessage,
};
});
expect(r.csiOk).toBe(true);
expect(r.loadTimesOk).toBe(true);
expect(r.connectErr).toContain('No matching signature');
expect(r.runtimePresent).toBe(true);
expect(r.connectType).toBe('undefined');
expect(r.sendMessageType).toBe('undefined');
} finally {
await page.close();
}
Expand Down