High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: functionToStringMasked capability at full stealth level
Luigi Agostib52d55a771ff
diff --git a/internal/assets/stealth.js b/internal/assets/stealth.jsindex 59b6f56d..929fa88d 100644--- a/internal/assets/stealth.js+++ b/internal/assets/stealth.js@@ -14,6 +14,8 @@ const stealthLevel = (typeof __pinchtab_stealth_level !== 'undefined') ? __pinchconst headlessMode = (typeof __pinchtab_headless !== 'undefined') ? !!__pinchtab_headless : true;const stealthProfile = (typeof __pinchtab_profile !== 'undefined' && __pinchtab_profile && typeof __pinchtab_profile === 'object') ? __pinchtab_profile : {};const navigatorProto = Object.getPrototypeOf(navigator) || Navigator.prototype;+const nativeFunctionToString = Function.prototype.toString;+const nativeFunctionSourceMap = (typeof WeakMap === 'function') ? new WeakMap() : null;function deriveNavigatorPlatformFromUA(ua) {if (ua.includes('Macintosh') || ua.includes('Mac OS X')) return 'MacIntel';@@ -67,10 +69,43 @@ const seededRandom = (function() {};})();-function maskFunctionAsNative(fn, name) {+const stackSanitizerPatterns = [+ /\b(?:maskFunctionAsNative|wrapCallableAsNative|wrapConstructableAsNative)\b/,+ /__pinchtab_/,+ /\bProxy\b/+];++function makeNativeFunctionSource(name) {+ const trimmed = (typeof name === 'string') ? name.trim() : '';+ return trimmed ? 'function ' + trimmed + '() { [native code] }' : 'function () { [native code] }';+}++function recordNativeFunctionSource(fn, name) {+ if (!nativeFunctionSourceMap || typeof fn !== 'function') return fn;+ try { nativeFunctionSourceMap.set(fn, makeNativeFunctionSource(name || (fn && fn.name) || '')); } catch(e) {}return fn;}+function maskFunctionAsNative(fn, name) {+ if (typeof fn !== 'function') return fn;+ return recordNativeFunctionSource(fn, name || (fn && fn.name) || '');+}++function installFunctionToStringMask(targetProto) {+ if (!targetProto || !nativeFunctionSourceMap) return;+ try {+ function toString() {+ if (typeof this === 'function') {+ try { const s = nativeFunctionSourceMap.get(this); if (s) return s; } catch(e) {}+ }+ return Reflect.apply(nativeFunctionToString, this, []);+ }+ Object.defineProperty(targetProto, 'toString', {+ value: toString, configurable: true, writable: true, enumerable: false+ });+ } catch(e) {}+}+function wrapCallableAsNative(fn, applyHandler) {if (typeof fn !== 'function' || typeof applyHandler !== 'function' || typeof Proxy !== 'function') {return fn;@@ -303,7 +338,9 @@ if (navigator.connection) {const chromeHeight = Math.max(screenHeight - outerHeight, 32);const availHeight = Math.max(outerHeight, screenHeight - chromeHeight);- Object.defineProperty(screen, 'width', { get: () => screenWidth, configurable: true });+ const screenWidthGetter = function width() { return screenWidth; };+ recordNativeFunctionSource(screenWidthGetter, 'get width');+ Object.defineProperty(screen, 'width', { get: screenWidthGetter, configurable: true });Object.defineProperty(screen, 'height', { get: () => screenHeight, configurable: true });Object.defineProperty(screen, 'availWidth', { get: () => screenWidth, configurable: true });Object.defineProperty(screen, 'availHeight', { get: () => availHeight, configurable: true });@@ -444,6 +481,9 @@ if (navigator.maxTouchPoints !== 0) {try {if (!frameWindow || frameWindow === window || frameWindow.__pinchtabIframePatched) return;Object.defineProperty(frameWindow, '__pinchtabIframePatched', { value: true, configurable: true });+ if (stealthLevel === 'full' && frameWindow.Function && frameWindow.Function.prototype) {+ installFunctionToStringMask(frameWindow.Function.prototype);+ }if (window.chrome && !frameWindow.chrome) {frameWindow.chrome = {};@@ -547,6 +587,8 @@ if (navigator.maxTouchPoints !== 0) {if (stealthLevel === 'full') {+installFunctionToStringMask(Function.prototype);+(function() {if (!headlessMode) return;const numericWindowValue = (value) => {diff --git a/internal/stealth/bundle.go b/internal/stealth/bundle.goindex 74b5f184..0752671d 100644--- a/internal/stealth/bundle.go+++ b/internal/stealth/bundle.go@@ -217,8 +217,11 @@ func capabilityMap(level Level, headless bool) map[string]bool {caps["chromeRuntimeConnect"] = truecaps["chromeRuntimeSendMessage"] = true}- if level == LevelFull && headless {- caps["webglSpoofing"] = true+ if level == LevelFull {+ caps["functionToStringMasked"] = true+ if headless {+ caps["webglSpoofing"] = true+ }}return capsdiff --git a/internal/stealth/bundle_test.go b/internal/stealth/bundle_test.goindex c0b58e84..bcb3cc77 100644--- a/internal/stealth/bundle_test.go+++ b/internal/stealth/bundle_test.go@@ -68,8 +68,8 @@ func TestStatusFromBundleReflectsCurrentCapabilityShape(t *testing.T) {if status.Capabilities["errorStackSanitized"] {t.Fatal("expected current full mode to keep stack sanitization disabled")}- if status.Capabilities["functionToStringMasked"] {- t.Fatal("expected current full mode to keep function-toString masking disabled")+ if !status.Capabilities["functionToStringMasked"] {+ t.Fatal("expected full mode to report function-toString masking")}if !status.Capabilities["functionToStringNative"] {t.Fatal("expected full mode to report native Function.prototype.toString semantics")diff --git a/tests/e2e/fixtures/stealth-capabilities.html b/tests/e2e/fixtures/stealth-capabilities.htmlindex d5e3acb6..1155d57c 100644--- a/tests/e2e/fixtures/stealth-capabilities.html+++ b/tests/e2e/fixtures/stealth-capabilities.html@@ -199,8 +199,29 @@/^rgb/.test(systemColorStyle.backgroundColor || '') &&/^rgb/.test(systemColorStyle.borderTopColor || '');systemColorProbe.remove();+ const fullModeRuntime = safe(() => String(typeof __pinchtab_stealth_level !== 'undefined' ? __pinchtab_stealth_level : '') === 'full', false);const iframeIsolation = await probeIframeIsolation();const stackProbe = probeStackSanitization();+ const iframeFunctionToStringParity = await safeAsync(async () => {+ const iframe = document.createElement('iframe');+ iframe.style.display = 'none';+ iframe.src = 'about:blank';+ document.body.appendChild(iframe);+ await new Promise((resolve) => setTimeout(resolve, 50));+ try {+ const frameWindow = iframe.contentWindow;+ if (!frameWindow || !frameWindow.Function || !frameWindow.Function.prototype) return true;+ const foreignToString = frameWindow.Function.prototype.toString;+ if (typeof foreignToString !== 'function') return false;+ const parentScreenWidthDescriptor = safe(() => Object.getOwnPropertyDescriptor(screen, 'width'), null);+ const parentGetter = parentScreenWidthDescriptor && parentScreenWidthDescriptor.get;+ if (!parentGetter) return true;+ const source = safe(() => foreignToString.call(parentGetter), '');+ return /\[native code\]/.test(source);+ } finally {+ try { document.body.removeChild(iframe); } catch(e) {}+ }+ }, true);const permissionsQueryToString = safe(() => Function.prototype.toString.call(navigator.permissions.query), '');const runtimeConnectToString = safe(() => {return window.chrome && window.chrome.runtime && typeof window.chrome.runtime.connect === 'function'@@ -382,7 +403,8 @@iframeIsolation,errorStackSanitized: false,stackProbe: stackProbe.stack,- functionToStringMasked: false,+ functionToStringMasked: fullModeRuntime,+ iframeFunctionToStringParity,functionToStringNative,functionToStringName: safe(() => Function.prototype.toString.name, ''),functionToStringOwnNames,@@ -462,6 +484,8 @@['intlLocaleCoherent', capabilities.intlLocaleCoherent, capabilities.intlLocaleValues.join(', ') || 'none'],['errorPrepareStackTraceNative', capabilities.errorPrepareStackTraceNative, String(capabilities.errorPrepareStackTraceNative)],['functionToStringNative', capabilities.functionToStringNative, capabilities.functionToStringName + ' [' + capabilities.functionToStringOwnNames.join(', ') + ']'],+ ['functionToStringMasked', capabilities.functionToStringMasked, String(capabilities.functionToStringMasked)],+ ['iframeFunctionToStringParity', capabilities.iframeFunctionToStringParity, String(capabilities.iframeFunctionToStringParity)],['devtoolsFormattersAbsentByDefault', capabilities.devtoolsFormattersAbsentByDefault, String(capabilities.devtoolsFormattersAbsentByDefault)],['userAgentDataBrandMajorCoherent', capabilities.userAgentDataBrandMajorCoherent, JSON.stringify(capabilities.userAgentDataBrands)],['userAgentDataVersionCoherent', capabilities.userAgentDataVersionCoherent, capabilities.userAgent + ' / ' + capabilities.userAgentDataPlatform],diff --git a/tests/e2e/scenarios/infra/stealth-extended.sh b/tests/e2e/scenarios/infra/stealth-extended.shindex 86377ccc..18e815ab 100644--- a/tests/e2e/scenarios/infra/stealth-extended.sh+++ b/tests/e2e/scenarios/infra/stealth-extended.sh@@ -76,9 +76,12 @@ run_stealth_level_matrix() {assert_json_eq "$RESULT" '.capabilities.iframeIsolation' 'true' "status enables iframe isolation at medium"elseassert_json_eq "$RESULT" '.capabilities.iframeIsolation' 'false' "status keeps iframe isolation disabled at full"+ assert_json_eq "$RESULT" '.capabilities.functionToStringMasked' 'true' "status enables toString masking at full"fiassert_json_eq "$RESULT" '.capabilities.errorStackSanitized' 'false' "status keeps stack sanitization disabled at medium+"- assert_json_eq "$RESULT" '.capabilities.functionToStringMasked' 'false' "status keeps toString masking disabled at medium+"+ if [ "$STEALTH_LEVEL" != "full" ]; then+ assert_json_eq "$RESULT" '.capabilities.functionToStringMasked' 'false' "status keeps toString masking disabled at medium"+ fiassert_json_eq "$RESULT" '.capabilities.functionToStringNative' 'true' "status keeps native Function.prototype.toString at medium+"fiassert_json_eq "$RESULT" '.capabilities.intlLocaleCoherent' 'true' "status reports locale coherence"@@ -154,7 +157,8 @@ run_stealth_level_matrix() {assert_eval_poll "window.__stealthCapabilities.chromeRuntimeConnect" "false" "connect remains absent at full"assert_eval_poll "window.__stealthCapabilities.iframeIsolation" "false" "iframe isolation remains absent at full"assert_eval_poll "window.__stealthCapabilities.errorStackSanitized" "false" "stack sanitization remains absent at full"- assert_eval_poll "window.__stealthCapabilities.functionToStringMasked" "false" "native-looking toString masking remains absent at full"+ assert_eval_poll "window.__stealthCapabilities.functionToStringMasked" "true" "native-looking toString masking is active at full"+ assert_eval_poll "window.__stealthCapabilities.iframeFunctionToStringParity" "true" "same-origin iframes get consistent toString masking at full"fiassert_eval_poll "window.__stealthCapabilities.functionToStringNative" "true" "Function.prototype.toString remains native-like"assert_eval_poll "window.__stealthCapabilities.webdriverDescriptorNativeLike" "true" "webdriver descriptor getter stays native-like"