@webdecoy/node 0.27.0 → 0.29.0
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 +2 -0
- package/dist/{chunk-P6IWJ7K5.mjs → chunk-VPPTUL5K.mjs} +3 -1
- package/dist/index.d.mts +49 -4
- package/dist/index.d.ts +49 -4
- package/dist/index.js +205 -107
- package/dist/index.mjs +203 -107
- package/dist/vercel.js +3 -1
- package/dist/vercel.mjs +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
resolveGateEnv,
|
|
12
12
|
ruleBlockResponse,
|
|
13
13
|
shouldSkipPath
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-VPPTUL5K.mjs";
|
|
15
15
|
import {
|
|
16
16
|
ATTACK_SIGNATURE_IDS,
|
|
17
17
|
AgentVerifier,
|
|
@@ -103,25 +103,43 @@ var MemoryClientSignalStore = class {
|
|
|
103
103
|
};
|
|
104
104
|
var CLIENT_SESSION_COOKIE = "wd_cs";
|
|
105
105
|
var CLIENT_SESSION_HEADER = "x-wd-session";
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
var CLIENT_RECEIPT_COOKIE = "__Host-wd_cs";
|
|
107
|
+
var CLIENT_RECEIPT_PREFIX = "receipt:";
|
|
108
|
+
var CLIENT_RECEIPT_TTL_MS = 15 * 6e4;
|
|
109
|
+
function getClientSignalHost(headers) {
|
|
110
|
+
const value = headers.host ?? headers[":authority"];
|
|
111
|
+
if (typeof value !== "string" || value.length > 255 || !/^[a-z0-9.:[\]-]+$/i.test(value)) {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
return new URL("https://" + value).host || void 0;
|
|
116
|
+
} catch {
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function readCookie(header, name) {
|
|
121
|
+
if (!header) return void 0;
|
|
122
|
+
for (const part of header.split(";")) {
|
|
123
|
+
const eq = part.indexOf("=");
|
|
124
|
+
if (eq >= 0 && part.slice(0, eq).trim() === name) {
|
|
125
|
+
return part.slice(eq + 1).trim();
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
|
-
|
|
119
|
-
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
function readClientSession(headers) {
|
|
131
|
+
const receipt = readCookie(headers.cookie, CLIENT_RECEIPT_COOKIE);
|
|
132
|
+
if (receipt !== void 0) {
|
|
133
|
+
return /^[0-9a-f]{48}$/.test(receipt) ? CLIENT_RECEIPT_PREFIX + receipt : void 0;
|
|
134
|
+
}
|
|
135
|
+
const legacy = readCookie(headers.cookie, CLIENT_SESSION_COOKIE) || headers[CLIENT_SESSION_HEADER];
|
|
136
|
+
return legacy && !legacy.startsWith(CLIENT_RECEIPT_PREFIX) ? legacy : void 0;
|
|
120
137
|
}
|
|
121
138
|
var ClientSignalRule = class {
|
|
122
139
|
constructor(config) {
|
|
123
140
|
this.name = "client-signals";
|
|
124
141
|
this.store = config.store;
|
|
142
|
+
this.siteKey = config.siteKey;
|
|
125
143
|
this.minScore = config.minScore;
|
|
126
144
|
this.action = config.action ?? "DENY";
|
|
127
145
|
this.dryRun = config.dryRun ?? false;
|
|
@@ -147,7 +165,10 @@ var ClientSignalRule = class {
|
|
|
147
165
|
};
|
|
148
166
|
}
|
|
149
167
|
const verdict = this.store.sync ? this.store.get(sessionId) : context.prepared?.[this.name];
|
|
150
|
-
|
|
168
|
+
const issuedReceipt = sessionId.startsWith(CLIENT_RECEIPT_PREFIX);
|
|
169
|
+
const receipt = verdict?.receipt;
|
|
170
|
+
const usableReceipt = receipt && Date.now() < receipt.expiresAt && getClientSignalHost(context.headers) === receipt.host && (this.siteKey === void 0 || this.siteKey === receipt.siteKey);
|
|
171
|
+
if (!verdict || verdict.sessionId !== sessionId || (issuedReceipt || this.siteKey !== void 0) && !usableReceipt) {
|
|
151
172
|
return {
|
|
152
173
|
action: "ALLOW",
|
|
153
174
|
rule: this.name,
|
|
@@ -170,7 +191,7 @@ var ClientSignalRule = class {
|
|
|
170
191
|
metadata: {
|
|
171
192
|
score: verdict.score,
|
|
172
193
|
recommendation: verdict.recommendation,
|
|
173
|
-
sessionId,
|
|
194
|
+
...issuedReceipt ? {} : { sessionId },
|
|
174
195
|
dryRun: this.dryRun
|
|
175
196
|
}
|
|
176
197
|
};
|
|
@@ -208,6 +229,21 @@ var AUTOMATION_UA_PATTERNS = [
|
|
|
208
229
|
/chromium.*headless/i
|
|
209
230
|
];
|
|
210
231
|
|
|
232
|
+
// src/detection/scroll-observation.ts
|
|
233
|
+
var MAX_SCROLL_SAMPLES = 100;
|
|
234
|
+
var LARGE_SCROLL_STEP_PX = 400;
|
|
235
|
+
function observeScrollJump(behavioral) {
|
|
236
|
+
const { samples, maxStep } = behavioral?.scrollMorphology ?? {};
|
|
237
|
+
if (typeof samples !== "number" || !Number.isInteger(samples) || samples < 2 || samples > MAX_SCROLL_SAMPLES || typeof maxStep !== "number" || !Number.isFinite(maxStep) || maxStep < 0 || (behavioral?.keyEvents ?? 0) > 0 || (behavioral?.touchEvents ?? 0) > 0) return void 0;
|
|
238
|
+
return {
|
|
239
|
+
id: "large-scroll-step-v1",
|
|
240
|
+
mode: "observe",
|
|
241
|
+
status: maxStep > LARGE_SCROLL_STEP_PX ? "detected" : "clear",
|
|
242
|
+
samples,
|
|
243
|
+
maxStep
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
211
247
|
// src/detection/ip.ts
|
|
212
248
|
var IPV4_RE = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
|
|
213
249
|
function isIPv4(ip) {
|
|
@@ -367,19 +403,58 @@ function recommend(finalScore) {
|
|
|
367
403
|
return "block";
|
|
368
404
|
}
|
|
369
405
|
|
|
406
|
+
// src/detection/detectors/keyboard-input.ts
|
|
407
|
+
var MIN_KEY_HOLD_SAMPLES = 3;
|
|
408
|
+
var MAX_KEY_HOLD_SAMPLES = 200;
|
|
409
|
+
var SHORT_KEY_HOLD_MS = 20;
|
|
410
|
+
var MAX_KEY_HOLD_MS = 2e3;
|
|
411
|
+
function classifyKeyboardInput(signals) {
|
|
412
|
+
const behavioral = signals.behavioral ?? {};
|
|
413
|
+
const keyEvents = behavioral.keyEvents ?? 0;
|
|
414
|
+
if (!Number.isFinite(keyEvents) || keyEvents < 2 || (behavioral.totalPoints ?? 0) !== 0) {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
const { keyHoldSamples = 0, keyHoldAvg = 0 } = behavioral;
|
|
418
|
+
const validSummary = Number.isInteger(keyHoldSamples) && keyHoldSamples > 0 && keyHoldSamples <= Math.min(MAX_KEY_HOLD_SAMPLES, Math.floor(keyEvents / 2)) && Number.isFinite(keyHoldAvg) && keyHoldAvg > 0 && keyHoldAvg < MAX_KEY_HOLD_MS;
|
|
419
|
+
let count = validSummary ? keyHoldSamples : 0;
|
|
420
|
+
let duration = count > 0 ? count * keyHoldAvg : 0;
|
|
421
|
+
for (const field of Object.values(signals.formAnalysis?.textareaKeyboard ?? {})) {
|
|
422
|
+
if (!Array.isArray(field?.dwellTimes)) continue;
|
|
423
|
+
for (const dwell of field.dwellTimes) {
|
|
424
|
+
if (typeof dwell === "number" && dwell > 0 && dwell < MAX_KEY_HOLD_MS) {
|
|
425
|
+
count++;
|
|
426
|
+
duration += dwell;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return count >= MIN_KEY_HOLD_SAMPLES && duration / count < SHORT_KEY_HOLD_MS ? "short-key-holds" : "keyboard-only";
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/detection/detectors/pointer-evidence.ts
|
|
434
|
+
function isTouchModality(behavioral) {
|
|
435
|
+
const touchEvents = behavioral.touchEvents ?? 0;
|
|
436
|
+
const hasTouchSample = touchEvents > 0 || (behavioral.touchTotalPoints ?? 0) > 0;
|
|
437
|
+
return touchEvents >= 3 || hasTouchSample && behavioral.pointerHasNonMouseType === true;
|
|
438
|
+
}
|
|
439
|
+
function hasHumanMovementMarkers(behavioral) {
|
|
440
|
+
const tremor = behavioral.microTremorScore ?? 0;
|
|
441
|
+
const corrections = behavioral.overshootCorrections ?? 0;
|
|
442
|
+
const changes = behavioral.directionChanges ?? 0;
|
|
443
|
+
return tremor >= 0.5 && (corrections >= 1 || changes >= 10);
|
|
444
|
+
}
|
|
445
|
+
|
|
370
446
|
// src/detection/detectors/vision-ai.ts
|
|
371
|
-
function detectVisionAI(signals) {
|
|
447
|
+
function detectVisionAI(signals, widgetInteraction = true) {
|
|
372
448
|
const detections = [];
|
|
373
449
|
const b = signals.behavioral ?? {};
|
|
374
450
|
const t = signals.temporal ?? {};
|
|
375
451
|
const totalPoints = b.totalPoints ?? 0;
|
|
376
452
|
const trajectory = b.trajectoryLength ?? 0;
|
|
377
453
|
const approachPts = b.approachPoints ?? 0;
|
|
378
|
-
const
|
|
379
|
-
const
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
if (totalPoints < 5 && trajectory < 10 && !isTouchUser && !isKeyboardUser) {
|
|
454
|
+
const isTouchUser = isTouchModality(b);
|
|
455
|
+
const isKeyboardUser = classifyKeyboardInput(signals) === "keyboard-only";
|
|
456
|
+
const usesMouse = !isTouchUser && !isKeyboardUser;
|
|
457
|
+
if (totalPoints < 5 && trajectory < 10 && usesMouse) {
|
|
383
458
|
detections.push({
|
|
384
459
|
category: "vision_ai",
|
|
385
460
|
score: 0.9,
|
|
@@ -387,7 +462,7 @@ function detectVisionAI(signals) {
|
|
|
387
462
|
reason: "No mouse movement detected before click (AI agent pattern)"
|
|
388
463
|
});
|
|
389
464
|
}
|
|
390
|
-
if (approachPts === 0 &&
|
|
465
|
+
if (widgetInteraction && approachPts === 0 && usesMouse) {
|
|
391
466
|
detections.push({
|
|
392
467
|
category: "vision_ai",
|
|
393
468
|
score: 0.7,
|
|
@@ -416,7 +491,7 @@ function detectVisionAI(signals) {
|
|
|
416
491
|
}
|
|
417
492
|
}
|
|
418
493
|
const microTremor = b.microTremorScore ?? 0.5;
|
|
419
|
-
if (microTremor < 0.15) {
|
|
494
|
+
if (usesMouse && totalPoints >= 5 && microTremor < 0.15) {
|
|
420
495
|
detections.push({
|
|
421
496
|
category: "vision_ai",
|
|
422
497
|
score: 0.7,
|
|
@@ -424,7 +499,7 @@ function detectVisionAI(signals) {
|
|
|
424
499
|
reason: "Mouse movement lacks natural micro-tremor"
|
|
425
500
|
});
|
|
426
501
|
}
|
|
427
|
-
if ((b.approachDirectness ?? 0) > 0.95) {
|
|
502
|
+
if (widgetInteraction && usesMouse && approachPts >= 5 && (b.approachDirectness ?? 0) > 0.95 && !hasHumanMovementMarkers(b)) {
|
|
428
503
|
detections.push({
|
|
429
504
|
category: "vision_ai",
|
|
430
505
|
score: 0.5,
|
|
@@ -432,17 +507,8 @@ function detectVisionAI(signals) {
|
|
|
432
507
|
reason: "Mouse path to target is unnaturally direct"
|
|
433
508
|
});
|
|
434
509
|
}
|
|
435
|
-
const precision = b.clickPrecision ?? 10;
|
|
436
|
-
if (precision > 0 && precision < 2) {
|
|
437
|
-
detections.push({
|
|
438
|
-
category: "vision_ai",
|
|
439
|
-
score: 0.4,
|
|
440
|
-
confidence: 0.5,
|
|
441
|
-
reason: "Click precision is unnaturally accurate"
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
510
|
const exploration = b.explorationRatio ?? 0.3;
|
|
445
|
-
if (exploration < 0.05 && trajectory > 50) {
|
|
511
|
+
if (widgetInteraction && exploration < 0.05 && trajectory > 50) {
|
|
446
512
|
detections.push({
|
|
447
513
|
category: "vision_ai",
|
|
448
514
|
score: 0.4,
|
|
@@ -626,24 +692,30 @@ function detectCDP(signals) {
|
|
|
626
692
|
}
|
|
627
693
|
|
|
628
694
|
// src/detection/detectors/behavioral.ts
|
|
629
|
-
function detectBehavioral(signals) {
|
|
695
|
+
function detectBehavioral(signals, widgetInteraction = true) {
|
|
630
696
|
const detections = [];
|
|
631
697
|
const b = signals.behavioral ?? {};
|
|
632
698
|
const t = signals.temporal ?? {};
|
|
633
699
|
const totalPoints = b.totalPoints ?? 0;
|
|
634
700
|
const trajectory = b.trajectoryLength ?? 0;
|
|
635
|
-
const
|
|
636
|
-
const
|
|
637
|
-
const
|
|
638
|
-
|
|
639
|
-
|
|
701
|
+
const isTouchUser = isTouchModality(b);
|
|
702
|
+
const keyboard = classifyKeyboardInput(signals);
|
|
703
|
+
const humanMovement = hasHumanMovementMarkers(b);
|
|
704
|
+
if (keyboard === "short-key-holds" && !isTouchUser) {
|
|
705
|
+
detections.push({
|
|
706
|
+
category: "behavioral",
|
|
707
|
+
score: 0.8,
|
|
708
|
+
confidence: 0.9,
|
|
709
|
+
reason: "Keyboard-only input has unusually short key holds"
|
|
710
|
+
});
|
|
711
|
+
} else if (totalPoints === 0 && !isTouchUser && keyboard === null) {
|
|
640
712
|
detections.push({
|
|
641
713
|
category: "behavioral",
|
|
642
714
|
score: 0.8,
|
|
643
715
|
confidence: 0.9,
|
|
644
716
|
reason: "Zero mouse, touch, or keyboard events recorded"
|
|
645
717
|
});
|
|
646
|
-
} else if (totalPoints < 10 && !
|
|
718
|
+
} else if (totalPoints < 10 && !isTouchUser && keyboard === null && trajectory < 30) {
|
|
647
719
|
detections.push({
|
|
648
720
|
category: "behavioral",
|
|
649
721
|
score: 0.6,
|
|
@@ -652,7 +724,7 @@ function detectBehavioral(signals) {
|
|
|
652
724
|
});
|
|
653
725
|
}
|
|
654
726
|
const velVar = b.velocityVariance ?? 1;
|
|
655
|
-
if (velVar < 0.02 && trajectory > 50) {
|
|
727
|
+
if (velVar < 0.02 && trajectory > 50 && !humanMovement) {
|
|
656
728
|
detections.push({
|
|
657
729
|
category: "behavioral",
|
|
658
730
|
score: 0.6,
|
|
@@ -661,7 +733,7 @@ function detectBehavioral(signals) {
|
|
|
661
733
|
});
|
|
662
734
|
}
|
|
663
735
|
const overshoots = b.overshootCorrections ?? 0;
|
|
664
|
-
if (overshoots === 0 && trajectory > 200) {
|
|
736
|
+
if (widgetInteraction && overshoots === 0 && trajectory > 200 && !humanMovement) {
|
|
665
737
|
detections.push({
|
|
666
738
|
category: "behavioral",
|
|
667
739
|
score: 0.4,
|
|
@@ -677,7 +749,7 @@ function detectBehavioral(signals) {
|
|
|
677
749
|
confidence: 0.7,
|
|
678
750
|
reason: "Interaction completed too quickly"
|
|
679
751
|
});
|
|
680
|
-
} else if (interactionTime > 6e4) {
|
|
752
|
+
} else if (widgetInteraction && interactionTime > 6e4) {
|
|
681
753
|
detections.push({
|
|
682
754
|
category: "captcha_farm",
|
|
683
755
|
score: 0.3,
|
|
@@ -702,7 +774,7 @@ function detectBehavioral(signals) {
|
|
|
702
774
|
confidence: 0.5,
|
|
703
775
|
reason: "Mouse event rate abnormally high"
|
|
704
776
|
});
|
|
705
|
-
} else if (eventRate > 0 && eventRate < 10) {
|
|
777
|
+
} else if (eventRate > 0 && eventRate < 10 && !humanMovement) {
|
|
706
778
|
detections.push({
|
|
707
779
|
category: "behavioral",
|
|
708
780
|
score: 0.4,
|
|
@@ -1392,7 +1464,7 @@ function analyzeKeystrokeCadence(stats) {
|
|
|
1392
1464
|
}
|
|
1393
1465
|
|
|
1394
1466
|
// src/detection/detectors/form.ts
|
|
1395
|
-
function analyzeFormInteraction(formAnalysis) {
|
|
1467
|
+
function analyzeFormInteraction(formAnalysis, behavioral) {
|
|
1396
1468
|
if (!formAnalysis) return [];
|
|
1397
1469
|
const detections = [];
|
|
1398
1470
|
const submit = formAnalysis.submit ?? {};
|
|
@@ -1439,13 +1511,14 @@ function analyzeFormInteraction(formAnalysis) {
|
|
|
1439
1511
|
}
|
|
1440
1512
|
const textareaData = formAnalysis.textareaKeyboard;
|
|
1441
1513
|
if (textareaData) {
|
|
1514
|
+
const hasPointerOrTouch = (behavioral?.totalPoints ?? 0) >= 5 || (behavioral?.touchEvents ?? 0) > 0;
|
|
1442
1515
|
for (const [fieldId, stats] of Object.entries(textareaData)) {
|
|
1443
1516
|
const keyCount = stats.keyCount ?? 0;
|
|
1444
1517
|
const pasteCount = stats.pasteCount ?? 0;
|
|
1445
1518
|
const avgKeyInterval = stats.avgKeyInterval ?? 0;
|
|
1446
1519
|
const keyIntervalVariance = stats.keyIntervalVariance ?? 0;
|
|
1447
1520
|
const keydownUpRatio = stats.keydownUpRatio ?? 1;
|
|
1448
|
-
if (pasteCount > 0 && keyCount < 5) {
|
|
1521
|
+
if (pasteCount > 0 && keyCount < 5 && !hasPointerOrTouch) {
|
|
1449
1522
|
detections.push({
|
|
1450
1523
|
category: "bot",
|
|
1451
1524
|
score: 0.6,
|
|
@@ -1477,7 +1550,7 @@ function analyzeFormInteraction(formAnalysis) {
|
|
|
1477
1550
|
reason: `Textarea "${fieldId}" has abnormal keydown/keyup ratio (${keydownUpRatio.toFixed(2)})`
|
|
1478
1551
|
});
|
|
1479
1552
|
}
|
|
1480
|
-
if (stats.noKeyboardEvents && (stats.contentLength ?? 0) > 0) {
|
|
1553
|
+
if (stats.noKeyboardEvents && keyCount === 0 && pasteCount === 0 && (stats.contentLength ?? 0) > 0) {
|
|
1481
1554
|
detections.push({
|
|
1482
1555
|
category: "bot",
|
|
1483
1556
|
score: 0.75,
|
|
@@ -1589,44 +1662,32 @@ function analyzeCSSMediaQueries(cssMedia, signals) {
|
|
|
1589
1662
|
}
|
|
1590
1663
|
return detections;
|
|
1591
1664
|
}
|
|
1592
|
-
function analyzeFonts(fontsInfo,
|
|
1593
|
-
if (!fontsInfo || !fontsInfo.supported) return [];
|
|
1594
|
-
const detections = [];
|
|
1665
|
+
function analyzeFonts(fontsInfo, platform) {
|
|
1595
1666
|
const count = fontsInfo.count ?? 0;
|
|
1596
|
-
if (count < 3) {
|
|
1597
|
-
|
|
1598
|
-
|
|
1667
|
+
if (fontsInfo.supported !== true || !Number.isInteger(count) || count < 3 || typeof platform !== "string") {
|
|
1668
|
+
return [];
|
|
1669
|
+
}
|
|
1670
|
+
const hasWindowsFonts = fontsInfo.hasSegoeUI === true || fontsInfo.hasCalibri === true;
|
|
1671
|
+
const hasMacFonts = fontsInfo.hasSFPro === true || fontsInfo.hasMenlo === true;
|
|
1672
|
+
const noWindowsFonts = fontsInfo.hasSegoeUI === false && fontsInfo.hasCalibri === false;
|
|
1673
|
+
const noMacFonts = fontsInfo.hasSFPro === false && fontsInfo.hasMenlo === false;
|
|
1674
|
+
if (/^(mac|iphone|ipad|ipod)/i.test(platform) && hasWindowsFonts && noMacFonts) {
|
|
1675
|
+
return [{
|
|
1676
|
+
category: "automation",
|
|
1599
1677
|
score: 0.5,
|
|
1600
1678
|
confidence: 0.5,
|
|
1601
|
-
reason: `
|
|
1602
|
-
}
|
|
1679
|
+
reason: `Font set contradicts platform (Windows faces while claiming ${platform})`
|
|
1680
|
+
}];
|
|
1603
1681
|
}
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
category: "bot",
|
|
1682
|
+
if (/^win/i.test(platform) && hasMacFonts && noWindowsFonts) {
|
|
1683
|
+
return [{
|
|
1684
|
+
category: "automation",
|
|
1608
1685
|
score: 0.5,
|
|
1609
|
-
confidence: 0.6,
|
|
1610
|
-
reason: "Windows UA but Segoe UI font not detected"
|
|
1611
|
-
});
|
|
1612
|
-
}
|
|
1613
|
-
if ((ua.includes("mac os x") || ua.includes("macintosh")) && fontsInfo.hasSFPro === false && !ua.includes("10_15") && !ua.includes("10_14") && count > 5) {
|
|
1614
|
-
detections.push({
|
|
1615
|
-
category: "bot",
|
|
1616
|
-
score: 0.3,
|
|
1617
|
-
confidence: 0.4,
|
|
1618
|
-
reason: "Modern macOS UA but SF Pro font not detected"
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
if (ua.includes("linux") && !ua.includes("android") && fontsInfo.hasDejaVuSans === false && count > 5) {
|
|
1622
|
-
detections.push({
|
|
1623
|
-
category: "bot",
|
|
1624
|
-
score: 0.4,
|
|
1625
1686
|
confidence: 0.5,
|
|
1626
|
-
reason:
|
|
1627
|
-
}
|
|
1687
|
+
reason: `Font set contradicts platform (macOS faces while claiming ${platform})`
|
|
1688
|
+
}];
|
|
1628
1689
|
}
|
|
1629
|
-
return
|
|
1690
|
+
return [];
|
|
1630
1691
|
}
|
|
1631
1692
|
var PERMISSION_API_KEYS = [
|
|
1632
1693
|
"hasPermissionsAPI",
|
|
@@ -1676,14 +1737,14 @@ function analyzeDOMRect(domRectInfo) {
|
|
|
1676
1737
|
}
|
|
1677
1738
|
return detections;
|
|
1678
1739
|
}
|
|
1679
|
-
function analyzeAdvancedSignals(signals
|
|
1740
|
+
function analyzeAdvancedSignals(signals) {
|
|
1680
1741
|
const detections = [];
|
|
1681
1742
|
const env = signals.environmental ?? {};
|
|
1682
1743
|
if (env.webrtcInfo) detections.push(...analyzeWebRTC(env.webrtcInfo));
|
|
1683
1744
|
if (env.speechInfo) detections.push(...analyzeSpeechAPI(env.speechInfo));
|
|
1684
1745
|
if (env.workerConsistency) detections.push(...analyzeWorkerConsistency(env.workerConsistency));
|
|
1685
1746
|
if (env.cssMediaQueries) detections.push(...analyzeCSSMediaQueries(env.cssMediaQueries, signals));
|
|
1686
|
-
if (env.fontsInfo) detections.push(...analyzeFonts(env.fontsInfo,
|
|
1747
|
+
if (env.fontsInfo) detections.push(...analyzeFonts(env.fontsInfo, env.navigator?.platform));
|
|
1687
1748
|
if (env.permissionsInfo) detections.push(...analyzePermissions(env.permissionsInfo));
|
|
1688
1749
|
if (env.domRectFingerprint) detections.push(...analyzeDOMRect(env.domRectFingerprint));
|
|
1689
1750
|
if (env.audioInfo) detections.push(...analyzeAudioContext(env.audioInfo));
|
|
@@ -1742,12 +1803,13 @@ var DetectionEngine = class {
|
|
|
1742
1803
|
reason: "No PoW solution provided"
|
|
1743
1804
|
});
|
|
1744
1805
|
}
|
|
1806
|
+
const widgetInteraction = context.widgetInteraction !== false;
|
|
1745
1807
|
detections.push(
|
|
1746
|
-
...detectVisionAI(signals),
|
|
1808
|
+
...detectVisionAI(signals, widgetInteraction),
|
|
1747
1809
|
...detectHeadless(signals, userAgent),
|
|
1748
1810
|
...detectAutomation(signals),
|
|
1749
1811
|
...detectCDP(signals),
|
|
1750
|
-
...detectBehavioral(signals),
|
|
1812
|
+
...detectBehavioral(signals, widgetInteraction),
|
|
1751
1813
|
...detectTouchAuthenticity(signals, userAgent),
|
|
1752
1814
|
...detectSensorEntropy(signals, userAgent),
|
|
1753
1815
|
...detectTouchKinematics(signals),
|
|
@@ -1772,17 +1834,19 @@ var DetectionEngine = class {
|
|
|
1772
1834
|
if (ja4) detections.push(...checkJA4Fingerprint(ja4));
|
|
1773
1835
|
}
|
|
1774
1836
|
if (signals.formAnalysis) {
|
|
1775
|
-
detections.push(...analyzeFormInteraction(signals.formAnalysis));
|
|
1837
|
+
detections.push(...analyzeFormInteraction(signals.formAnalysis, signals.behavioral));
|
|
1776
1838
|
}
|
|
1777
|
-
detections.push(...analyzeAdvancedSignals(signals
|
|
1839
|
+
detections.push(...analyzeAdvancedSignals(signals));
|
|
1778
1840
|
const categoryScores = calculateCategoryScores(detections, this.weights);
|
|
1779
1841
|
const score = calculateFinalScore(categoryScores, this.weights);
|
|
1842
|
+
const scrollObservation = observeScrollJump(signals.behavioral);
|
|
1780
1843
|
return {
|
|
1781
1844
|
success: score < 0.5,
|
|
1782
1845
|
score,
|
|
1783
1846
|
recommendation: recommend(score),
|
|
1784
1847
|
categoryScores,
|
|
1785
1848
|
detections,
|
|
1849
|
+
...scrollObservation ? { observations: [scrollObservation] } : {},
|
|
1786
1850
|
timestamp: Math.floor(Date.now() / 1e3)
|
|
1787
1851
|
};
|
|
1788
1852
|
}
|
|
@@ -2007,10 +2071,14 @@ var Captcha = class {
|
|
|
2007
2071
|
* signals, and issues a session token on success. Mirrors `runVerification`.
|
|
2008
2072
|
*/
|
|
2009
2073
|
async verify(input) {
|
|
2074
|
+
return (await this.verifySubmission(input, true)).result;
|
|
2075
|
+
}
|
|
2076
|
+
async verifySubmission(input, widgetInteraction) {
|
|
2010
2077
|
const { siteKey, ip, userAgent } = input;
|
|
2011
2078
|
const headers = input.headers ?? {};
|
|
2012
2079
|
let signals = input.signals ?? {};
|
|
2013
2080
|
const extraDetections = [];
|
|
2081
|
+
let committedSignals = false;
|
|
2014
2082
|
const clientSignalsHash = input.powSolution?.signalsHash ?? null;
|
|
2015
2083
|
if (input.signalsJson && clientSignalsHash) {
|
|
2016
2084
|
const computed = await sha256Hex(input.signalsJson);
|
|
@@ -2023,7 +2091,11 @@ var Captcha = class {
|
|
|
2023
2091
|
});
|
|
2024
2092
|
}
|
|
2025
2093
|
try {
|
|
2026
|
-
|
|
2094
|
+
const parsed = JSON.parse(input.signalsJson);
|
|
2095
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2096
|
+
signals = parsed;
|
|
2097
|
+
committedSignals = computed === clientSignalsHash;
|
|
2098
|
+
}
|
|
2027
2099
|
} catch {
|
|
2028
2100
|
}
|
|
2029
2101
|
}
|
|
@@ -2050,21 +2122,36 @@ var Captcha = class {
|
|
|
2050
2122
|
headers,
|
|
2051
2123
|
ja3Hash: input.ja3Hash ?? null,
|
|
2052
2124
|
trustedJA4Headers: this.trustedJA4Headers,
|
|
2125
|
+
widgetInteraction,
|
|
2053
2126
|
pow,
|
|
2054
2127
|
extraDetections
|
|
2055
2128
|
});
|
|
2056
|
-
const
|
|
2057
|
-
|
|
2129
|
+
const proofVerified = pow.valid === true;
|
|
2130
|
+
const success = proofVerified && verdict.success;
|
|
2131
|
+
const token = success ? await this.tokens.issue(ip, siteKey, verdict.score) : null;
|
|
2132
|
+
const recommendation = !proofVerified && verdict.recommendation === "allow" ? "challenge" : verdict.recommendation;
|
|
2133
|
+
return {
|
|
2134
|
+
result: { ...verdict, success, recommendation, token },
|
|
2135
|
+
verifiedSignals: proofVerified && committedSignals && !!pow.nonce && signals.meta?.challengeNonce === pow.nonce
|
|
2136
|
+
};
|
|
2058
2137
|
}
|
|
2059
2138
|
/** Invisible-mode scoring — same pipeline, returns a compact result + action. */
|
|
2060
2139
|
async score(input) {
|
|
2061
|
-
|
|
2140
|
+
return (await this.scoreForSession(input)).result;
|
|
2141
|
+
}
|
|
2142
|
+
/** @internal Return the score and whether the server verified the committed signals. */
|
|
2143
|
+
async scoreForSession(input) {
|
|
2144
|
+
const { result, verifiedSignals } = await this.verifySubmission(input, false);
|
|
2062
2145
|
return {
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2146
|
+
result: {
|
|
2147
|
+
success: result.success,
|
|
2148
|
+
score: result.score,
|
|
2149
|
+
token: result.token,
|
|
2150
|
+
action: input.action ?? "",
|
|
2151
|
+
recommendation: result.recommendation,
|
|
2152
|
+
...result.observations ? { observations: result.observations } : {}
|
|
2153
|
+
},
|
|
2154
|
+
verifiedSignals
|
|
2068
2155
|
};
|
|
2069
2156
|
}
|
|
2070
2157
|
/** Verify a previously issued token (single-use, optionally IP-bound). */
|
|
@@ -2114,8 +2201,9 @@ function createCaptchaEndpoints(options = {}) {
|
|
|
2114
2201
|
}
|
|
2115
2202
|
if (sub === "/score" && method === "POST") {
|
|
2116
2203
|
const b = req.body ?? {};
|
|
2117
|
-
const
|
|
2118
|
-
|
|
2204
|
+
const siteKey = b.siteKey ?? "default";
|
|
2205
|
+
const { result, verifiedSignals } = await captcha.scoreForSession({
|
|
2206
|
+
siteKey,
|
|
2119
2207
|
ip: req.ip,
|
|
2120
2208
|
userAgent,
|
|
2121
2209
|
headers: req.headers,
|
|
@@ -2126,20 +2214,28 @@ function createCaptchaEndpoints(options = {}) {
|
|
|
2126
2214
|
ja3Hash,
|
|
2127
2215
|
action: b.action
|
|
2128
2216
|
});
|
|
2129
|
-
|
|
2217
|
+
const legacyId = typeof b.sessionId === "string" && !b.sessionId.startsWith(CLIENT_RECEIPT_PREFIX) ? b.sessionId || null : null;
|
|
2218
|
+
const response = json(200, { ...result, sessionId: legacyId });
|
|
2219
|
+
if (!signalStore) return response;
|
|
2220
|
+
const at = Date.now();
|
|
2221
|
+
const verdict = { score: result.score, recommendation: result.recommendation, at };
|
|
2222
|
+
if (legacyId) {
|
|
2223
|
+
await signalStore.set({ ...verdict, sessionId: legacyId });
|
|
2224
|
+
return response;
|
|
2225
|
+
}
|
|
2226
|
+
const host = getClientSignalHost(req.headers);
|
|
2227
|
+
const origin = req.headers.origin;
|
|
2228
|
+
if (verifiedSignals && host && (!origin || origin === "https://" + host) && typeof siteKey === "string" && siteKey.length <= 128) {
|
|
2229
|
+
const receipt = randomHex(24);
|
|
2130
2230
|
await signalStore.set({
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
at: Date.now()
|
|
2231
|
+
...verdict,
|
|
2232
|
+
sessionId: CLIENT_RECEIPT_PREFIX + receipt,
|
|
2233
|
+
receipt: { host, siteKey, expiresAt: at + CLIENT_RECEIPT_TTL_MS }
|
|
2135
2234
|
});
|
|
2235
|
+
response.headers["set-cookie"] = `${CLIENT_RECEIPT_COOKIE}=${receipt}; Path=/; Max-Age=${CLIENT_RECEIPT_TTL_MS / 1e3}; Secure; HttpOnly; SameSite=Lax`;
|
|
2236
|
+
response.headers["cache-control"] = "private, no-store";
|
|
2136
2237
|
}
|
|
2137
|
-
return
|
|
2138
|
-
...result,
|
|
2139
|
-
// Echoed so the widget can set the cookie the rule reads, without the
|
|
2140
|
-
// developer wiring a second endpoint to hand it one.
|
|
2141
|
-
sessionId: b.sessionId ?? null
|
|
2142
|
-
});
|
|
2238
|
+
return response;
|
|
2143
2239
|
}
|
|
2144
2240
|
if (sub === "/token/verify" && method === "POST") {
|
|
2145
2241
|
const b = req.body ?? {};
|
package/dist/vercel.js
CHANGED
|
@@ -4524,12 +4524,14 @@ function createFetchGuard(options = {}) {
|
|
|
4524
4524
|
},
|
|
4525
4525
|
async check(request, peer) {
|
|
4526
4526
|
const url = new URL(request.url);
|
|
4527
|
+
const headers = headerRecord(request.headers);
|
|
4528
|
+
if (!headers.host && !headers[":authority"]) headers.host = url.host;
|
|
4527
4529
|
const metadata = {
|
|
4528
4530
|
method: request.method,
|
|
4529
4531
|
path: url.pathname,
|
|
4530
4532
|
ip: resolveIP(request, peer),
|
|
4531
4533
|
user_agent: request.headers.get("user-agent") ?? void 0,
|
|
4532
|
-
headers
|
|
4534
|
+
headers,
|
|
4533
4535
|
query: url.search ? url.search.slice(1) : void 0,
|
|
4534
4536
|
timestamp: Date.now()
|
|
4535
4537
|
};
|
package/dist/vercel.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdecoy/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Bot detection and AI agent verification for Node.js and edge runtimes. Local honeypot tripwires, rate limiting and AI crawler policies, with optional WebDecoy dashboard reporting.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|