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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Every embedded CAPTCHA detection now includes a stable `evidenceFamily` for
diagnostics and future calibration. Evidence-family attribution does not
change scores, thresholds, or recommendations.

## [0.36.1] - 2026-12-05

### Changed
Expand Down
8 changes: 7 additions & 1 deletion packages/webdecoy/src/detection/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,13 @@ describe('advanced fingerprint detection', () => {
it.each(fontPlatformFixtures.cases)('matches the reference for $name', ({ fonts, platform, reasons }) => {
const verdict = score({ environmental: { fontsInfo: fonts, navigator: { platform } } });
expect(verdict.detections.filter(({ reason }) => /font/i.test(reason))).toEqual(
reasons.map(reason => ({ category: 'automation', score: 0.5, confidence: 0.5, reason })),
reasons.map(reason => ({
category: 'automation',
score: 0.5,
confidence: 0.5,
reason,
evidenceFamily: 'platform_coherence',
})),
);
});

Expand Down
2 changes: 2 additions & 0 deletions packages/webdecoy/src/detection/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
} from './types';
import { DEFAULT_WEIGHTS } from './weights';
import { observeScrollJump } from './scroll-observation';
import { annotateEvidenceFamilies } from './evidence-family';
import { isDatacenterIP } from './ip';
import {
InMemoryFingerprintStore,
Expand Down Expand Up @@ -205,6 +206,7 @@ export class DetectionEngine {
detections.push(...analyzeAdvancedSignals(signals));

// --- Aggregate -------------------------------------------------------------
annotateEvidenceFamilies(detections);
const currentCategoryScores = calculateCategoryScores(detections, this.weights);
const currentScore = calculateFinalScore(currentCategoryScores, this.weights);
const currentRecommendation = recommend(currentScore);
Expand Down
31 changes: 31 additions & 0 deletions packages/webdecoy/src/detection/evidence-family.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fixtures from './fixtures/evidence-families.json';
import { annotateEvidenceFamilies, evidenceFamilyForDetection } from './evidence-family';
import { calculateCategoryScores, calculateFinalScore } from './scoring';
import { DEFAULT_WEIGHTS } from './weights';
import type { Detection } from './types';

describe('evidence family attribution', () => {
it.each(fixtures.cases)('$reason', ({ reason, family }) => {
expect(evidenceFamilyForDetection({ category: 'behavioral', score: 0.5, confidence: 0.5, reason }))
.toBe(family);
});

it('does not change category or final scores', () => {
const detections: Detection[] = [
{ category: 'vision_ai', score: 0.7, confidence: 0.6, reason: fixtures.cases[0].reason },
{ category: 'behavioral', score: 0.5, confidence: 0.5, reason: fixtures.cases[2].reason },
];
const before = calculateFinalScore(calculateCategoryScores(detections, DEFAULT_WEIGHTS), DEFAULT_WEIGHTS);
annotateEvidenceFamilies(detections);
const after = calculateFinalScore(calculateCategoryScores(detections, DEFAULT_WEIGHTS), DEFAULT_WEIGHTS);
expect(after).toBe(before);
expect(detections.map(({ evidenceFamily }) => evidenceFamily))
.toEqual(['pointer_absence', 'pointer_path']);
});

it('collapses unknown and unregistered families', () => {
const detection = { category: 'behavioral', score: 0.5, confidence: 0.5, reason: 'custom' };
expect(evidenceFamilyForDetection(detection)).toBe('unclassified');
expect(evidenceFamilyForDetection({ ...detection, evidenceFamily: 'unclassified' })).toBe('unclassified');
});
});
52 changes: 52 additions & 0 deletions packages/webdecoy/src/detection/evidence-family.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { Detection, EvidenceFamily } from './types';

const FAMILY_RULES: ReadonlyArray<readonly [EvidenceFamily, RegExp]> = [
['pointer_absence', /No mouse movement detected|No approach trajectory|No exploratory mouse movement|Zero mouse, touch, or keyboard events|Insufficient mouse movement/],
['pointer_path', /Mouse movement lacks natural micro-tremor|Mouse path to target is unnaturally direct|Mouse event timing unnaturally consistent|Mouse velocity too consistent|No overshoot corrections|Mouse movements too straight|Too few direction changes/],
['pointer_provenance', /Pointer moves never coalesced|Pointer movement deltas incoherent|teleport click/i],
['typing_cadence', /typing rhythm|typing speed impossibly fast|Keystroke cadence|Typing cadence is mechanical|keydown\/keyup ratio|short key holds/i],
['field_injection', /Field populated without keystrokes|filled programmatically|chars but no keyboard events/i],
['interaction_speed', /Interaction completed too quickly|First interaction too fast|First interaction too soon/],
['interaction_cadence', /Interaction cadence matches agent act\/think loop|Unusually long interaction time|Mouse event rate abnormally/],
['execution_timing', /JS execution unusually|RequestAnimationFrame timing too consistent/],
['notification_state', /Notifications pre-denied|Notification permission contradicts/],
['platform_coherence', /Paste shortcut contradicts platform|Font set contradicts platform|UA\/platform mismatch|UA claims mobile but no touch|Worker\/main thread mismatch|Page and Worker disagree|Windows UA but Segoe UI font not detected|Linux UA but DejaVu Sans font not detected/],
['explicit_automation', /^WebDriver detected|CDP (automation detected|indicator)|Multiple CDP indicators|Playwright artifact|Native function.*patched|Function\.prototype\.toString is proxied/i],
['proof_of_work', /PoW verification failed|PoW completed impossibly fast|PoW timing suggests external processing|Challenge nonce mismatch|Challenge solved too fast|Challenge submitted before the required delay|No PoW solution provided|Signals tampered after PoW/],
['agent_declaration', /Declared AI agent user-agent|User-Agent indicates bot|Automation pattern in User-Agent/],
['agent_authentication', /Web Bot Auth|Signed agent request/],
['network_origin', /known datacenter IP|Reverse DNS suggests VPN\/proxy/],
['request_headers', /Missing \d+ expected browser headers|Suspicious header present|Invalid Accept-Language|Unusual Accept-Encoding/],
['transport_fingerprint', /TLS (JA4 )?fingerprint matches/],
['browser_surface', /No browser plugins|No navigator\.languages|Window lacks outer dimensions|Viewport equals window size|window\.chrome missing|Very few navigator APIs|Very few fonts detected|No local IP addresses detected via WebRTC|DOMRect/],
['graphics_surface', /Software(?:\/virtualized)? WebGL renderer|Canvas fingerprinting blocked|Canvas readback changed/],
['touch_provenance', /Touch force is identical|touches report force=1\.0|Touch contact radius identical|touches lack identifier tracking/i],
['touch_path', /Touch path too straight|Touch path has no micro-tremor|Touch path has zero direction changes/],
['device_sensors', /Motion sensor active but flat|Orientation sensor active but completely flat/],
['form_submission', /Form submitted programmatically|Form submitted too quickly|Form submitted with no user interaction|Very few events before submit/],
['paste_behavior', /filled mostly by paste/],
['scroll_behavior', /Page scrolled by API rather than by gesture/],
['fingerprint_churn', /IP has used many different fingerprints|Fingerprint seen from many IPs/],
['rate_behavior', /Verification rate exceeded|Rate limit exceeded|High request rate/],
['media_surface', /media devices|speech (?:synthesis )?voices|AudioContext/i],
['input_capability', /CSS reports coarse pointer|Fine pointer reported but no hover/],
];

const KNOWN_FAMILIES = new Set<EvidenceFamily>(FAMILY_RULES.map(([family]) => family));

export function evidenceFamilyForDetection(detection: Detection): EvidenceFamily {
if (detection.evidenceFamily && KNOWN_FAMILIES.has(detection.evidenceFamily)) {
return detection.evidenceFamily;
}
for (const [family, pattern] of FAMILY_RULES) {
if (pattern.test(detection.reason)) return family;
}
return 'unclassified';
}

export function annotateEvidenceFamilies(detections: Detection[]): Detection[] {
for (const detection of detections) {
detection.evidenceFamily = evidenceFamilyForDetection(detection);
}
return detections;
}
35 changes: 35 additions & 0 deletions packages/webdecoy/src/detection/fixtures/evidence-families.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"cases": [
{ "reason": "No mouse movement detected before click (AI agent pattern)", "family": "pointer_absence" },
{ "reason": "No approach trajectory to target", "family": "pointer_absence" },
{ "reason": "Mouse path to target is unnaturally direct", "family": "pointer_path" },
{ "reason": "Pointer moves never coalesced across many samples (synthetic/CDP input)", "family": "pointer_provenance" },
{ "reason": "Textarea \"message\" has unnaturally consistent typing rhythm", "family": "typing_cadence" },
{ "reason": "Field populated without keystrokes or paste (synthetic input event)", "family": "field_injection" },
{ "reason": "First interaction too fast after page load (25ms)", "family": "interaction_speed" },
{ "reason": "Interaction cadence matches agent act/think loop (bursts + dead air)", "family": "interaction_cadence" },
{ "reason": "RequestAnimationFrame timing too consistent", "family": "execution_timing" },
{ "reason": "Notification permission contradicts Permissions API (headless/stealth tell)", "family": "notification_state" },
{ "reason": "Font set contradicts platform (macOS faces while claiming Win32)", "family": "platform_coherence" },
{ "reason": "WebDriver detected", "family": "explicit_automation" },
{ "reason": "Challenge nonce mismatch (signals not bound to challenge)", "family": "proof_of_work" },
{ "reason": "Declared AI agent user-agent: ExampleBot", "family": "agent_declaration" },
{ "reason": "Verified AI agent (Web Bot Auth): ExampleBot", "family": "agent_authentication" },
{ "reason": "Request from known datacenter IP range", "family": "network_origin" },
{ "reason": "Missing 3 expected browser headers", "family": "request_headers" },
{ "reason": "TLS JA4 fingerprint matches: ExampleBot", "family": "transport_fingerprint" },
{ "reason": "No browser plugins detected", "family": "browser_surface" },
{ "reason": "Software WebGL renderer detected", "family": "graphics_surface" },
{ "reason": "Touch force is identical across all events (synthetic touch)", "family": "touch_provenance" },
{ "reason": "Touch path has no micro-tremor (unnaturally smooth)", "family": "touch_path" },
{ "reason": "Motion sensor active but flat (variance=0.0000) — likely emulator", "family": "device_sensors" },
{ "reason": "Form submitted programmatically (script)", "family": "form_submission" },
{ "reason": "Textarea \"message\" filled mostly by paste (1 pastes, 2 keystrokes)", "family": "paste_behavior" },
{ "reason": "Page scrolled by API rather than by gesture (single-event jump)", "family": "scroll_behavior" },
{ "reason": "IP has used many different fingerprints", "family": "fingerprint_churn" },
{ "reason": "High request rate", "family": "rate_behavior" },
{ "reason": "AudioContext unavailable (headless or blocked audio stack)", "family": "media_surface" },
{ "reason": "CSS reports coarse pointer but no touch support", "family": "input_capability" },
{ "reason": "A future detector without attribution", "family": "unclassified" }
]
}
2 changes: 2 additions & 0 deletions packages/webdecoy/src/detection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {
calculateFinalScore,
recommend,
} from './scoring';
export { annotateEvidenceFamilies, evidenceFamilyForDetection } from './evidence-family';

export { DEFAULT_WEIGHTS, AUTOMATION_UA_PATTERNS } from './weights';
export { isDatacenterIP, DATACENTER_CIDRS } from './ip';
Expand All @@ -30,6 +31,7 @@ export * from './detectors';

export type {
Detection,
EvidenceFamily,
ScrollJumpObservation,
CategoryScores,
Recommendation,
Expand Down
34 changes: 34 additions & 0 deletions packages/webdecoy/src/detection/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@
* the reference implementation).
*/

export type EvidenceFamily =
| 'pointer_absence'
| 'pointer_path'
| 'pointer_provenance'
| 'typing_cadence'
| 'field_injection'
| 'interaction_speed'
| 'interaction_cadence'
| 'execution_timing'
| 'notification_state'
| 'platform_coherence'
| 'explicit_automation'
| 'proof_of_work'
| 'agent_declaration'
| 'agent_authentication'
| 'network_origin'
| 'request_headers'
| 'transport_fingerprint'
| 'browser_surface'
| 'graphics_surface'
| 'touch_provenance'
| 'touch_path'
| 'device_sensors'
| 'form_submission'
| 'paste_behavior'
| 'scroll_behavior'
| 'fingerprint_churn'
| 'rate_behavior'
| 'media_surface'
| 'input_capability'
| 'unclassified';

/** A single triggered heuristic. */
export interface Detection {
/** Scoring bucket this detection contributes to (see {@link Weights}). */
Expand All @@ -21,6 +53,8 @@ export interface Detection {
confidence: number;
/** Human-readable explanation. */
reason: string;
/** Stable provenance shared by detections derived from the same evidence. */
evidenceFamily?: EvidenceFamily;
/** Optional structured detail (e.g. keystroke-cadence metrics). */
details?: Record<string, unknown>;
}
Expand Down
Loading