capjs-core 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/package.json +5 -2
- package/src/agents.js +700 -0
- package/src/behavior.js +437 -0
- package/src/detect.js +189 -8
- package/src/hashwx-wasm.js +1 -5
- package/src/index.d.ts +198 -43
- package/src/index.js +298 -67
- package/src/instrumentation.js +742 -116
- package/src/rsw.js +13 -5
package/src/instrumentation.js
CHANGED
|
@@ -87,7 +87,7 @@ function domSumMock(x, y, z) {
|
|
|
87
87
|
let cur = parent;
|
|
88
88
|
let v = val;
|
|
89
89
|
for (let i = 0; i < 8; i++) {
|
|
90
|
-
const child = { parentNode: cur,
|
|
90
|
+
const child = { parentNode: cur, textContent: String(v) };
|
|
91
91
|
if ((v & 1) === 0) cur = child;
|
|
92
92
|
v = v >> 1;
|
|
93
93
|
}
|
|
@@ -96,7 +96,7 @@ function domSumMock(x, y, z) {
|
|
|
96
96
|
|
|
97
97
|
function walk(node, rootRef, sum) {
|
|
98
98
|
if (!node || node === rootRef) return sum % 256;
|
|
99
|
-
return walk(node.parentNode, rootRef, sum + parseInt(node.
|
|
99
|
+
return walk(node.parentNode, rootRef, sum + parseInt(node.textContent, 10));
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
return toInt32(
|
|
@@ -137,6 +137,27 @@ const WINDOW_PROP_MARKERS = [
|
|
|
137
137
|
"nightmare",
|
|
138
138
|
"__playwright__binding__",
|
|
139
139
|
"__pwInitScripts",
|
|
140
|
+
"setFontSpacingSeed",
|
|
141
|
+
"setAudioFingerprintSeed",
|
|
142
|
+
"setScreenDimensions",
|
|
143
|
+
"setScreenColorDepth",
|
|
144
|
+
"setNavigatorPlatform",
|
|
145
|
+
"setNavigatorOscpu",
|
|
146
|
+
"setNavigatorHardwareConcurrency",
|
|
147
|
+
"setWebGLVendor",
|
|
148
|
+
"setWebGLRenderer",
|
|
149
|
+
"setFontList",
|
|
150
|
+
"setSpeechVoices",
|
|
151
|
+
"setWebRTCIPv4",
|
|
152
|
+
"__playwright__binding__controller__",
|
|
153
|
+
"__playwright_builtins__",
|
|
154
|
+
"__pwWebSocketDispatch",
|
|
155
|
+
"__playwright_mark_target__",
|
|
156
|
+
"callPuppeteer",
|
|
157
|
+
"callSelenium",
|
|
158
|
+
"__phantomas",
|
|
159
|
+
"__stagehandV3__",
|
|
160
|
+
"__stagehandV3Injected",
|
|
140
161
|
];
|
|
141
162
|
const DOC_PROP_MARKERS = [
|
|
142
163
|
"__selenium_evaluate",
|
|
@@ -180,6 +201,127 @@ const UA_TOKEN_MARKERS = [
|
|
|
180
201
|
"SlimerJS",
|
|
181
202
|
"headless",
|
|
182
203
|
];
|
|
204
|
+
const AGENT_MARKS = [
|
|
205
|
+
[
|
|
206
|
+
"cic_active",
|
|
207
|
+
"#claude-agent-glow-border,#claude-agent-stop-container,#claude-phantom-cursor,#claude-cursor-layer",
|
|
208
|
+
null,
|
|
209
|
+
],
|
|
210
|
+
["cic_shared", "#claude-static-indicator-container", null],
|
|
211
|
+
[
|
|
212
|
+
"browser_use",
|
|
213
|
+
"#browser-use-debug-highlights,[data-browser-use-highlight],[data-browser-use-interaction-highlight],[data-browser-use-coordinate-highlight],#playwright-highlight-container,[browser-user-highlight-id],#browser-use-demo-panel",
|
|
214
|
+
["__browserUseDemoPanelLoaded"],
|
|
215
|
+
],
|
|
216
|
+
["cic_legacy", "#claude-agent-animation-styles", null],
|
|
217
|
+
[
|
|
218
|
+
"codex",
|
|
219
|
+
"#codex-agent-overlay-root,#codex-browser-sidebar-comments-root",
|
|
220
|
+
null,
|
|
221
|
+
],
|
|
222
|
+
["browserflow", "#browserflow-container,.browserflow-container", null],
|
|
223
|
+
[
|
|
224
|
+
"thunderbit",
|
|
225
|
+
"#thunderbit-crx-scout-overlay,#thunderbit-crx-side-bar",
|
|
226
|
+
null,
|
|
227
|
+
],
|
|
228
|
+
[
|
|
229
|
+
"fellou",
|
|
230
|
+
"#eko-highlight-container",
|
|
231
|
+
["__FELLOU_TAB_ID__", "FELLOU_PARTITION", "FELLOU_WEBVIEW_PRELOAD_PATH"],
|
|
232
|
+
],
|
|
233
|
+
[
|
|
234
|
+
"stagehand",
|
|
235
|
+
"#__v3_cursor_overlay__,[data-stagehand-mask]",
|
|
236
|
+
["__stagehandV3__", "__stagehandV3Injected"],
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
"twocaptcha",
|
|
240
|
+
"head > captcha-widgets",
|
|
241
|
+
["registerCaptchaWidget", "isCaptchaWidgetRegistered"],
|
|
242
|
+
],
|
|
243
|
+
["comet", "#pplx-agent-overlay-stop-button", null],
|
|
244
|
+
[
|
|
245
|
+
"genspark",
|
|
246
|
+
"#genspark-float-bar,#gs-overlay-cursor-style",
|
|
247
|
+
["navigator.genspark"],
|
|
248
|
+
],
|
|
249
|
+
["sigma", null, ["__SIGMA__"]],
|
|
250
|
+
["manus", "#manus-action-mask-host", ["__manusOriginalPostMessage"]],
|
|
251
|
+
["antigravity", "html[data-jetski-tab-id]", null],
|
|
252
|
+
["cursor", null, ["__cursorDialogConfig"]],
|
|
253
|
+
["rtrvr", "[rtrvr-mw-host-id],html[rtrvr-mw-busy]", null],
|
|
254
|
+
[
|
|
255
|
+
"rtrvr_installed",
|
|
256
|
+
"html[rtrvr-mw-ready]",
|
|
257
|
+
["__RTRVR_MAIN_WORLD_INITIALIZED__"],
|
|
258
|
+
],
|
|
259
|
+
["harpa_installed", "html > __hrp__", ["__hrp_globals"]],
|
|
260
|
+
["monica", "#monica-action-mask-host", null],
|
|
261
|
+
["monica_installed", "#monica-content-root", null],
|
|
262
|
+
["sider", "#sider-agent-glow-border", null],
|
|
263
|
+
["sider_installed", "chatgpt-sidebar", null],
|
|
264
|
+
[
|
|
265
|
+
"maxai_installed",
|
|
266
|
+
"#USE_CHAT_GPT_AI_ROOT,max-ai-minimum-app",
|
|
267
|
+
["__MAXAI__EXTENSION__VERSION__"],
|
|
268
|
+
],
|
|
269
|
+
["nova_act", "[nova-act-id]", null],
|
|
270
|
+
["agentql", "[tf623_id]", null],
|
|
271
|
+
[
|
|
272
|
+
"hyperagent",
|
|
273
|
+
null,
|
|
274
|
+
[
|
|
275
|
+
"__hyperagent_getScrollableElementXpaths",
|
|
276
|
+
"__hyperagent_collectBoundingBoxes",
|
|
277
|
+
],
|
|
278
|
+
],
|
|
279
|
+
[
|
|
280
|
+
"agent_browser",
|
|
281
|
+
"[data-agent-browser-located],#__agent_browser_annotations__,agent-browser-recording-cursor,[data-__ab-ci]",
|
|
282
|
+
null,
|
|
283
|
+
],
|
|
284
|
+
[
|
|
285
|
+
"do_browser",
|
|
286
|
+
"#redo-active-glow,#redo-active-glow-style",
|
|
287
|
+
["__redoGlowState"],
|
|
288
|
+
],
|
|
289
|
+
["nanobrowser", "[data-nanobrowser-border]", null],
|
|
290
|
+
["dassi", "#dassi-neon-overlay-root", null],
|
|
291
|
+
[
|
|
292
|
+
"kimi",
|
|
293
|
+
"#kimi-webbridge-agent-visuals,link[data-wb-cursor]",
|
|
294
|
+
["__kimiWebBridgeVisuals"],
|
|
295
|
+
],
|
|
296
|
+
[
|
|
297
|
+
"magnitude",
|
|
298
|
+
"style[data-cursor-effects],style[data-type-effects]",
|
|
299
|
+
["__mouseEffectsInitialized", "__typeEffectsInitialized"],
|
|
300
|
+
],
|
|
301
|
+
["lavague", ".lavague-highlight", null],
|
|
302
|
+
["kernel", null, ["__kernelEventInjected"]],
|
|
303
|
+
[
|
|
304
|
+
"skyvern",
|
|
305
|
+
"[data-skyvern-otp-box],#boundingBoxContainer",
|
|
306
|
+
[
|
|
307
|
+
"GlobalSkyvernFrameIndex",
|
|
308
|
+
"globalDomDepthMap",
|
|
309
|
+
"globalParsedElementCounter",
|
|
310
|
+
],
|
|
311
|
+
],
|
|
312
|
+
];
|
|
313
|
+
const MARK_ATTRS = {
|
|
314
|
+
"data-__ab-ci": "agent_browser",
|
|
315
|
+
"nova-act-id": "nova_act",
|
|
316
|
+
tf623_id: "agentql",
|
|
317
|
+
"rtrvr-mw-host-id": "rtrvr",
|
|
318
|
+
"rtrvr-mw-busy": "rtrvr",
|
|
319
|
+
"data-nanobrowser-border": "nanobrowser",
|
|
320
|
+
"data-jetski-tab-id": "antigravity",
|
|
321
|
+
};
|
|
322
|
+
const SENSITIVE_FIELDS =
|
|
323
|
+
'input[type="password"],[autocomplete~="one-time-code"],[autocomplete~="current-password"],[autocomplete~="new-password"],[autocomplete^="cc-"]';
|
|
324
|
+
const MAX_BOUND_CODES = 32;
|
|
183
325
|
const WEBGL_VENDOR_MARKER = "Brian Paul";
|
|
184
326
|
const WEBGL_RENDERER_MARKER = "Mesa OffScreen";
|
|
185
327
|
const PRODUCTSUB_GECKO = "20030107";
|
|
@@ -223,13 +365,25 @@ function buildProbe(P) {
|
|
|
223
365
|
`${sf}("outerWH",function(){return [outerWidth,outerHeight]});`,
|
|
224
366
|
`${sf}("isExtended",function(){return screen.isExtended===undefined?null:screen.isExtended});`,
|
|
225
367
|
`${sf}("fontWidths",function(){var sp=document.createElement("span");sp.style.cssText="position:absolute;left:-9999px;top:-9999px;font-size:72px;white-space:nowrap";sp.textContent="mmmmmmmmmmlli WwWwGg @#Xj";document.body.appendChild(sp);var st=${JSON.stringify(PROBE_FONT_STACKS)};var out=[];for(var i=0;i<st.length;i++){sp.style.fontFamily=st[i];out.push(Math.round(sp.getBoundingClientRect().width*100)/100)}document.body.removeChild(sp);return out});`,
|
|
368
|
+
`${sf}("maxTouchPoints",function(){return navigator.maxTouchPoints});`,
|
|
369
|
+
`${sf}("juggler",function(){if(typeof window.mozInnerScreenX!=="number")return null;try{var w=new Worker("chrome://juggler/content");try{w.terminate()}catch(e){}return true}catch(e){return false}});`,
|
|
370
|
+
`${sf}("evalLen",function(){return Function.prototype.toString.call(eval).length});`,
|
|
371
|
+
`${sf}("langs",function(){var l=navigator.languages||[];return [l.length,l[0]===navigator.language]});`,
|
|
372
|
+
`${sf}("activeText",function(){var d=document.createElement("div");d.style.setProperty("color-scheme","light","important");d.style.setProperty("color","ActiveText","important");document.body.appendChild(d);var c=getComputedStyle(d).color;d.remove();return [c,matchMedia("(forced-colors: active)").matches]});`,
|
|
373
|
+
`${sf}("stealth",function(){var f=document.createElement("iframe");f.srcdoc="x";var r=window.chrome&&window.chrome.runtime;var m=r&&r.sendMessage;return {iframe:!!f.contentWindow,runtime:typeof m==="function"&&Object.prototype.hasOwnProperty.call(m,"prototype")}});`,
|
|
374
|
+
`${sf}("lies",function(){var out=[],g=function(o,k){var d=o&&Object.getOwnPropertyDescriptor(o,k);return d&&d.get},N=Navigator.prototype,list=[["webdriver",g(N,"webdriver")],["languages",g(N,"languages")],["plugins",g(N,"plugins")],["hardwareConcurrency",g(N,"hardwareConcurrency")],["vendor",g(N,"vendor")],["platform",g(N,"platform")],["userAgent",g(N,"userAgent")],["permissionsQuery",window.Permissions&&Permissions.prototype.query],["getParameter",window.WebGLRenderingContext&&WebGLRenderingContext.prototype.getParameter],["canPlayType",HTMLMediaElement.prototype.canPlayType],["fnToString",Function.prototype.toString],["contentWindow",g(HTMLIFrameElement.prototype,"contentWindow")]];for(var i=0;i<list.length;i++){var f=list[i][1];if(typeof f!=="function")continue;var bad=Object.prototype.hasOwnProperty.call(f,"prototype")||Object.getOwnPropertyNames(f).sort().join()!=="length,name";if(!bad){var pr=Object.getPrototypeOf(f);try{Object.setPrototypeOf(f,Object.create(f));bad=true}catch(e){}finally{try{Object.setPrototypeOf(f,pr)}catch(e){}}}if(bad)out.push(list[i][0])}return out});`,
|
|
226
375
|
`${sf}("tamper",function(){return {getParameterWebGL:${nat}(WebGLRenderingContext.prototype.getParameter),toDataURL:${nat}(HTMLCanvasElement.prototype.toDataURL),getImageData:${nat}(CanvasRenderingContext2D.prototype.getImageData),permissionsQuery:navigator.permissions?${nat}(navigator.permissions.query):true,fnToString:${nat}(Function.prototype.toString)}});`,
|
|
227
376
|
];
|
|
228
377
|
shuffle(fields);
|
|
378
|
+
const nv = rVar();
|
|
379
|
+
const collect = `function(){var n=navigator,tz=null,b=null;try{tz=Intl.DateTimeFormat().resolvedOptions().timeZone}catch(e){}try{b=n.userAgentData?n.userAgentData.brands.map(function(x){return x.brand+"/"+x.version}).join(","):null}catch(e){}var gl=null;try{var c=new OffscreenCanvas(1,1).getContext("webgl");if(c){var x=c.getExtension("WEBGL_debug_renderer_info");gl=x?c.getParameter(x.UNMASKED_RENDERER_WEBGL):null;var lc=c.getExtension("WEBGL_lose_context");if(lc)lc.loseContext()}}catch(e){}return {ua:n.userAgent,platform:n.platform,languages:(n.languages||[]).join(","),hc:n.hardwareConcurrency,tz:tz,brands:b,brave:!!n.brave,gl:gl}}`;
|
|
229
380
|
return (
|
|
230
381
|
`var ${P}={};function ${sf}(k,f){try{${P}[k]=f()}catch(e){${P}[k]=null}}` +
|
|
231
382
|
`function ${nat}(fn){try{return /\\{\\s*\\[native code\\]\\s*\\}/.test(Function.prototype.toString.call(fn))}catch(e){return true}}` +
|
|
232
|
-
fields.join("")
|
|
383
|
+
fields.join("") +
|
|
384
|
+
`var ${nv}=${collect};${sf}("mainNav",${nv});` +
|
|
385
|
+
`${P}.hev=await new Promise(function(r){var u=navigator.userAgentData;if(!u||!u.getHighEntropyValues){r(null);return}var t=setTimeout(function(){r(null)},1000);u.getHighEntropyValues(["platformVersion","architecture","uaFullVersion","bitness","fullVersionList"]).then(function(v){clearTimeout(t);r({pv:v.platformVersion||"",ar:v.architecture||"",fv:v.uaFullVersion||"",bi:v.bitness||"",fl:(v.fullVersionList||[]).map(function(x){return x.brand}).join(",")})},function(){clearTimeout(t);r(null)})});` +
|
|
386
|
+
`${P}.workerNav=await new Promise(function(r){var w,t,u;function d(v){clearTimeout(t);try{if(w)w.terminate()}catch(x){}try{if(u)URL.revokeObjectURL(u)}catch(x){}r(v)}try{u=URL.createObjectURL(new Blob([${JSON.stringify(`postMessage((${collect})())`)}],{type:"text/javascript"}));w=new Worker(u)}catch(e){d(null);return}t=setTimeout(function(){d(null)},1500);w.onmessage=function(e){d(e.data&&typeof e.data==="object"?e.data:null)};w.onerror=function(){d(null)}});`
|
|
233
387
|
);
|
|
234
388
|
}
|
|
235
389
|
|
|
@@ -365,9 +519,129 @@ function buildBlockChecks(b, id, hF, hSet, h) {
|
|
|
365
519
|
}
|
|
366
520
|
|
|
367
521
|
shuffle(checks);
|
|
368
|
-
const sampled = checks.slice(0, Math.min(checks.length, 8));
|
|
369
522
|
|
|
370
|
-
return `let ${b} = false;try {${
|
|
523
|
+
return `let ${b} = false;try {${checks.join("")}} catch {${b} = true} if (${b}) {parent.postMessage({ type: 'cap:instr', nonce: ${JSON.stringify(id)}, result: '', blocked: true }, '*');return;}`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const CDP_PROBE = `function(E,C,w,n){var p=0,k=0,e,s=Object.getOwnPropertyDescriptor(E,"prepareStackTrace");if(!s||s.configurable){Object.defineProperty(E,"prepareStackTrace",{configurable:true,writable:true,value:function(x){if(x===e)p++;return String(x)}});try{for(var i=0;i<3;i++){e=new E("x");C.debug(e)}}finally{if(s)Object.defineProperty(E,"prepareStackTrace",s);else delete E.prepareStackTrace}}var X=class extends E{get name(){k++;return "Error"}};for(var j=0;j<3;j++)C.debug(new X("x"));return p>0||(k>6&&(typeof w.chrome!=="undefined"||!!n.userAgentData))}`;
|
|
527
|
+
|
|
528
|
+
const COLLECTOR_HEAD = `function($W,$F,$cfg,$cdp){
|
|
529
|
+
var $ap=Reflect.apply,$gopd=Object.getOwnPropertyDescriptor,$ael=$F.EventTarget.prototype.addEventListener,$rel0=$F.EventTarget.prototype.removeEventListener,$fnow=$F.Performance.prototype.now;
|
|
530
|
+
var $gets={};["performance","innerWidth","innerHeight"].forEach(function($k){try{var $d=$gopd($F,$k)||$gopd($F.Window.prototype,$k);if($d&&$d.get)$gets[$k]=$d.get}catch($x){}});
|
|
531
|
+
var $read=function($o,$k){try{return $o[$k]}catch($x){}try{if($gets[$k])return $ap($gets[$k],$o,[])}catch($x){}return null};
|
|
532
|
+
var $D=$W.document,$perf=$read($W,"performance"),$offs=[],$seen=[],$opt={capture:true,passive:true},$mo=null,$io=null,$ia=null,$trace=null;
|
|
533
|
+
var $pnow=function(){try{return $ap($fnow,$perf,[])}catch($x){return $ap($fnow,$F.performance,[])}};
|
|
534
|
+
var $origin=$pnow();
|
|
535
|
+
var $on=function($t,$y,$f,$o){var $p=$o||$opt;$ap($ael,$t,[$y,$f,$p]);$offs.push(function(){$ap($rel0,$t,[$y,$f,$p])})};
|
|
536
|
+
var $mark=function($c){if($seen.indexOf($c)<0)$seen.push($c)};
|
|
537
|
+
var $scan=function($r){for(var $i=0;$i<$cfg.marks.length;$i++){var $m=$cfg.marks[$i];if($seen.indexOf($m[0])>=0)continue;try{if(($m[1]&&(($r.matches&&$r.matches($m[1]))||($r.querySelector&&$r.querySelector($m[1]))))||($m[2]&&$m[2].some(function($g){return $g.indexOf("navigator.")===0?$g.slice(10) in $W.navigator:$g in $W})))$mark($m[0])}catch($e){}}};
|
|
538
|
+
var $comet=function(){try{var $h=$D.body||$D.documentElement;if($seen.indexOf("comet")>=0||!$h)return;var $d=$D.createElement("div");$d.id="pplx-agent-0_0-overlay-stop-button";$d.style.cssText="position:absolute;left:-99999px;visibility:hidden";$h.appendChild($d);var $s=$W.getComputedStyle($d);if($s.zIndex==="2147483647"&&$s.minHeight==="32px")$mark("comet");$d.remove()}catch($e){}};
|
|
539
|
+
var $sens=function($e){try{var $t=$e.composedPath()[0];return !!($t&&$t.closest&&$t.closest($cfg.sens))}catch($x){return false}};
|
|
540
|
+
if($cfg.ia){try{var $cnt=[0,0];var $syn=function($e){if($e.isTrusted||$sens($e))return;if($e.type==="click")$cnt[0]=Math.min(255,$cnt[0]+1);else $cnt[1]=Math.min(255,$cnt[1]+1)};$on($W,"click",$syn);$on($W,"keydown",$syn);$ia=$cnt}catch($x){$ia=null}}
|
|
541
|
+
`;
|
|
542
|
+
|
|
543
|
+
const COLLECTOR_TRACE = `if($cfg.bh){try{$trace=(function(){
|
|
544
|
+
var $moves=[],$keys=[],$open=new Map(),$recent=[],$n=[0,0,0,0,0,0,0,0,0,0,0],$lastKey=-Infinity,$shift=false,$lsi=-Infinity,$ls=-Infinity,$us=-1,$sx=$W.scrollX,$sy=$W.scrollY,$act=null,$vis=-1,$press=null,$pt={mouse:0,pen:1,touch:2};
|
|
545
|
+
var $rel=function($t){return Math.max(0,Math.round(($t-$origin)*10)/10)};
|
|
546
|
+
var $r1=function($x){return Math.round($x*10)/10};
|
|
547
|
+
var $r2=function($x){return Math.round($x*100)/100};
|
|
548
|
+
var $ptype=function($e){return Object.prototype.hasOwnProperty.call($pt,$e.pointerType)?$pt[$e.pointerType]:0};
|
|
549
|
+
var $touch=function($t){$recent.push($rel($t));if($recent.length>16)$recent.shift()};
|
|
550
|
+
var $judge=function($t){if(!($t-$lsi<1000||$t-$origin<1000)){$n[7]++;$us=$rel($t)}};
|
|
551
|
+
var $check=function($t){var $x=$W.scrollX,$y=$W.scrollY;if($x===$sx&&$y===$sy)return;$sx=$x;$sy=$y;if($t-$ls>150)$judge($t);$ls=$t};
|
|
552
|
+
var $hidden=function(){return $D.visibilityState==="hidden"?1:0};
|
|
553
|
+
$on($W,"pointermove",function($e){if(!$e.isTrusted)return;if($e.pointerType==="touch"||$e.pointerType==="pen")$lsi=$e.timeStamp;$check($e.timeStamp);$n[4]++;$touch($e.timeStamp);var $c=1;try{$c=$e.getCoalescedEvents?$e.getCoalescedEvents().length:1}catch($x){}$moves.push([$rel($e.timeStamp),$r2($e.clientX),$r2($e.clientY),Math.min($c,1000),$ptype($e)]);if($moves.length>320)$moves.shift()});
|
|
554
|
+
$on($W,"pointerdown",function($e){if(!$e.isTrusted)return;$n[6]++;$check($e.timeStamp);$lsi=$e.timeStamp;$touch($e.timeStamp)});
|
|
555
|
+
$on($W,"click",function($e){if(!$e.isTrusted)$n[0]++});
|
|
556
|
+
$on($W,"keydown",function($e){if(!$e.isTrusted){$n[1]++;return}$touch($e.timeStamp);$lsi=$e.timeStamp;$check($e.timeStamp);$lastKey=$e.timeStamp;if($e.key==="Shift")$shift=true;if($e.repeat||$e.isComposing||$sens($e))return;if($e.shiftKey&&!$shift&&$e.key&&$e.key.length===1&&$e.key!==$e.key.toLowerCase())$n[10]++;$n[5]++;var $en=[$rel($e.timeStamp),-1];$keys.push($en);if($keys.length>64)$keys.shift();$open.set($e.code||$e.key,$en)});
|
|
557
|
+
$on($W,"keyup",function($e){if(!$e.isTrusted)return;if($e.key==="Shift")$shift=false;var $id=$e.code||$e.key,$en=$open.get($id);if(!$en)return;$open.delete($id);$en[1]=Math.min(60000,$r1($rel($e.timeStamp)-$en[0]))});
|
|
558
|
+
$on($W,"wheel",function($e){if(!$e.isTrusted)return;$n[2]++;$lsi=$e.timeStamp;$check($e.timeStamp);$touch($e.timeStamp)});
|
|
559
|
+
$on($W,"scroll",function($e){var $t=$e.timeStamp,$mv=$W.scrollX!==$sx||$W.scrollY!==$sy;$sx=$W.scrollX;$sy=$W.scrollY;if($mv&&$t-$ls>150)$judge($t);$ls=$t});
|
|
560
|
+
$on($W,"paste",function(){$n[3]++});
|
|
561
|
+
$on($W,"input",function($e){if(!$e.isTrusted){$n[9]++;return}if($e.inputType==="insertText"&&!$e.isComposing&&$e.timeStamp-$lastKey>50&&!$sens($e))$n[8]++});
|
|
562
|
+
var $trg=null;try{var $rt=$F.frameElement&&$F.frameElement.getRootNode();$trg=$rt&&$rt!==$D&&$rt.querySelector?$rt.querySelector(".captcha-trigger"):null}catch($x){}
|
|
563
|
+
if($trg){
|
|
564
|
+
try{$io=new $W.IntersectionObserver(function($es){for(var $i=0;$i<$es.length;$i++){if($es[$i].isIntersecting&&$vis<0){$vis=$rel($es[$i].time);$io.disconnect()}}});$io.observe($trg)}catch($x){}
|
|
565
|
+
var $pa=function($e){var $r=$trg.getBoundingClientRect();return {k:0,tr:$e.isTrusted?1:0,hid:$hidden(),pt:$ptype($e),t:$rel($e.timeStamp),u:-1,x:$r1($e.clientX),y:$r1($e.clientY),cx:$r1($e.clientX-($r.left+$r.width/2)),cy:$r1($e.clientY-($r.top+$r.height/2)),w:$r1($r.width),h:$r1($r.height),sox:$r1($e.screenX-$e.clientX),soy:$r1($e.screenY-$e.clientY),cw:$r1(Math.min(10000,$e.width||0)),ch:$r1(Math.min(10000,$e.height||0)),pr:Math.max(0,Math.min(1,$e.pressure||0))}};
|
|
566
|
+
var $po={passive:true};
|
|
567
|
+
$on($trg,"pointerdown",function($e){if($e.button!==0)return;$press=$pa($e)},$po);
|
|
568
|
+
$on($trg,"pointerup",function($e){if($press&&$press.u<0)$press.u=$rel($e.timeStamp);if(!$e.isTrusted&&$press)$press.tr=0},$po);
|
|
569
|
+
$on($trg,"click",function($e){var $t=$rel($e.timeStamp);if($press&&$t-$press.t<5000){if(!$e.isTrusted)$press.tr=0;$act=$press}else if(!($act&&$act.k===1&&$t-$act.t<1000)){$act={k:2,tr:$e.isTrusted?1:0,hid:$hidden(),t:$t,u:-1}}$press=null},$po);
|
|
570
|
+
$on($trg,"keydown",function($e){if($e.target!==$trg||$e.repeat)return;if($e.key!=="Enter"&&$e.key!==" ")return;var $a={k:1,tr:$e.isTrusted?1:0,hid:$hidden(),t:$rel($e.timeStamp),u:-1};$act=$a;var $cd=$e.code||$e.key;var $up=function($v){if(($v.code||$v.key)!==$cd)return;$a.u=$rel($v.timeStamp);$W.removeEventListener("keyup",$up,true)};$W.addEventListener("keyup",$up,true);$offs.push(function(){$W.removeEventListener("keyup",$up,true)})},$po);
|
|
571
|
+
}
|
|
572
|
+
return function(){var $a=$act,$at=$a?$a.t:Infinity,$last=0;for(var $i=0;$i<$recent.length;$i++){var $t=$recent[$i];if($t<$at-100&&$t>$last)$last=$t}var $fs=0;try{$fs=$D.fullscreenElement?1:0}catch($x){}var $best=Infinity,$dl=Date.now()+5;for(var $j=0;$j<3&&Date.now()<$dl;$j++){var $p=$pnow(),$q=$p;while($q===$p&&Date.now()<$dl)$q=$pnow();if($q>$p)$best=Math.min($best,$q-$p)}
|
|
573
|
+
return {v:1,res:isFinite($best)?Math.min(1000,$r1($best*1000)/1000):1000,now:$rel($pnow()),vis:$vis>=0?$vis:-1,last:$a?$last:-1,us:$us,env:[$W.innerWidth,$W.innerHeight,$r1($W.devicePixelRatio||1),$W.matchMedia&&$W.matchMedia("(pointer: fine)").matches?1:0,$fs,$W.outerHeight-$W.innerHeight,$W.screenX||0,$W.screenY||0],n:$n.slice(),m:$moves,k:$keys,a:$a}};
|
|
574
|
+
})()}catch($x){$trace=null}}
|
|
575
|
+
`;
|
|
576
|
+
|
|
577
|
+
const COLLECTOR_TAIL = `try{$scan($D)}catch($x){}$comet();
|
|
578
|
+
if($cfg.bh||$cfg.ia){try{$mo=new $W.MutationObserver(function($rs){for(var $i=0;$i<$rs.length;$i++){var $r=$rs[$i];if($r.type==="attributes"){if(Object.prototype.hasOwnProperty.call($cfg.attrs,$r.attributeName))$mark($cfg.attrs[$r.attributeName]);continue}for(var $j=0;$j<$r.addedNodes.length;$j++){if($r.addedNodes[$j].nodeType===1)$scan($r.addedNodes[$j])}}});$mo.observe($D.documentElement,{childList:true,subtree:true,attributes:true,attributeFilter:Object.keys($cfg.attrs)})}catch($x){}}
|
|
579
|
+
return {
|
|
580
|
+
host:function(){var $o={};try{var $nv=$W.navigator;$o.nav={ua:$nv.userAgent,platform:$nv.platform,languages:($nv.languages||[]).join(","),hc:$nv.hardwareConcurrency,brands:$nv.userAgentData?$nv.userAgentData.brands.map(function($x){return $x.brand+"/"+$x.version}).join(","):null,webdriver:$nv.webdriver===true}}catch($x){}try{var $en=$F.Performance.prototype.getEntriesByType.call($perf,"navigation")[0];$o.doc=!!$en&&$en.nextHopProtocol===""&&$en.transferSize>0&&($en.deliveryType||"")===""&&$en.workerStart===0}catch($x){}try{$o.cdp=!!$cdp($W.Error,$W.console,$W,$W.navigator)}catch($x){}return $o},
|
|
581
|
+
marks:function(){try{$scan($D)}catch($x){}$comet();return $seen.slice()},
|
|
582
|
+
vp:function(){var $w=$read($W,"innerWidth"),$h=$read($W,"innerHeight");return typeof $w==="number"&&typeof $h==="number"?[$w,$h]:null},
|
|
583
|
+
ia:function(){return $ia?$ia.slice():null},
|
|
584
|
+
trace:function(){return $trace?$trace():null},
|
|
585
|
+
stop:function(){for(var $i=0;$i<$offs.length;$i++){try{$offs[$i]()}catch($x){}}$offs=[];if($mo)$mo.disconnect();if($io)$io.disconnect()}
|
|
586
|
+
}}`;
|
|
587
|
+
|
|
588
|
+
const NATIVE_PRELUDE = String.raw`var $ap,$keys,$isArr,$sort,$cca,$fcc,$nts,$pnow,$pobj,$P,$ce=0;
|
|
589
|
+
var $ok=(function(){try{var $fts=Function.prototype.toString,$app=Reflect.apply,$idx=String.prototype.indexOf;
|
|
590
|
+
var $nat=function($f){return typeof $f==="function"&&$app($idx,$app($fts,$f,[]),["[native code]"])>0};
|
|
591
|
+
var $list=[$fts,$app,$idx,Object.keys,Array.isArray,Array.prototype.sort,Array.prototype.slice,Array.prototype.indexOf,Array.prototype.push,String.prototype.charCodeAt,String.fromCharCode,Number.prototype.toString,Object.freeze,Object.defineProperty,Performance.prototype.now,JSON.parse,Math.round,Math.max,Math.min,eval,Function,EvalError,EventTarget.prototype.addEventListener];
|
|
592
|
+
for(var $i=0;$i<$list.length;$i++)if(!$nat($list[$i]))return false;
|
|
593
|
+
var $EE=EvalError,$ev=null,$fn=null;
|
|
594
|
+
$app(EventTarget.prototype.addEventListener,document,["securitypolicyviolation",function($e){try{if($ce===1&&$e.isTrusted&&$e.blockedURI==="eval"&&$app($idx,""+$e.violatedDirective,["script-src"])===0)$ce=2}catch($x){}},true]);
|
|
595
|
+
try{(0,eval)("0")}catch($x){$ev=$x}
|
|
596
|
+
try{Function("")}catch($x){$fn=$x}
|
|
597
|
+
if(($ev===null)!==($fn===null))return false;
|
|
598
|
+
if($ev!==null){if(!($ev instanceof $EE)||!($fn instanceof $EE))return false;$ce=1}
|
|
599
|
+
$ap=$app;$keys=Object.keys;$isArr=Array.isArray;$sort=Array.prototype.sort;$cca=String.prototype.charCodeAt;$fcc=String.fromCharCode;$nts=Number.prototype.toString;$pnow=Performance.prototype.now;$pobj=performance;$P=parent;
|
|
600
|
+
var $fz=Object.freeze,$dp=Object.defineProperty;
|
|
601
|
+
var $objs=[Object.prototype,Array.prototype,String.prototype,Number.prototype,Boolean.prototype,Function.prototype,Promise.prototype,Performance.prototype,Object,Array,String,Number,JSON,Math,Reflect,Promise];
|
|
602
|
+
for(var $j=0;$j<$objs.length;$j++)$fz($objs[$j]);
|
|
603
|
+
var $g=["Object","Array","String","Number","JSON","Math","Reflect","Promise","Function","performance","parent"];
|
|
604
|
+
for(var $k=0;$k<$g.length;$k++){try{$dp(window,$g[$k],{value:window[$g[$k]],writable:false,configurable:false})}catch($x){}}
|
|
605
|
+
return true}catch($x){return false}})();
|
|
606
|
+
var $now=function(){return $ap($pnow,$pobj,[])};
|
|
607
|
+
var $Q=function($s){var $o='"';for(var $i=0;$i<$s.length;$i++){var $c=$ap($cca,$s,[$i]);if($c===34)$o+='\\"';else if($c===92)$o+='\\\\';else if($c<32)$o+=$c===8?'\\b':$c===12?'\\f':$c===10?'\\n':$c===13?'\\r':$c===9?'\\t':'\\u00'+($c<16?'0':'')+$ap($nts,$c,[16]);else if($c>=55296&&$c<=57343){var $n=$i+1<$s.length?$ap($cca,$s,[$i+1]):0;if($c<=56319&&$n>=56320&&$n<=57343){$o+=$fcc($c,$n);$i++}else $o+='\\u'+$ap($nts,$c,[16])}else $o+=$fcc($c)}return $o+'"'};
|
|
608
|
+
var $S=function($v){if($v===null)return "null";var $t=typeof $v;if($t==="boolean")return $v?"true":"false";if($t==="number")return $v===$v&&$v!==1/0&&$v!==-1/0?""+$v:"null";if($t==="string")return $Q($v);if($t!=="object")return undefined;var $o,$i,$x;if($isArr($v)){$o="[";for($i=0;$i<$v.length;$i++){$x=$S($v[$i]);$o+=($i?",":"")+($x===undefined?"null":$x)}return $o+"]"}var $k=$ap($sort,$keys($v),[]),$f=true;$o="{";for($i=0;$i<$k.length;$i++){$x=$S($v[$k[$i]]);if($x===undefined)continue;$o+=($f?"":",")+$Q($k[$i])+":"+$x;$f=false}return $o+"}"};
|
|
609
|
+
var $H=function($s,$seed){var $h=$seed>>>0;for(var $i=0;$i<$s.length;$i++){$h^=$ap($cca,$s,[$i]);$h=($h+($h<<1)+($h<<4)+($h<<7)+($h<<8)+($h<<24))>>>0}return $h>>>0};
|
|
610
|
+
`;
|
|
611
|
+
|
|
612
|
+
function randomizeNames(src, names = new Map()) {
|
|
613
|
+
const used = new Set(names.values());
|
|
614
|
+
return src.replace(/\$[A-Za-z][A-Za-z0-9]*/g, (m) => {
|
|
615
|
+
if (!names.has(m)) {
|
|
616
|
+
let v = rVar();
|
|
617
|
+
while (used.has(v)) v = rVar();
|
|
618
|
+
used.add(v);
|
|
619
|
+
names.set(m, v);
|
|
620
|
+
}
|
|
621
|
+
return names.get(m);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function buildAgentScan(agAll, hF, hSet, h) {
|
|
626
|
+
const add = rVar();
|
|
627
|
+
const cdpProbe = rVar();
|
|
628
|
+
const c = rVar();
|
|
629
|
+
const i = rVar();
|
|
630
|
+
const list = rVar();
|
|
631
|
+
const el = rVar();
|
|
632
|
+
const cs = rVar();
|
|
633
|
+
const err = rVar();
|
|
634
|
+
const winHashes = JSON.stringify(WINDOW_PROP_MARKERS.map(h));
|
|
635
|
+
const prefixHashes = JSON.stringify(WINDOW_PREFIX_MARKERS.map(h));
|
|
636
|
+
const frameGlobals = AGENT_MARKS.filter((m) => m[2]).map((m) => [m[0], m[2]]);
|
|
637
|
+
const parts = [
|
|
638
|
+
`try{var ${list}=${JSON.stringify(frameGlobals)};for(var ${i}=0;${i}<${list}.length;${i}++){if(${list}[${i}][1].some(function(${c}){return ${c}.indexOf("navigator.")===0?${c}.slice(10) in navigator:${c} in window}))${add}(${list}[${i}][0])}}catch(${err}){}`,
|
|
639
|
+
`try{var ${list}=Object.getOwnPropertyNames(window);for(var ${i}=0;${i}<${list}.length;${i}++){var ${c}=${list}[${i}];if(${hSet}(${winHashes},${hF}(${c}))||${hSet}(${prefixHashes},${hF}(${c}.slice(0,4)))||${hSet}(${prefixHashes},${hF}(${c}.slice(0,5)))||${hSet}(${prefixHashes},${hF}(${c}.slice(0,10)))){${add}("automation");break}}}catch(${err}){}`,
|
|
640
|
+
`try{var ${el}=document.createElement("div");${el}.id="pplx-agent-0_0-overlay-stop-button";${el}.style.cssText="position:absolute;left:-99999px;visibility:hidden";document.body.appendChild(${el});var ${cs}=getComputedStyle(${el});if(${cs}.zIndex==="2147483647"&&${cs}.minHeight==="32px")${add}("comet");${el}.remove()}catch(${err}){}`,
|
|
641
|
+
`try{if(${cdpProbe}(Error,console,window,navigator))${add}("cdp_trap")}catch(${err}){}`,
|
|
642
|
+
`try{if(!/\\{\\s*\\[native code\\]\\s*\\}/.test(Function.prototype.toString.call(Element.prototype.attachShadow)))${add}("shadow_patched")}catch(${err}){}`,
|
|
643
|
+
];
|
|
644
|
+
return `var ${add}=function(${c}){if(${agAll}.indexOf(${c})<0)${agAll}.push(${c})};var ${cdpProbe}=${CDP_PROBE};${shuffle(parts).join("")}`;
|
|
371
645
|
}
|
|
372
646
|
|
|
373
647
|
function buildClientScript({
|
|
@@ -376,9 +650,16 @@ function buildClientScript({
|
|
|
376
650
|
initVals,
|
|
377
651
|
clientEqs,
|
|
378
652
|
blockAutomatedBrowsers,
|
|
653
|
+
checkSeed,
|
|
654
|
+
seedKeys,
|
|
655
|
+
salts,
|
|
656
|
+
fold,
|
|
657
|
+
cfg,
|
|
379
658
|
}) {
|
|
380
|
-
const
|
|
381
|
-
const
|
|
659
|
+
const h = hashWith(checkSeed);
|
|
660
|
+
const pn = new Map();
|
|
661
|
+
const prelude = randomizeNames(NATIVE_PRELUDE, pn);
|
|
662
|
+
const N = (k) => pn.get(k);
|
|
382
663
|
const hF = rVar();
|
|
383
664
|
const hSet = rVar();
|
|
384
665
|
const evalLocalVar = rVar();
|
|
@@ -387,7 +668,7 @@ function buildClientScript({
|
|
|
387
668
|
const evalB = rVar();
|
|
388
669
|
const evalC = rVar();
|
|
389
670
|
const helpers =
|
|
390
|
-
`function ${hF}(s){
|
|
671
|
+
`function ${hF}(s){return ${N("$H")}(s,${checkSeed})}` +
|
|
391
672
|
`function ${hSet}(a,v){for(var i=0;i<a.length;i++)if(a[i]===v)return true;return false;}`;
|
|
392
673
|
|
|
393
674
|
const blockChecks = blockAutomatedBrowsers
|
|
@@ -398,6 +679,25 @@ function buildClientScript({
|
|
|
398
679
|
const nKey = rVar();
|
|
399
680
|
const outKey = rVar();
|
|
400
681
|
const pKey = rVar();
|
|
682
|
+
const agAll = rVar();
|
|
683
|
+
const col = rVar();
|
|
684
|
+
const fin = rVar();
|
|
685
|
+
const finP = rVar();
|
|
686
|
+
const t0 = rVar();
|
|
687
|
+
const data = rVar();
|
|
688
|
+
const ser = rVar();
|
|
689
|
+
const g1 = rVar();
|
|
690
|
+
const g2 = rVar();
|
|
691
|
+
const mk = rVar();
|
|
692
|
+
const st = rVar();
|
|
693
|
+
const res = rVar();
|
|
694
|
+
const emit = rVar();
|
|
695
|
+
const lw = rVar();
|
|
696
|
+
const iso = rVar();
|
|
697
|
+
const nonce = JSON.stringify(id);
|
|
698
|
+
const mix = vars.map((v) => `${dvKey}[${JSON.stringify(v)}]`).join('+","+');
|
|
699
|
+
const observe = cfg.bh === 1 || cfg.ia === 1;
|
|
700
|
+
const agentScan = buildAgentScan(agAll, hF, hSet, h);
|
|
401
701
|
|
|
402
702
|
const envChecks = [
|
|
403
703
|
`try { const ${nKey}st = (new Error()).stack || ''; if (${nKey}st.indexOf('node:internal') !== -1 || ${nKey}st.indexOf('moduleEvaluation') !== -1 || ${nKey}st.indexOf('loadAndEvaluateModule') !== -1 || ${nKey}st.indexOf('file:///') !== -1 || ${nKey}st.indexOf('[eval]') !== -1 || /\\(native:/.test(${nKey}st)) return null; } catch { return null }`,
|
|
@@ -408,16 +708,39 @@ function buildClientScript({
|
|
|
408
708
|
|
|
409
709
|
`try { if (typeof EventTarget !== 'function' || !(document.body instanceof EventTarget) || !(window instanceof EventTarget)) return null; const ${nKey}probe = document.createElement('div'); let ${nKey}fired = 0; const ${nKey}ev = '_c' + (Date.now() & 0xffff).toString(36); const ${nKey}h = (e) => { if (e && e.detail === 0xc0de) ${nKey}fired++; }; ${nKey}probe.addEventListener(${nKey}ev, ${nKey}h); ${nKey}probe.dispatchEvent(new CustomEvent(${nKey}ev, { detail: 0xc0de })); ${nKey}probe.dispatchEvent(new CustomEvent(${nKey}ev, { detail: 0xc0de })); ${nKey}probe.removeEventListener(${nKey}ev, ${nKey}h); ${nKey}probe.dispatchEvent(new CustomEvent(${nKey}ev, { detail: 0xc0de })); if (${nKey}fired !== 2) return null; } catch { return null }`,
|
|
410
710
|
|
|
411
|
-
`try { const ${nKey}gf = new Function('return this'); const ${nKey}tg = ${nKey}gf(); if (${nKey}tg !== globalThis) return null; const ${nKey}leakHashes = ${JSON.stringify(["Bun", "process", "module", "require", "global", "__dirname", "Deno"].map(h))}; for (const ${nKey}k of Object.getOwnPropertyNames(${nKey}tg)) { if (${hSet}(${nKey}leakHashes, ${hF}(${nKey}k))) return null; } const ${nKey}fnArgs = new Function('a','b','c','return a+b+c'); if (${nKey}fnArgs.length !== 3) return null; if (${nKey}fnArgs(10,20,30) !== 60) return null; const ${nKey}src = Function.prototype.toString.call(${nKey}fnArgs); if (${nKey}src.indexOf('return a+b+c') === -1) return null; if (${nKey}src.indexOf('apply') !== -1 || ${nKey}src.indexOf('callArgs') !== -1 || ${nKey}src.indexOf('Reflect.') !== -1) return null; let ${nKey}thrown = null; try { new Function('throw new Error("x")')(); } catch (${nKey}e) { ${nKey}thrown = ${nKey}e; } if (!${nKey}thrown || !${nKey}thrown.stack) return null; const ${nKey}st2 = ${nKey}thrown.stack; if (${nKey}st2.indexOf('node:internal') !== -1 || ${nKey}st2.indexOf('moduleEvaluation') !== -1 || ${nKey}st2.indexOf('file:///') !== -1 || ${nKey}st2.indexOf('[eval]') !== -1 || /\\(native:/.test(${nKey}st2)) return null; } catch { return null }`,
|
|
711
|
+
`if (!${N("$ce")}) { try { const ${nKey}gf = new Function('return this'); const ${nKey}tg = ${nKey}gf(); if (${nKey}tg !== globalThis) return null; const ${nKey}leakHashes = ${JSON.stringify(["Bun", "process", "module", "require", "global", "__dirname", "Deno"].map(h))}; for (const ${nKey}k of Object.getOwnPropertyNames(${nKey}tg)) { if (${hSet}(${nKey}leakHashes, ${hF}(${nKey}k))) return null; } const ${nKey}fnArgs = new Function('a','b','c','return a+b+c'); if (${nKey}fnArgs.length !== 3) return null; if (${nKey}fnArgs(10,20,30) !== 60) return null; const ${nKey}src = Function.prototype.toString.call(${nKey}fnArgs); if (${nKey}src.indexOf('return a+b+c') === -1) return null; if (${nKey}src.indexOf('apply') !== -1 || ${nKey}src.indexOf('callArgs') !== -1 || ${nKey}src.indexOf('Reflect.') !== -1) return null; let ${nKey}thrown = null; try { new Function('throw new Error("x")')(); } catch (${nKey}e) { ${nKey}thrown = ${nKey}e; } if (!${nKey}thrown || !${nKey}thrown.stack) return null; const ${nKey}st2 = ${nKey}thrown.stack; if (${nKey}st2.indexOf('node:internal') !== -1 || ${nKey}st2.indexOf('moduleEvaluation') !== -1 || ${nKey}st2.indexOf('file:///') !== -1 || ${nKey}st2.indexOf('[eval]') !== -1 || /\\(native:/.test(${nKey}st2)) return null; } catch { return null } }`,
|
|
712
|
+
|
|
713
|
+
`if (!${N("$ce")}) { try { const ${nKey}ie = (0, eval); const ${nKey}eg = ${nKey}ie('this'); if (${nKey}eg !== globalThis) return null; const ${nKey}leak2 = ${JSON.stringify(["Bun", "process", "require", "global", "__dirname", "Deno"].map(h))}; for (const ${nKey}k of Object.getOwnPropertyNames(${nKey}eg)) { if (${hSet}(${nKey}leak2, ${hF}(${nKey}k))) return null; } } catch { return null } }`,
|
|
412
714
|
|
|
413
|
-
`try { const ${nKey}
|
|
715
|
+
`try { const ${nKey}sg = (function () { return this; })(); if (!${nKey}sg || ${nKey}sg !== globalThis || ${nKey}sg !== window) return null; const ${nKey}leak3 = ${JSON.stringify(["Bun", "process", "module", "require", "global", "__dirname", "Deno"].map(h))}; for (const ${nKey}k of Object.getOwnPropertyNames(${nKey}sg)) { if (${hSet}(${nKey}leak3, ${hF}(${nKey}k))) return null; } } catch { return null }`,
|
|
414
716
|
|
|
415
|
-
`try { var ${evalLocalVar} = ${evalSecret}; var ${evalA} = '${evalLocalVar.slice(0, 2)}'; var ${evalB} = '${evalLocalVar.slice(2)}'; var ${evalC} = ${evalA} + ${evalB}; var ${evalLocalVar}r1 = (0, eval)('typeof ' + ${evalC}); if (${evalLocalVar}r1 !== 'undefined') return
|
|
717
|
+
`if (!${N("$ce")}) { try { if (!new Function(${JSON.stringify(`try { var ${evalLocalVar} = ${evalSecret}; var ${evalA} = '${evalLocalVar.slice(0, 2)}'; var ${evalB} = '${evalLocalVar.slice(2)}'; var ${evalC} = ${evalA} + ${evalB}; var ${evalLocalVar}r1 = (0, eval)('typeof ' + ${evalC}); if (${evalLocalVar}r1 !== 'undefined') return false; var ${evalLocalVar}r2 = eval(${evalC}); if (${evalLocalVar}r2 !== ${evalSecret}) return false; var ${evalLocalVar}r3 = eval(${evalA} + ${evalB} + '+1'); if (${evalLocalVar}r3 !== ${evalSecret + 1}) return false; var ${evalLocalVar}arr = ['(', '(', ')', '=', '>', 't', 'h', 'i', 's', ')', '(', ')']; var ${evalLocalVar}arrow = (0, eval)(${evalLocalVar}arr.join('')); if (${evalLocalVar}arrow !== globalThis) return false; var ${evalLocalVar}r4 = eval('(function(){return ' + ${evalC} + '*2;})()'); if (${evalLocalVar}r4 !== ${evalSecret * 2}) return false; return true; } catch { return false }`)})()) return null; } catch { return null } }`,
|
|
416
718
|
];
|
|
417
719
|
|
|
418
|
-
|
|
720
|
+
const folds = vars
|
|
721
|
+
.map((v, i) => {
|
|
722
|
+
const k = JSON.stringify(v);
|
|
723
|
+
const extra = `${i === fold[0] ? `^${g1}` : ""}${i === fold[1] ? `^${g2}` : ""}`;
|
|
724
|
+
return `${st}[${k}]=((${dvKey}[${k}]^${salts[i]}${extra})&0x7FFFFFFF)%900000+100000;`;
|
|
725
|
+
})
|
|
726
|
+
.join("");
|
|
727
|
+
|
|
728
|
+
const collected = shuffle([
|
|
729
|
+
`v:1`,
|
|
730
|
+
`el:Math.max(0,Math.round(${N("$now")}()-${t0}))`,
|
|
731
|
+
`p:${pKey}`,
|
|
732
|
+
`vp:${col}?${col}.vp():null`,
|
|
733
|
+
`hp:${col}?${col}.host():null`,
|
|
734
|
+
`ag:${agAll}.slice(0,${MAX_BOUND_CODES})`,
|
|
735
|
+
`ce:${N("$ce")}`,
|
|
736
|
+
`ia:${cfg.ia ? `${col}?${col}.ia():null` : "null"}`,
|
|
737
|
+
`bh:${cfg.bh ? `${col}?${col}.trace():null` : "null"}`,
|
|
738
|
+
]).join(",");
|
|
739
|
+
|
|
740
|
+
const post = (m) => `${N("$P")}.postMessage(${m},"*")`;
|
|
741
|
+
return `(function(){${prelude}if(!${N("$ok")}){parent.postMessage({type:"cap:error",nonce:${nonce},reason:"natives_tampered"},"*");return}${helpers}var ${iso}=0;try{${N("$P")}.document.nodeType}catch(e){${iso}=1}var ${t0}=${N("$now")}(),${fin},${finP}=new Promise(function(r){${fin}=r}),${col}=null;window.addEventListener("message",function(e){var d=e.data;if(e.source===${N("$P")}&&d&&d.type==="cap:finalize"&&d.nonce===${nonce})${fin}()});try{${col}=(${randomizeNames(`${COLLECTOR_HEAD}${cfg.bh ? COLLECTOR_TRACE : ""}${COLLECTOR_TAIL}`)})(${iso}?window:parent,window,JSON.parse(${JSON.stringify(JSON.stringify(cfg))}),${CDP_PROBE})}catch(e){${col}=null}window.addEventListener("pagehide",function(){try{if(${col})${col}.stop()}catch(e){}});${post(`{type:"cap:ready",nonce:${nonce},observe:${observe}}`)};window.onload=async function(){var ${dvKey}=null;try {var ${agAll}=[];${dvKey}=await (async function(){${shuffle(envChecks).join("")}${blockChecks}${agentScan}
|
|
419
742
|
var ${vars[0]}=${initVals[0]};var ${vars[1]}=${initVals[1]};var ${vars[2]}=${initVals[2]};var ${vars[3]}=${initVals[3]};${clientEqs}
|
|
420
|
-
var ${outKey}={};${outKey}["${vars[0]}"]=${vars[0]};${outKey}["${vars[1]}"]=${vars[1]};${outKey}["${vars[2]}"]=${vars[2]};${outKey}["${vars[3]}"]=${vars[3]};return ${outKey};})();if (!${dvKey} || typeof ${dvKey} !== 'object')
|
|
743
|
+
var ${outKey}={};${outKey}["${vars[0]}"]=${vars[0]};${outKey}["${vars[1]}"]=${vars[1]};${outKey}["${vars[2]}"]=${vars[2]};${outKey}["${vars[3]}"]=${vars[3]};return ${outKey};})();if (!${dvKey} || typeof ${dvKey} !== 'object') throw 0;${buildProbe(pKey)}var ${emit}=function(${lw}){if(${col}){var ${mk}=${col}.marks();for(var i=0;i<${mk}.length;i++)if(${agAll}.indexOf(${mk}[i])<0)${agAll}.push(${mk}[i])}${agAll}.sort();var ${data}={${collected}};if(${lw}){${data}.ia=null;${data}.bh=null;${data}.lw=1}if(${iso}){${data}.ia=null;${data}.bh=null;${data}.is=1}var ${ser}=${N("$S")}(${data}),${g1}=${N("$H")}(${ser},(${seedKeys[0][1]}^${N("$H")}(${mix},${seedKeys[0][0]}))>>>0),${g2}=${N("$H")}(${ser},(${seedKeys[1][1]}^${N("$H")}(${mix},${seedKeys[1][0]}))>>>0),${st}={};${folds}return {i:${nonce},state:${st},d:${ser}}};${observe ? `${post(`{type:"cap:instr",nonce:${nonce},early:true,result:${emit}(1)}`)};await ${finP};` : ""}var ${res}=${emit}(0);if(${col})${col}.stop();${post(`{type:"cap:instr",nonce:${nonce},result:${res}}`)};} catch (e) {try{if(${col})${col}.stop()}catch(x){}${post(`{type:"cap:error",nonce:${nonce},reason:${dvKey}?"script_failed":"env_failed"}`)}}};})();`;
|
|
421
744
|
}
|
|
422
745
|
|
|
423
746
|
const DEFAULT_TTL_MS = 5 * 60 * 1000;
|
|
@@ -426,64 +749,74 @@ export async function generateInstrumentation(opts = {}) {
|
|
|
426
749
|
const id = rHex(32);
|
|
427
750
|
const vars = Array.from({ length: 4 }, () => rVar(12));
|
|
428
751
|
const blockAutomatedBrowsers = opts.blockAutomatedBrowsers === true;
|
|
752
|
+
const blockAutomatedInteractions = opts.blockAutomatedInteractions === true;
|
|
753
|
+
const detectAutomatedInteractions =
|
|
754
|
+
opts.detectAutomatedInteractions === true || blockAutomatedInteractions;
|
|
755
|
+
const behavior = opts.behavior === true;
|
|
756
|
+
const behaviorEnforced = behavior && opts.behaviorEnforced === true;
|
|
757
|
+
|
|
758
|
+
let initVals;
|
|
759
|
+
let vals;
|
|
760
|
+
let clientEqs;
|
|
761
|
+
do {
|
|
762
|
+
initVals = [
|
|
763
|
+
fastRnd(10, 250),
|
|
764
|
+
fastRnd(10, 250),
|
|
765
|
+
fastRnd(10, 250),
|
|
766
|
+
fastRnd(10, 250),
|
|
767
|
+
];
|
|
768
|
+
vals = [...initVals];
|
|
769
|
+
|
|
770
|
+
const correctKey = fastRnd(1000, 9000);
|
|
771
|
+
let badKey = fastRnd(1000, 9000);
|
|
772
|
+
while (badKey === correctKey) {
|
|
773
|
+
badKey = fastRnd(1000, 9000);
|
|
774
|
+
}
|
|
429
775
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
clientEqs += `${vD} = ${vD} | ${vS1};`;
|
|
473
|
-
vals[dest] = toInt32(vals[dest] | vals[src1]);
|
|
474
|
-
} else if (op === 3) {
|
|
475
|
-
clientEqs += `${vD} = ${vD} & ${vS1};`;
|
|
476
|
-
vals[dest] = toInt32(vals[dest] & vals[src1]);
|
|
477
|
-
} else if (op === 4) {
|
|
478
|
-
clientEqs += `${vD} = ${fnHelper}(${vS1}, ${vS2}, ${vD});`;
|
|
479
|
-
vals[dest] = toInt32(
|
|
480
|
-
(vals[src2] ^ vals[src1]) | (vals[dest] ^ vals[src2]),
|
|
481
|
-
);
|
|
482
|
-
} else {
|
|
483
|
-
clientEqs += `${vD} = ${domHelper}(${vS1}, ${vS2}, ${vS3});`;
|
|
484
|
-
vals[dest] = toInt32(domSumMock(vals[src1], vals[src2], vals[src3]));
|
|
776
|
+
vals[0] = toInt32(vals[0] ^ correctKey);
|
|
777
|
+
|
|
778
|
+
const fnHelper = rVar();
|
|
779
|
+
const domHelper = rVar();
|
|
780
|
+
const helperDecls =
|
|
781
|
+
`function ${fnHelper}(a,b,c){function F(d){this.v=function(){return this.k^d;}};var p={k:c};var i=new F(a);i.k=b;F.prototype=p;return i.v()|(new F(b)).v();}` +
|
|
782
|
+
`function ${domHelper}(x,y,z){var d=document.createElement('div');d.style.display='none';document.body.appendChild(d);function A(p,v){for(var i=0;i<8;i++){var c=document.createElement('div');p.appendChild(c);c.textContent=v;if((v&1)==0)p=c;v=v>>1;}return p;}function B(n,r,s){if(!n||n==r)return s%256;while(n.children.length>0)n.removeChild(n.lastElementChild);return B(n.parentNode,r,s+parseInt(n.textContent));}var s=B(A(A(A(d,x),y),z),d,0);d.parentNode.removeChild(d);return s;}`;
|
|
783
|
+
|
|
784
|
+
clientEqs = `${helperDecls}${vars[0]} = ${vars[0]} ^ (navigator.userAgent ? ${correctKey} : ${badKey});`;
|
|
785
|
+
|
|
786
|
+
for (let i = 0; i < 20; i++) {
|
|
787
|
+
const op = fastRnd(0, 5);
|
|
788
|
+
const dest = fastRnd(0, 3);
|
|
789
|
+
const src1 = fastRnd(0, 3);
|
|
790
|
+
const src2 = fastRnd(0, 3);
|
|
791
|
+
const src3 = fastRnd(0, 3);
|
|
792
|
+
const vD = vars[dest];
|
|
793
|
+
const vS1 = vars[src1];
|
|
794
|
+
const vS2 = vars[src2];
|
|
795
|
+
const vS3 = vars[src3];
|
|
796
|
+
|
|
797
|
+
if (op === 0) {
|
|
798
|
+
clientEqs += `${vD} = ~(${vD} & ${vS1});`;
|
|
799
|
+
vals[dest] = toInt32(~(vals[dest] & vals[src1]));
|
|
800
|
+
} else if (op === 1) {
|
|
801
|
+
clientEqs += `${vD} = ${vD} ^ ${vS1};`;
|
|
802
|
+
vals[dest] = toInt32(vals[dest] ^ vals[src1]);
|
|
803
|
+
} else if (op === 2) {
|
|
804
|
+
clientEqs += `${vD} = ${vD} | ${vS1};`;
|
|
805
|
+
vals[dest] = toInt32(vals[dest] | vals[src1]);
|
|
806
|
+
} else if (op === 3) {
|
|
807
|
+
clientEqs += `${vD} = ${vD} & ${vS1};`;
|
|
808
|
+
vals[dest] = toInt32(vals[dest] & vals[src1]);
|
|
809
|
+
} else if (op === 4) {
|
|
810
|
+
clientEqs += `${vD} = ${fnHelper}(${vS1}, ${vS2}, ${vD});`;
|
|
811
|
+
vals[dest] = toInt32(
|
|
812
|
+
(vals[src2] ^ vals[src1]) | (vals[dest] ^ vals[src2]),
|
|
813
|
+
);
|
|
814
|
+
} else {
|
|
815
|
+
clientEqs += `${vD} = ${domHelper}(${vS1}, ${vS2}, ${vS3});`;
|
|
816
|
+
vals[dest] = toInt32(domSumMock(vals[src1], vals[src2], vals[src3]));
|
|
817
|
+
}
|
|
485
818
|
}
|
|
486
|
-
}
|
|
819
|
+
} while (vals.filter((v) => v !== 0).length < 2);
|
|
487
820
|
|
|
488
821
|
const salts = [
|
|
489
822
|
fastRnd(100_000, 999_999),
|
|
@@ -491,10 +824,15 @@ export async function generateInstrumentation(opts = {}) {
|
|
|
491
824
|
fastRnd(100_000, 999_999),
|
|
492
825
|
fastRnd(100_000, 999_999),
|
|
493
826
|
];
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
827
|
+
const seeds = [randomInt(1, 0x7fffffff), randomInt(1, 0x7fffffff)];
|
|
828
|
+
const checkSeed = randomInt(1, 0x7fffffff);
|
|
829
|
+
const seedKeys = seeds.map((seed) => {
|
|
830
|
+
const c = randomInt(1, 0x7fffffff);
|
|
831
|
+
return [c, toInt32(seed ^ hashWith(c)(vals.join(",")))];
|
|
832
|
+
});
|
|
833
|
+
const first = fastRnd(0, 3);
|
|
834
|
+
const fold = [first, (first + fastRnd(1, 3)) % 4];
|
|
835
|
+
const binding = { pv: vals, sl: salts, hs: seeds, j: fold };
|
|
498
836
|
|
|
499
837
|
const script = buildClientScript({
|
|
500
838
|
id,
|
|
@@ -502,9 +840,20 @@ export async function generateInstrumentation(opts = {}) {
|
|
|
502
840
|
initVals,
|
|
503
841
|
clientEqs,
|
|
504
842
|
blockAutomatedBrowsers,
|
|
843
|
+
checkSeed,
|
|
844
|
+
seedKeys,
|
|
845
|
+
salts,
|
|
846
|
+
fold,
|
|
847
|
+
cfg: {
|
|
848
|
+
bh: behavior ? 1 : 0,
|
|
849
|
+
ia: detectAutomatedInteractions ? 1 : 0,
|
|
850
|
+
sens: SENSITIVE_FIELDS,
|
|
851
|
+
marks: AGENT_MARKS,
|
|
852
|
+
attrs: MARK_ATTRS,
|
|
853
|
+
},
|
|
505
854
|
});
|
|
506
855
|
|
|
507
|
-
const level = Math.max(1, Math.min(10, opts.obfuscationLevel ??
|
|
856
|
+
const level = Math.max(1, Math.min(10, opts.obfuscationLevel ?? 5));
|
|
508
857
|
|
|
509
858
|
let finalScript;
|
|
510
859
|
if (level <= 3) {
|
|
@@ -564,77 +913,354 @@ export async function generateInstrumentation(opts = {}) {
|
|
|
564
913
|
});
|
|
565
914
|
|
|
566
915
|
const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS;
|
|
916
|
+
const iat = Date.now();
|
|
567
917
|
|
|
568
918
|
return {
|
|
569
919
|
id,
|
|
570
|
-
|
|
571
|
-
|
|
920
|
+
iat,
|
|
921
|
+
expires: iat + ttlMs,
|
|
572
922
|
vars,
|
|
573
923
|
blockAutomatedBrowsers,
|
|
924
|
+
blockAutomatedInteractions,
|
|
925
|
+
detectAutomatedInteractions,
|
|
926
|
+
behavior,
|
|
927
|
+
behaviorEnforced,
|
|
928
|
+
binding,
|
|
574
929
|
instrumentation: Buffer.from(compressed).toString("base64"),
|
|
575
930
|
};
|
|
576
931
|
}
|
|
577
932
|
|
|
578
|
-
export
|
|
579
|
-
|
|
580
|
-
|
|
933
|
+
export const MAX_BOUND_DATA = 65_536;
|
|
934
|
+
const CLOCK_SLACK_MS = 5_000;
|
|
935
|
+
const DATA_KEYS = new Set([
|
|
936
|
+
"v",
|
|
937
|
+
"el",
|
|
938
|
+
"p",
|
|
939
|
+
"vp",
|
|
940
|
+
"hp",
|
|
941
|
+
"ag",
|
|
942
|
+
"ia",
|
|
943
|
+
"bh",
|
|
944
|
+
"ce",
|
|
945
|
+
"lw",
|
|
946
|
+
"is",
|
|
947
|
+
]);
|
|
948
|
+
const PAYLOAD_KEYS = new Set(["i", "state", "d"]);
|
|
949
|
+
const LEGACY_PAYLOAD_KEYS = new Set(["vp", "p", "ts"]);
|
|
950
|
+
const UNSAFE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
951
|
+
|
|
952
|
+
const isPlain = (o) => !!o && typeof o === "object" && !Array.isArray(o);
|
|
953
|
+
|
|
954
|
+
export function canonicalize(v) {
|
|
955
|
+
if (Array.isArray(v)) {
|
|
956
|
+
return v.map((x) =>
|
|
957
|
+
x === undefined || typeof x === "function" ? null : canonicalize(x),
|
|
958
|
+
);
|
|
581
959
|
}
|
|
582
|
-
if (
|
|
583
|
-
|
|
960
|
+
if (v && typeof v === "object") {
|
|
961
|
+
const out = {};
|
|
962
|
+
for (const k of Object.keys(v).sort()) {
|
|
963
|
+
const x = v[k];
|
|
964
|
+
if (x !== undefined && typeof x !== "function") out[k] = canonicalize(x);
|
|
965
|
+
}
|
|
966
|
+
return out;
|
|
584
967
|
}
|
|
968
|
+
return v;
|
|
969
|
+
}
|
|
585
970
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
971
|
+
export function serializeBound(data) {
|
|
972
|
+
return JSON.stringify(canonicalize(data));
|
|
973
|
+
}
|
|
589
974
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
975
|
+
export function boundValues(binding, serialized) {
|
|
976
|
+
const g1 = hashWith(binding.hs[0])(serialized);
|
|
977
|
+
const g2 = hashWith(binding.hs[1])(serialized);
|
|
978
|
+
return binding.pv.map(
|
|
979
|
+
(v, i) =>
|
|
980
|
+
(((v ^
|
|
981
|
+
binding.sl[i] ^
|
|
982
|
+
(i === binding.j[0] ? g1 : 0) ^
|
|
983
|
+
(i === binding.j[1] ? g2 : 0)) &
|
|
984
|
+
0x7fffffff) %
|
|
985
|
+
900_000) +
|
|
986
|
+
100_000,
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
function parseBound(serialized) {
|
|
991
|
+
try {
|
|
992
|
+
let unsafe = false;
|
|
993
|
+
const parsed = JSON.parse(serialized, (k, v) => {
|
|
994
|
+
if (UNSAFE_KEYS.has(k)) unsafe = true;
|
|
995
|
+
return v;
|
|
996
|
+
});
|
|
997
|
+
if (unsafe || !isPlain(parsed)) return null;
|
|
998
|
+
if (serializeBound(parsed) !== serialized) return null;
|
|
999
|
+
return parsed;
|
|
1000
|
+
} catch {
|
|
1001
|
+
return null;
|
|
593
1002
|
}
|
|
1003
|
+
}
|
|
594
1004
|
|
|
1005
|
+
const canonicalCodes = (list, max) =>
|
|
1006
|
+
Array.isArray(list) &&
|
|
1007
|
+
list.length <= max &&
|
|
1008
|
+
list.every(
|
|
1009
|
+
(c, i) =>
|
|
1010
|
+
typeof c === "string" &&
|
|
1011
|
+
/^[a-z_]{1,24}$/.test(c) &&
|
|
1012
|
+
(i === 0 || list[i - 1] < c),
|
|
1013
|
+
);
|
|
1014
|
+
|
|
1015
|
+
const isNumPair = (x) =>
|
|
1016
|
+
Array.isArray(x) &&
|
|
1017
|
+
x.length === 2 &&
|
|
1018
|
+
x.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
1019
|
+
|
|
1020
|
+
const optional = (x, ok) => x === undefined || x === null || ok(x);
|
|
1021
|
+
const isStr = (x) => typeof x === "string";
|
|
1022
|
+
|
|
1023
|
+
function boundDataValid(d) {
|
|
1024
|
+
if (Object.keys(d).some((k) => !DATA_KEYS.has(k))) return false;
|
|
1025
|
+
if (d.v !== 1 || !Number.isInteger(d.el) || d.el < 0) return false;
|
|
1026
|
+
if (!canonicalCodes(d.ag, MAX_BOUND_CODES)) return false;
|
|
1027
|
+
if (d.p !== null && !isPlain(d.p)) return false;
|
|
1028
|
+
if (d.hp !== null && !isPlain(d.hp)) return false;
|
|
1029
|
+
if (d.bh !== null && !isPlain(d.bh)) return false;
|
|
1030
|
+
if (d.vp !== null && !isNumPair(d.vp)) return false;
|
|
1031
|
+
if (d.ce !== undefined && d.ce !== 0 && d.ce !== 1 && d.ce !== 2)
|
|
1032
|
+
return false;
|
|
1033
|
+
if (d.lw !== undefined && (d.lw !== 1 || d.ia !== null || d.bh !== null)) {
|
|
1034
|
+
return false;
|
|
1035
|
+
}
|
|
1036
|
+
if (d.is !== undefined && (d.is !== 1 || d.ia !== null || d.bh !== null)) {
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
595
1039
|
if (
|
|
596
|
-
|
|
597
|
-
!
|
|
1040
|
+
d.ia !== null &&
|
|
1041
|
+
!(
|
|
1042
|
+
Array.isArray(d.ia) &&
|
|
1043
|
+
d.ia.length === 2 &&
|
|
1044
|
+
d.ia.every((n) => Number.isInteger(n) && n >= 0 && n <= 255)
|
|
1045
|
+
)
|
|
598
1046
|
) {
|
|
599
|
-
return
|
|
1047
|
+
return false;
|
|
600
1048
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
(
|
|
1049
|
+
const p = d.p ?? {};
|
|
1050
|
+
return (
|
|
1051
|
+
optional(d.hp?.nav?.brands, isStr) &&
|
|
1052
|
+
optional(p.mainNav?.brands, isStr) &&
|
|
1053
|
+
optional(p.ua, isStr) &&
|
|
1054
|
+
optional(p.webdriver, (x) => typeof x === "boolean") &&
|
|
1055
|
+
optional(p.uaData?.brands, (x) => Array.isArray(x) && x.every(isStr)) &&
|
|
1056
|
+
optional(
|
|
1057
|
+
p.langs,
|
|
1058
|
+
(x) =>
|
|
1059
|
+
Array.isArray(x) && Number.isFinite(x[0]) && typeof x[1] === "boolean",
|
|
1060
|
+
)
|
|
604
1061
|
);
|
|
1062
|
+
}
|
|
605
1063
|
|
|
606
|
-
|
|
607
|
-
return { valid: false, reason: "failed_challenge" };
|
|
608
|
-
}
|
|
1064
|
+
const failed = { valid: false, reason: "failed_challenge" };
|
|
609
1065
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
if (
|
|
1066
|
+
export function verifyInstrumentationResult(
|
|
1067
|
+
challengeMeta,
|
|
1068
|
+
payload,
|
|
1069
|
+
now = Date.now(),
|
|
1070
|
+
) {
|
|
1071
|
+
try {
|
|
1072
|
+
if (!isPlain(challengeMeta)) {
|
|
1073
|
+
return { valid: false, reason: "missing_meta" };
|
|
1074
|
+
}
|
|
1075
|
+
if (!isPlain(payload)) {
|
|
1076
|
+
return { valid: false, reason: "missing_output" };
|
|
1077
|
+
}
|
|
1078
|
+
if (payload.i !== challengeMeta.id) {
|
|
1079
|
+
return { valid: false, reason: "id_mismatch" };
|
|
1080
|
+
}
|
|
1081
|
+
const state = payload.state;
|
|
1082
|
+
if (!isPlain(state)) {
|
|
1083
|
+
return { valid: false, reason: "invalid_state" };
|
|
1084
|
+
}
|
|
1085
|
+
const vars = challengeMeta.vars;
|
|
1086
|
+
if (!Array.isArray(vars)) {
|
|
1087
|
+
return { valid: false, reason: "invalid_meta" };
|
|
1088
|
+
}
|
|
1089
|
+
if (
|
|
1090
|
+
Object.keys(payload).some(
|
|
1091
|
+
(k) => !PAYLOAD_KEYS.has(k) && !LEGACY_PAYLOAD_KEYS.has(k),
|
|
1092
|
+
)
|
|
1093
|
+
) {
|
|
1094
|
+
return failed;
|
|
1095
|
+
}
|
|
1096
|
+
if (
|
|
1097
|
+
Object.keys(state).length !== vars.length ||
|
|
1098
|
+
vars.some((v) => !Object.hasOwn(state, v) || !Number.isInteger(state[v]))
|
|
1099
|
+
) {
|
|
1100
|
+
return failed;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
const binding = challengeMeta.binding;
|
|
1104
|
+
let expected = challengeMeta.expectedVals;
|
|
1105
|
+
if (binding) {
|
|
1106
|
+
if (typeof payload.d !== "string") return failed;
|
|
1107
|
+
if (payload.d.length > MAX_BOUND_DATA) {
|
|
1108
|
+
return { valid: false, reason: "instr_oversized" };
|
|
1109
|
+
}
|
|
1110
|
+
expected = boundValues(binding, payload.d);
|
|
1111
|
+
} else if (!Array.isArray(expected)) {
|
|
1112
|
+
return { valid: false, reason: "invalid_meta" };
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (!vars.every((v, i) => state[v] === expected[i])) return failed;
|
|
1116
|
+
|
|
1117
|
+
if (!binding) {
|
|
1118
|
+
if (challengeMeta.blockAutomatedBrowsers) {
|
|
1119
|
+
return { valid: false, reason: "instr_probe_missing" };
|
|
1120
|
+
}
|
|
1121
|
+
if (challengeMeta.behavior) {
|
|
1122
|
+
return { valid: false, reason: "behavior_missing" };
|
|
1123
|
+
}
|
|
1124
|
+
return { valid: true, riskFlags: [], trace: null };
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
const data = parseBound(payload.d);
|
|
1128
|
+
if (!data || !boundDataValid(data)) return failed;
|
|
1129
|
+
|
|
1130
|
+
if (Number.isFinite(challengeMeta.iat)) {
|
|
1131
|
+
const ttl =
|
|
1132
|
+
(challengeMeta.expires ?? Number.POSITIVE_INFINITY) - challengeMeta.iat;
|
|
1133
|
+
if (
|
|
1134
|
+
challengeMeta.iat + data.el > now + CLOCK_SLACK_MS ||
|
|
1135
|
+
data.el > ttl + CLOCK_SLACK_MS
|
|
1136
|
+
) {
|
|
1137
|
+
return { valid: false, reason: "instr_stale" };
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
const legacy = data.lw === 1;
|
|
1142
|
+
const isolated = data.is === 1 && !legacy;
|
|
1143
|
+
const reduced = legacy || isolated;
|
|
1144
|
+
const outdated = {
|
|
1145
|
+
valid: false,
|
|
1146
|
+
reason: isolated ? "instr_isolated" : "instr_widget_outdated",
|
|
1147
|
+
};
|
|
1148
|
+
if (challengeMeta.behavior === true && data.bh === null) {
|
|
1149
|
+
if (!reduced) return { valid: false, reason: "behavior_missing" };
|
|
1150
|
+
if (challengeMeta.behaviorEnforced !== false) return outdated;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
const unreachable = reduced
|
|
1154
|
+
? outdated
|
|
1155
|
+
: { valid: false, reason: "instr_host_unreachable" };
|
|
1156
|
+
if (data.hp === null && challengeMeta.blockAutomatedBrowsers === true) {
|
|
1157
|
+
return unreachable;
|
|
1158
|
+
}
|
|
1159
|
+
if (
|
|
1160
|
+
data.ia === null &&
|
|
1161
|
+
(reduced
|
|
1162
|
+
? challengeMeta.blockAutomatedInteractions === true
|
|
1163
|
+
: challengeMeta.detectAutomatedInteractions === true)
|
|
1164
|
+
) {
|
|
1165
|
+
return unreachable;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
const riskFlags = [];
|
|
1169
|
+
if (data.hp === null) riskFlags.push("host_unreachable");
|
|
1170
|
+
if (legacy) riskFlags.push("legacy_widget");
|
|
1171
|
+
if (isolated) riskFlags.push("isolated_frame");
|
|
1172
|
+
if (data.ce > 0) riskFlags.push("csp_eval_blocked");
|
|
1173
|
+
|
|
1174
|
+
const interactionFlags = [];
|
|
1175
|
+
if (
|
|
1176
|
+
challengeMeta.detectAutomatedInteractions === true &&
|
|
1177
|
+
data.ia !== null
|
|
1178
|
+
) {
|
|
1179
|
+
if (data.ia[0] >= 3)
|
|
1180
|
+
interactionFlags.push("interaction_synthetic_clicks");
|
|
1181
|
+
if (data.ia[1] >= 3) {
|
|
1182
|
+
interactionFlags.push("interaction_synthetic_keydowns");
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
if (
|
|
1187
|
+
challengeMeta.blockAutomatedInteractions === true &&
|
|
1188
|
+
interactionFlags.length
|
|
1189
|
+
) {
|
|
620
1190
|
return {
|
|
621
1191
|
valid: false,
|
|
622
|
-
reason: "
|
|
1192
|
+
reason: "instr_automated_interaction",
|
|
1193
|
+
blockedBy: interactionFlags,
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
const brands = [data.hp?.nav?.brands, data.p?.mainNav?.brands]
|
|
1198
|
+
.map((b) => (isStr(b) ? b : ""))
|
|
1199
|
+
.join(",");
|
|
1200
|
+
const agent = {
|
|
1201
|
+
all: data.ag,
|
|
1202
|
+
host: data.hp !== null,
|
|
1203
|
+
legacy,
|
|
1204
|
+
isolated,
|
|
1205
|
+
browser:
|
|
1206
|
+
data.p?.mainNav?.brave === true || /(^|,)Brave\//.test(brands)
|
|
1207
|
+
? "brave"
|
|
1208
|
+
: /(^|,)Google Chrome\//.test(brands)
|
|
1209
|
+
? "chrome"
|
|
1210
|
+
: null,
|
|
1211
|
+
};
|
|
1212
|
+
const boundFlags = data.ag.includes("automation")
|
|
1213
|
+
? ["automation_globals"]
|
|
1214
|
+
: [];
|
|
1215
|
+
const trace = data.bh;
|
|
1216
|
+
|
|
1217
|
+
if (data.p) {
|
|
1218
|
+
const vector = {
|
|
1219
|
+
...data.p,
|
|
1220
|
+
...(data.vp && { innerWH: data.vp }),
|
|
1221
|
+
cdp: {
|
|
1222
|
+
trap: data.ag.includes("cdp_trap") || data.hp?.cdp === true,
|
|
1223
|
+
shadow: !data.ag.includes("shadow_patched"),
|
|
1224
|
+
},
|
|
1225
|
+
...(data.hp && { host: data.hp }),
|
|
1226
|
+
};
|
|
1227
|
+
const d = detectAutomation(vector, {
|
|
1228
|
+
fontStackCount: PROBE_FONT_STACKS.length,
|
|
1229
|
+
});
|
|
1230
|
+
if (challengeMeta.blockAutomatedBrowsers && !d.pass) {
|
|
1231
|
+
return {
|
|
1232
|
+
valid: false,
|
|
1233
|
+
reason: "instr_automated_browser",
|
|
1234
|
+
blockedBy: d.blockedBy,
|
|
1235
|
+
checks: d.checks,
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
return {
|
|
1239
|
+
valid: true,
|
|
1240
|
+
riskFlags: [
|
|
1241
|
+
...d.riskFlags,
|
|
1242
|
+
...interactionFlags,
|
|
1243
|
+
...boundFlags,
|
|
1244
|
+
...riskFlags,
|
|
1245
|
+
],
|
|
623
1246
|
blockedBy: d.blockedBy,
|
|
624
1247
|
checks: d.checks,
|
|
1248
|
+
agent,
|
|
1249
|
+
trace,
|
|
625
1250
|
};
|
|
626
1251
|
}
|
|
1252
|
+
|
|
1253
|
+
if (challengeMeta.blockAutomatedBrowsers) {
|
|
1254
|
+
return { valid: false, reason: "instr_probe_missing" };
|
|
1255
|
+
}
|
|
1256
|
+
|
|
627
1257
|
return {
|
|
628
1258
|
valid: true,
|
|
629
|
-
riskFlags:
|
|
630
|
-
|
|
631
|
-
|
|
1259
|
+
riskFlags: [...interactionFlags, ...boundFlags, ...riskFlags],
|
|
1260
|
+
agent,
|
|
1261
|
+
trace,
|
|
632
1262
|
};
|
|
1263
|
+
} catch {
|
|
1264
|
+
return failed;
|
|
633
1265
|
}
|
|
634
|
-
|
|
635
|
-
if (challengeMeta.blockAutomatedBrowsers) {
|
|
636
|
-
return { valid: false, reason: "instr_probe_missing" };
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
return { valid: true, riskFlags: [] };
|
|
640
1266
|
}
|