@webdecoy/node 0.3.0 → 0.4.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/dist/index.d.mts +139 -2
- package/dist/index.d.ts +139 -2
- package/dist/index.js +148 -23
- package/dist/index.mjs +131 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -73,6 +73,23 @@ interface FilterConfig {
|
|
|
73
73
|
/** Dry run mode: log violations but don't block */
|
|
74
74
|
dryRun?: boolean;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Configuration for tripwire (honeypot-path) rules
|
|
78
|
+
*/
|
|
79
|
+
interface TripwireConfig {
|
|
80
|
+
/** Exact hidden honeypot paths (e.g. a honeytoken path or `/admin-backup.zip`). */
|
|
81
|
+
paths?: string[];
|
|
82
|
+
/** Path prefixes treated as tripwires (e.g. `/.git/`). */
|
|
83
|
+
prefixes?: string[];
|
|
84
|
+
/** Regex patterns for tripwire paths. */
|
|
85
|
+
patterns?: RegExp[];
|
|
86
|
+
/** Include the built-in scanner/scraper bait paths. Default `true`. */
|
|
87
|
+
includeDefaults?: boolean;
|
|
88
|
+
/** Action when a tripwire is hit: 'DENY' (default) or 'THROTTLE'. */
|
|
89
|
+
action?: 'DENY' | 'THROTTLE';
|
|
90
|
+
/** Dry run mode: log the violation but don't block. */
|
|
91
|
+
dryRun?: boolean;
|
|
92
|
+
}
|
|
76
93
|
/**
|
|
77
94
|
* A violation event recorded when a rule triggers
|
|
78
95
|
*/
|
|
@@ -447,6 +464,75 @@ declare class FilterRule implements Rule {
|
|
|
447
464
|
evaluate(context: RuleContext): RuleResult;
|
|
448
465
|
}
|
|
449
466
|
|
|
467
|
+
/**
|
|
468
|
+
* Tripwire Rule (F4 — deception layer)
|
|
469
|
+
*
|
|
470
|
+
* Deterministic, zero-false-positive bot detection: a request for a hidden
|
|
471
|
+
* honeypot path (a "tripwire") that a real user can never reach — because it is
|
|
472
|
+
* only exposed as an invisible link, listed in robots.txt `Disallow`, or is a
|
|
473
|
+
* scanner-bait path no human ever types — is, by construction, automated.
|
|
474
|
+
*
|
|
475
|
+
* Unlike fingerprinting (which a stealth tool like botasaurus is purpose-built
|
|
476
|
+
* to defeat), a tripwire detects *intent* — going where a human cannot — which
|
|
477
|
+
* cannot be spoofed away by a better browser fingerprint.
|
|
478
|
+
*
|
|
479
|
+
* Implemented as a {@link Rule} so it flows through the existing
|
|
480
|
+
* DENY -> block -> violation-report pipeline with no middleware changes.
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Common scanner/scraper bait paths that no legitimate user ever requests.
|
|
485
|
+
* Requesting any of these is a strong automated-intent signal on its own.
|
|
486
|
+
*/
|
|
487
|
+
declare const DEFAULT_TRIPWIRE_PATHS: readonly string[];
|
|
488
|
+
declare class TripwireRule implements Rule {
|
|
489
|
+
readonly name = "tripwire";
|
|
490
|
+
private readonly exact;
|
|
491
|
+
private readonly prefixes;
|
|
492
|
+
private readonly patterns;
|
|
493
|
+
private readonly action;
|
|
494
|
+
private readonly dryRun;
|
|
495
|
+
constructor(config?: TripwireConfig);
|
|
496
|
+
evaluate(context: RuleContext): RuleResult;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Honeytoken generator (F4 — deception layer)
|
|
501
|
+
*
|
|
502
|
+
* Produces a hidden decoy link and the tripwire path it points at. Embed the
|
|
503
|
+
* link in a page (it is visually hidden and marked nofollow/aria-hidden, so a
|
|
504
|
+
* real user never sees or clicks it); register the path with a {@link
|
|
505
|
+
* TripwireRule}. Any client that parses the HTML and follows links — i.e. a
|
|
506
|
+
* scraper/crawler — requests the path and is deterministically flagged, while
|
|
507
|
+
* genuine users are never affected.
|
|
508
|
+
*/
|
|
509
|
+
interface HoneytokenOptions {
|
|
510
|
+
/** Base path under which honeytoken tripwires are generated. Default `/__wd`. */
|
|
511
|
+
basePath?: string;
|
|
512
|
+
/** Fixed token (else a random one is generated). */
|
|
513
|
+
token?: string;
|
|
514
|
+
/** Visually-hidden link text. Default `.`. */
|
|
515
|
+
text?: string;
|
|
516
|
+
}
|
|
517
|
+
interface Honeytoken {
|
|
518
|
+
/** The tripwire path to register with a TripwireRule (`tripwire({ paths: [token.path] })`). */
|
|
519
|
+
path: string;
|
|
520
|
+
/** Invisible `<a>` HTML to embed in a page; only a link-following bot requests `path`. */
|
|
521
|
+
linkHtml: string;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Generate a honeytoken (hidden link + tripwire path).
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* import { honeytoken, tripwire, WebDecoy } from '@webdecoy/node';
|
|
529
|
+
* const hp = honeytoken();
|
|
530
|
+
* const sdk = new WebDecoy({ rules: [tripwire({ paths: [hp.path] })] });
|
|
531
|
+
* // ...inject hp.linkHtml into your page's HTML
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
declare function honeytoken(options?: HoneytokenOptions): Honeytoken;
|
|
535
|
+
|
|
450
536
|
/**
|
|
451
537
|
* Rules Engine - Barrel exports
|
|
452
538
|
*/
|
|
@@ -483,6 +569,27 @@ declare function rateLimit(config: RateLimitConfig): Rule;
|
|
|
483
569
|
* ```
|
|
484
570
|
*/
|
|
485
571
|
declare function filter(config: FilterConfig): Rule;
|
|
572
|
+
/**
|
|
573
|
+
* Factory function to create a tripwire (honeypot-path) rule.
|
|
574
|
+
*
|
|
575
|
+
* Deterministic, zero-false-positive: any request for a hidden honeypot path is
|
|
576
|
+
* automated by construction. Detects intent (going where a human can't), which
|
|
577
|
+
* stealth fingerprint-spoofing (e.g. botasaurus) cannot evade.
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* import { WebDecoy, tripwire, honeytoken } from '@webdecoy/node';
|
|
582
|
+
*
|
|
583
|
+
* const hp = honeytoken();
|
|
584
|
+
* const sdk = new WebDecoy({
|
|
585
|
+
* rules: [
|
|
586
|
+
* tripwire({ paths: [hp.path] }), // + built-in scanner-bait paths
|
|
587
|
+
* ],
|
|
588
|
+
* });
|
|
589
|
+
* // inject hp.linkHtml into your pages
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
declare function tripwire(config?: TripwireConfig): Rule;
|
|
486
593
|
|
|
487
594
|
/**
|
|
488
595
|
* Detection engine types.
|
|
@@ -619,6 +726,8 @@ interface EnvironmentalSignals {
|
|
|
619
726
|
fontsInfo?: FontsInfo;
|
|
620
727
|
permissionsInfo?: PermissionsInfo;
|
|
621
728
|
domRectFingerprint?: DOMRectInfo;
|
|
729
|
+
audioInfo?: AudioContextInfo;
|
|
730
|
+
lieDetection?: LieDetectionInfo;
|
|
622
731
|
[key: string]: unknown;
|
|
623
732
|
}
|
|
624
733
|
interface WebRTCInfo {
|
|
@@ -672,6 +781,25 @@ interface DOMRectInfo {
|
|
|
672
781
|
rangeWidth?: number;
|
|
673
782
|
[key: string]: unknown;
|
|
674
783
|
}
|
|
784
|
+
/** AudioContext fingerprint. A real audio stack exposes `baseLatency` and a
|
|
785
|
+
* conventional sample rate; headless/mocked stacks omit or fake these. */
|
|
786
|
+
interface AudioContextInfo {
|
|
787
|
+
supported?: boolean;
|
|
788
|
+
sampleRate?: number;
|
|
789
|
+
state?: string;
|
|
790
|
+
baseLatency?: number | null;
|
|
791
|
+
[key: string]: unknown;
|
|
792
|
+
}
|
|
793
|
+
/** Native-function integrity check. `patched` lists native functions whose
|
|
794
|
+
* `toString()` no longer reports `[native code]` (or whose prototype was
|
|
795
|
+
* tampered with) — the signature of stealth automation hiding itself. A real
|
|
796
|
+
* browser never patches its own natives. */
|
|
797
|
+
interface LieDetectionInfo {
|
|
798
|
+
supported?: boolean;
|
|
799
|
+
patched?: string[];
|
|
800
|
+
patchedCount?: number;
|
|
801
|
+
[key: string]: unknown;
|
|
802
|
+
}
|
|
675
803
|
/** Per-field keystroke statistics for one textarea. */
|
|
676
804
|
interface TextareaKeyboardStats {
|
|
677
805
|
keyCount?: number;
|
|
@@ -848,7 +976,16 @@ declare function recommend(finalScore: number): Recommendation;
|
|
|
848
976
|
* Values match the FCaptcha standalone server (server.js), which is the most
|
|
849
977
|
* complete variant of the engine and the one the reference test suite exercises.
|
|
850
978
|
*/
|
|
851
|
-
/**
|
|
979
|
+
/**
|
|
980
|
+
* Default per-category weights used to compute the final score.
|
|
981
|
+
*
|
|
982
|
+
* `stealth` carries deliberate anti-detection tampering (native functions
|
|
983
|
+
* patched to hide automation). This is the least-ambiguous evidence of a bot —
|
|
984
|
+
* a genuine browser never patches its own natives — so it is weighted highest.
|
|
985
|
+
* Because weights are a simple weighted sum (not required to total 1.0), and
|
|
986
|
+
* `stealth` is 0 for any clean browser, this raises stealth-bot scores without
|
|
987
|
+
* affecting legitimate traffic.
|
|
988
|
+
*/
|
|
852
989
|
declare const DEFAULT_WEIGHTS: Record<string, number>;
|
|
853
990
|
|
|
854
991
|
/** True when `ip` falls inside a known datacenter CIDR block (IPv4 only). */
|
|
@@ -1135,4 +1272,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
|
|
|
1135
1272
|
};
|
|
1136
1273
|
type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
|
|
1137
1274
|
|
|
1138
|
-
export { type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createCaptchaEndpoints, filter, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret };
|
|
1275
|
+
export { type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret, tripwire };
|
package/dist/index.d.ts
CHANGED
|
@@ -73,6 +73,23 @@ interface FilterConfig {
|
|
|
73
73
|
/** Dry run mode: log violations but don't block */
|
|
74
74
|
dryRun?: boolean;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Configuration for tripwire (honeypot-path) rules
|
|
78
|
+
*/
|
|
79
|
+
interface TripwireConfig {
|
|
80
|
+
/** Exact hidden honeypot paths (e.g. a honeytoken path or `/admin-backup.zip`). */
|
|
81
|
+
paths?: string[];
|
|
82
|
+
/** Path prefixes treated as tripwires (e.g. `/.git/`). */
|
|
83
|
+
prefixes?: string[];
|
|
84
|
+
/** Regex patterns for tripwire paths. */
|
|
85
|
+
patterns?: RegExp[];
|
|
86
|
+
/** Include the built-in scanner/scraper bait paths. Default `true`. */
|
|
87
|
+
includeDefaults?: boolean;
|
|
88
|
+
/** Action when a tripwire is hit: 'DENY' (default) or 'THROTTLE'. */
|
|
89
|
+
action?: 'DENY' | 'THROTTLE';
|
|
90
|
+
/** Dry run mode: log the violation but don't block. */
|
|
91
|
+
dryRun?: boolean;
|
|
92
|
+
}
|
|
76
93
|
/**
|
|
77
94
|
* A violation event recorded when a rule triggers
|
|
78
95
|
*/
|
|
@@ -447,6 +464,75 @@ declare class FilterRule implements Rule {
|
|
|
447
464
|
evaluate(context: RuleContext): RuleResult;
|
|
448
465
|
}
|
|
449
466
|
|
|
467
|
+
/**
|
|
468
|
+
* Tripwire Rule (F4 — deception layer)
|
|
469
|
+
*
|
|
470
|
+
* Deterministic, zero-false-positive bot detection: a request for a hidden
|
|
471
|
+
* honeypot path (a "tripwire") that a real user can never reach — because it is
|
|
472
|
+
* only exposed as an invisible link, listed in robots.txt `Disallow`, or is a
|
|
473
|
+
* scanner-bait path no human ever types — is, by construction, automated.
|
|
474
|
+
*
|
|
475
|
+
* Unlike fingerprinting (which a stealth tool like botasaurus is purpose-built
|
|
476
|
+
* to defeat), a tripwire detects *intent* — going where a human cannot — which
|
|
477
|
+
* cannot be spoofed away by a better browser fingerprint.
|
|
478
|
+
*
|
|
479
|
+
* Implemented as a {@link Rule} so it flows through the existing
|
|
480
|
+
* DENY -> block -> violation-report pipeline with no middleware changes.
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Common scanner/scraper bait paths that no legitimate user ever requests.
|
|
485
|
+
* Requesting any of these is a strong automated-intent signal on its own.
|
|
486
|
+
*/
|
|
487
|
+
declare const DEFAULT_TRIPWIRE_PATHS: readonly string[];
|
|
488
|
+
declare class TripwireRule implements Rule {
|
|
489
|
+
readonly name = "tripwire";
|
|
490
|
+
private readonly exact;
|
|
491
|
+
private readonly prefixes;
|
|
492
|
+
private readonly patterns;
|
|
493
|
+
private readonly action;
|
|
494
|
+
private readonly dryRun;
|
|
495
|
+
constructor(config?: TripwireConfig);
|
|
496
|
+
evaluate(context: RuleContext): RuleResult;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Honeytoken generator (F4 — deception layer)
|
|
501
|
+
*
|
|
502
|
+
* Produces a hidden decoy link and the tripwire path it points at. Embed the
|
|
503
|
+
* link in a page (it is visually hidden and marked nofollow/aria-hidden, so a
|
|
504
|
+
* real user never sees or clicks it); register the path with a {@link
|
|
505
|
+
* TripwireRule}. Any client that parses the HTML and follows links — i.e. a
|
|
506
|
+
* scraper/crawler — requests the path and is deterministically flagged, while
|
|
507
|
+
* genuine users are never affected.
|
|
508
|
+
*/
|
|
509
|
+
interface HoneytokenOptions {
|
|
510
|
+
/** Base path under which honeytoken tripwires are generated. Default `/__wd`. */
|
|
511
|
+
basePath?: string;
|
|
512
|
+
/** Fixed token (else a random one is generated). */
|
|
513
|
+
token?: string;
|
|
514
|
+
/** Visually-hidden link text. Default `.`. */
|
|
515
|
+
text?: string;
|
|
516
|
+
}
|
|
517
|
+
interface Honeytoken {
|
|
518
|
+
/** The tripwire path to register with a TripwireRule (`tripwire({ paths: [token.path] })`). */
|
|
519
|
+
path: string;
|
|
520
|
+
/** Invisible `<a>` HTML to embed in a page; only a link-following bot requests `path`. */
|
|
521
|
+
linkHtml: string;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Generate a honeytoken (hidden link + tripwire path).
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* import { honeytoken, tripwire, WebDecoy } from '@webdecoy/node';
|
|
529
|
+
* const hp = honeytoken();
|
|
530
|
+
* const sdk = new WebDecoy({ rules: [tripwire({ paths: [hp.path] })] });
|
|
531
|
+
* // ...inject hp.linkHtml into your page's HTML
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
declare function honeytoken(options?: HoneytokenOptions): Honeytoken;
|
|
535
|
+
|
|
450
536
|
/**
|
|
451
537
|
* Rules Engine - Barrel exports
|
|
452
538
|
*/
|
|
@@ -483,6 +569,27 @@ declare function rateLimit(config: RateLimitConfig): Rule;
|
|
|
483
569
|
* ```
|
|
484
570
|
*/
|
|
485
571
|
declare function filter(config: FilterConfig): Rule;
|
|
572
|
+
/**
|
|
573
|
+
* Factory function to create a tripwire (honeypot-path) rule.
|
|
574
|
+
*
|
|
575
|
+
* Deterministic, zero-false-positive: any request for a hidden honeypot path is
|
|
576
|
+
* automated by construction. Detects intent (going where a human can't), which
|
|
577
|
+
* stealth fingerprint-spoofing (e.g. botasaurus) cannot evade.
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* import { WebDecoy, tripwire, honeytoken } from '@webdecoy/node';
|
|
582
|
+
*
|
|
583
|
+
* const hp = honeytoken();
|
|
584
|
+
* const sdk = new WebDecoy({
|
|
585
|
+
* rules: [
|
|
586
|
+
* tripwire({ paths: [hp.path] }), // + built-in scanner-bait paths
|
|
587
|
+
* ],
|
|
588
|
+
* });
|
|
589
|
+
* // inject hp.linkHtml into your pages
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
declare function tripwire(config?: TripwireConfig): Rule;
|
|
486
593
|
|
|
487
594
|
/**
|
|
488
595
|
* Detection engine types.
|
|
@@ -619,6 +726,8 @@ interface EnvironmentalSignals {
|
|
|
619
726
|
fontsInfo?: FontsInfo;
|
|
620
727
|
permissionsInfo?: PermissionsInfo;
|
|
621
728
|
domRectFingerprint?: DOMRectInfo;
|
|
729
|
+
audioInfo?: AudioContextInfo;
|
|
730
|
+
lieDetection?: LieDetectionInfo;
|
|
622
731
|
[key: string]: unknown;
|
|
623
732
|
}
|
|
624
733
|
interface WebRTCInfo {
|
|
@@ -672,6 +781,25 @@ interface DOMRectInfo {
|
|
|
672
781
|
rangeWidth?: number;
|
|
673
782
|
[key: string]: unknown;
|
|
674
783
|
}
|
|
784
|
+
/** AudioContext fingerprint. A real audio stack exposes `baseLatency` and a
|
|
785
|
+
* conventional sample rate; headless/mocked stacks omit or fake these. */
|
|
786
|
+
interface AudioContextInfo {
|
|
787
|
+
supported?: boolean;
|
|
788
|
+
sampleRate?: number;
|
|
789
|
+
state?: string;
|
|
790
|
+
baseLatency?: number | null;
|
|
791
|
+
[key: string]: unknown;
|
|
792
|
+
}
|
|
793
|
+
/** Native-function integrity check. `patched` lists native functions whose
|
|
794
|
+
* `toString()` no longer reports `[native code]` (or whose prototype was
|
|
795
|
+
* tampered with) — the signature of stealth automation hiding itself. A real
|
|
796
|
+
* browser never patches its own natives. */
|
|
797
|
+
interface LieDetectionInfo {
|
|
798
|
+
supported?: boolean;
|
|
799
|
+
patched?: string[];
|
|
800
|
+
patchedCount?: number;
|
|
801
|
+
[key: string]: unknown;
|
|
802
|
+
}
|
|
675
803
|
/** Per-field keystroke statistics for one textarea. */
|
|
676
804
|
interface TextareaKeyboardStats {
|
|
677
805
|
keyCount?: number;
|
|
@@ -848,7 +976,16 @@ declare function recommend(finalScore: number): Recommendation;
|
|
|
848
976
|
* Values match the FCaptcha standalone server (server.js), which is the most
|
|
849
977
|
* complete variant of the engine and the one the reference test suite exercises.
|
|
850
978
|
*/
|
|
851
|
-
/**
|
|
979
|
+
/**
|
|
980
|
+
* Default per-category weights used to compute the final score.
|
|
981
|
+
*
|
|
982
|
+
* `stealth` carries deliberate anti-detection tampering (native functions
|
|
983
|
+
* patched to hide automation). This is the least-ambiguous evidence of a bot —
|
|
984
|
+
* a genuine browser never patches its own natives — so it is weighted highest.
|
|
985
|
+
* Because weights are a simple weighted sum (not required to total 1.0), and
|
|
986
|
+
* `stealth` is 0 for any clean browser, this raises stealth-bot scores without
|
|
987
|
+
* affecting legitimate traffic.
|
|
988
|
+
*/
|
|
852
989
|
declare const DEFAULT_WEIGHTS: Record<string, number>;
|
|
853
990
|
|
|
854
991
|
/** True when `ip` falls inside a known datacenter CIDR block (IPv4 only). */
|
|
@@ -1135,4 +1272,4 @@ declare function createCaptchaEndpoints(options?: CaptchaEndpointsOptions): {
|
|
|
1135
1272
|
};
|
|
1136
1273
|
type CaptchaEndpoints = ReturnType<typeof createCaptchaEndpoints>;
|
|
1137
1274
|
|
|
1138
|
-
export { type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createCaptchaEndpoints, filter, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret };
|
|
1275
|
+
export { type BehavioralSignals, Captcha, type CaptchaEndpoints, type CaptchaEndpointsOptions, type CaptchaHttpResponse, type CaptchaOptions, type CaptchaRequest, type CategoryScores, type ChallengeData, type ChallengeStore, DEFAULT_TRIPWIRE_PATHS, DEFAULT_WEIGHTS, type Detection, type DetectionContext, DetectionEngine, type DetectionEngineOptions, type EnvironmentalSignals, type FilterConfig, FilterRule, type FingerprintStore, type FormAnalysisSignals, type Honeytoken, type HoneytokenOptions, type IPEnrichmentData, InMemoryChallengeStore, InMemoryFingerprintStore, InMemoryRateLimiter, InMemoryTokenStore, type LocalAnalysis, PoWManager, type PoWManagerOptions, type PoWOutcome, type PoWSolution, type PoWVerification, type ProtectOptions, type ProtectResult, type RateLimitConfig, RateLimitRule, type RateLimiter, type Recommendation, type RequestMetadata, type Rule, type RuleContext, RuleEngine, type RuleEngineResult, type RuleResult, type SDKDetectionRequest, type SDKDetectionResponse, type ScoreResult, type Signals, type StoredChallenge, type TLSInfo, type TemporalSignals, type TextareaKeyboardStats, TokenManager, type TokenManagerOptions, type TokenStore, type TokenVerification, type TripwireConfig, TripwireRule, type Verdict, type VerifyInput, type VerifyResult, type ViolationEvent, WebDecoy, type WebDecoyConfig, calculateCategoryScores, calculateFinalScore, createCaptchaEndpoints, filter, honeytoken, isDatacenterIP, isMobileUA, parseUserAgent, rateLimit, recommend, resolveSecret, tripwire };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
Captcha: () => Captcha,
|
|
34
|
+
DEFAULT_TRIPWIRE_PATHS: () => DEFAULT_TRIPWIRE_PATHS,
|
|
34
35
|
DEFAULT_WEIGHTS: () => DEFAULT_WEIGHTS,
|
|
35
36
|
DetectionEngine: () => DetectionEngine,
|
|
36
37
|
FilterRule: () => FilterRule,
|
|
@@ -42,17 +43,20 @@ __export(index_exports, {
|
|
|
42
43
|
RateLimitRule: () => RateLimitRule,
|
|
43
44
|
RuleEngine: () => RuleEngine,
|
|
44
45
|
TokenManager: () => TokenManager,
|
|
46
|
+
TripwireRule: () => TripwireRule,
|
|
45
47
|
WebDecoy: () => WebDecoy,
|
|
46
48
|
calculateCategoryScores: () => calculateCategoryScores,
|
|
47
49
|
calculateFinalScore: () => calculateFinalScore,
|
|
48
50
|
createCaptchaEndpoints: () => createCaptchaEndpoints,
|
|
49
51
|
filter: () => filter,
|
|
52
|
+
honeytoken: () => honeytoken,
|
|
50
53
|
isDatacenterIP: () => isDatacenterIP2,
|
|
51
54
|
isMobileUA: () => isMobileUA,
|
|
52
55
|
parseUserAgent: () => parseUserAgent,
|
|
53
56
|
rateLimit: () => rateLimit,
|
|
54
57
|
recommend: () => recommend,
|
|
55
|
-
resolveSecret: () => resolveSecret
|
|
58
|
+
resolveSecret: () => resolveSecret,
|
|
59
|
+
tripwire: () => tripwire
|
|
56
60
|
});
|
|
57
61
|
module.exports = __toCommonJS(index_exports);
|
|
58
62
|
|
|
@@ -1346,6 +1350,67 @@ var FilterRule = class {
|
|
|
1346
1350
|
}
|
|
1347
1351
|
};
|
|
1348
1352
|
|
|
1353
|
+
// src/rules/tripwire-rule.ts
|
|
1354
|
+
var DEFAULT_TRIPWIRE_PATHS = [
|
|
1355
|
+
"/.git/config",
|
|
1356
|
+
"/.git/HEAD",
|
|
1357
|
+
"/.env",
|
|
1358
|
+
"/.env.local",
|
|
1359
|
+
"/.env.production",
|
|
1360
|
+
"/wp-config.php",
|
|
1361
|
+
"/config.php",
|
|
1362
|
+
"/.aws/credentials",
|
|
1363
|
+
"/.ssh/id_rsa",
|
|
1364
|
+
"/backup.zip",
|
|
1365
|
+
"/backup.sql",
|
|
1366
|
+
"/database.sql",
|
|
1367
|
+
"/dump.sql",
|
|
1368
|
+
"/.DS_Store",
|
|
1369
|
+
"/phpinfo.php",
|
|
1370
|
+
"/server-status",
|
|
1371
|
+
"/actuator/env",
|
|
1372
|
+
"/.vscode/sftp.json"
|
|
1373
|
+
];
|
|
1374
|
+
function normalizePath(path) {
|
|
1375
|
+
return path.split("?")[0].split("#")[0];
|
|
1376
|
+
}
|
|
1377
|
+
var TripwireRule = class {
|
|
1378
|
+
constructor(config = {}) {
|
|
1379
|
+
this.name = "tripwire";
|
|
1380
|
+
const paths = [...config.paths ?? []];
|
|
1381
|
+
if (config.includeDefaults ?? true) paths.push(...DEFAULT_TRIPWIRE_PATHS);
|
|
1382
|
+
this.exact = new Set(paths);
|
|
1383
|
+
this.prefixes = config.prefixes ?? [];
|
|
1384
|
+
this.patterns = config.patterns ?? [];
|
|
1385
|
+
this.action = config.action ?? "DENY";
|
|
1386
|
+
this.dryRun = config.dryRun ?? false;
|
|
1387
|
+
}
|
|
1388
|
+
evaluate(context) {
|
|
1389
|
+
const path = normalizePath(context.path);
|
|
1390
|
+
const hit = this.exact.has(path) || this.prefixes.some((prefix) => path.startsWith(prefix)) || this.patterns.some((re) => re.test(path));
|
|
1391
|
+
if (hit) {
|
|
1392
|
+
return {
|
|
1393
|
+
action: this.dryRun ? "ALLOW" : this.action,
|
|
1394
|
+
rule: this.name,
|
|
1395
|
+
reason: `Tripwire hit: ${path} \u2014 hidden honeypot path, deterministic automated-intent signal`,
|
|
1396
|
+
metadata: { path, dryRun: this.dryRun, confidence: 100 }
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
return { action: "ALLOW", rule: this.name };
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1403
|
+
// src/rules/honeytoken.ts
|
|
1404
|
+
var import_crypto = require("crypto");
|
|
1405
|
+
function honeytoken(options = {}) {
|
|
1406
|
+
const base = (options.basePath ?? "/__wd").replace(/\/+$/, "");
|
|
1407
|
+
const token = options.token ?? (0, import_crypto.randomBytes)(6).toString("hex");
|
|
1408
|
+
const path = `${base}/${token}`;
|
|
1409
|
+
const text = options.text ?? ".";
|
|
1410
|
+
const linkHtml = `<a href="${path}" aria-hidden="true" tabindex="-1" rel="nofollow noindex" style="position:absolute;left:-9999px;top:auto;width:1px;height:1px;overflow:hidden">${text}</a>`;
|
|
1411
|
+
return { path, linkHtml };
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1349
1414
|
// src/rules/index.ts
|
|
1350
1415
|
function rateLimit(config) {
|
|
1351
1416
|
return new RateLimitRule(config);
|
|
@@ -1353,6 +1418,9 @@ function rateLimit(config) {
|
|
|
1353
1418
|
function filter(config) {
|
|
1354
1419
|
return new FilterRule(config);
|
|
1355
1420
|
}
|
|
1421
|
+
function tripwire(config = {}) {
|
|
1422
|
+
return new TripwireRule(config);
|
|
1423
|
+
}
|
|
1356
1424
|
|
|
1357
1425
|
// src/detection/weights.ts
|
|
1358
1426
|
var DEFAULT_WEIGHTS = {
|
|
@@ -1365,7 +1433,8 @@ var DEFAULT_WEIGHTS = {
|
|
|
1365
1433
|
rate_limit: 0.01,
|
|
1366
1434
|
datacenter: 0.07,
|
|
1367
1435
|
tor_vpn: 0.01,
|
|
1368
|
-
bot: 0.15
|
|
1436
|
+
bot: 0.15,
|
|
1437
|
+
stealth: 0.3
|
|
1369
1438
|
};
|
|
1370
1439
|
var AUTOMATION_UA_PATTERNS = [
|
|
1371
1440
|
/headless/i,
|
|
@@ -1626,9 +1695,7 @@ function detectVisionAI(signals) {
|
|
|
1626
1695
|
// src/detection/detectors/headless.ts
|
|
1627
1696
|
var PLAYWRIGHT_SCORE_MAP = {
|
|
1628
1697
|
playwright_globals: 0.95,
|
|
1629
|
-
webdriver_deleted: 0.8
|
|
1630
|
-
webdriver_configurable: 0.7,
|
|
1631
|
-
chrome_runtime_missing: 0.6
|
|
1698
|
+
webdriver_deleted: 0.8
|
|
1632
1699
|
};
|
|
1633
1700
|
function detectHeadless(signals, userAgent) {
|
|
1634
1701
|
const detections = [];
|
|
@@ -1695,12 +1762,13 @@ function detectHeadless(signals, userAgent) {
|
|
|
1695
1762
|
}
|
|
1696
1763
|
}
|
|
1697
1764
|
const renderer = (env.webglInfo?.renderer ?? "").toLowerCase();
|
|
1698
|
-
|
|
1765
|
+
const softwareRenderer = env.webglInfo?.suspiciousRenderer === true || ["swiftshader", "llvmpipe", "softpipe", "virtualbox", "vmware"].some((r) => renderer.includes(r));
|
|
1766
|
+
if (softwareRenderer) {
|
|
1699
1767
|
detections.push({
|
|
1700
1768
|
category: "headless",
|
|
1701
1769
|
score: 0.8,
|
|
1702
1770
|
confidence: 0.8,
|
|
1703
|
-
reason: "Software WebGL renderer detected"
|
|
1771
|
+
reason: "Software/virtualized WebGL renderer detected"
|
|
1704
1772
|
});
|
|
1705
1773
|
}
|
|
1706
1774
|
const playwright = env.playwright ?? {};
|
|
@@ -2067,7 +2135,7 @@ function detectTouchKinematics(signals) {
|
|
|
2067
2135
|
}
|
|
2068
2136
|
|
|
2069
2137
|
// src/detection/detectors/fingerprint.ts
|
|
2070
|
-
var
|
|
2138
|
+
var import_crypto2 = require("crypto");
|
|
2071
2139
|
function detectFingerprint(signals, ip, siteKey, store) {
|
|
2072
2140
|
const detections = [];
|
|
2073
2141
|
const env = signals.environmental ?? {};
|
|
@@ -2078,7 +2146,7 @@ function detectFingerprint(signals, ip, siteKey, store) {
|
|
|
2078
2146
|
String(automation.platform ?? ""),
|
|
2079
2147
|
String(automation.hardwareConcurrency ?? "")
|
|
2080
2148
|
];
|
|
2081
|
-
const fp = (0,
|
|
2149
|
+
const fp = (0, import_crypto2.createHash)("sha256").update(components.join("|")).digest("hex").slice(0, 16);
|
|
2082
2150
|
store.record(fp, ip, siteKey);
|
|
2083
2151
|
if (store.getIpFpCount(ip) > 5) {
|
|
2084
2152
|
detections.push({
|
|
@@ -2130,6 +2198,57 @@ function detectRateAbuse(ip, siteKey, limiter) {
|
|
|
2130
2198
|
return detections;
|
|
2131
2199
|
}
|
|
2132
2200
|
|
|
2201
|
+
// src/detection/detectors/audio.ts
|
|
2202
|
+
function analyzeAudioContext(audioInfo) {
|
|
2203
|
+
if (!audioInfo) return [];
|
|
2204
|
+
const detections = [];
|
|
2205
|
+
if (audioInfo.supported === false) {
|
|
2206
|
+
detections.push({
|
|
2207
|
+
category: "headless",
|
|
2208
|
+
score: 0.6,
|
|
2209
|
+
confidence: 0.6,
|
|
2210
|
+
reason: "AudioContext unavailable (headless or blocked audio stack)"
|
|
2211
|
+
});
|
|
2212
|
+
return detections;
|
|
2213
|
+
}
|
|
2214
|
+
if (audioInfo.baseLatency === void 0 || audioInfo.baseLatency === null) {
|
|
2215
|
+
detections.push({
|
|
2216
|
+
category: "headless",
|
|
2217
|
+
score: 0.55,
|
|
2218
|
+
confidence: 0.6,
|
|
2219
|
+
reason: "AudioContext missing baseLatency (mocked/headless audio)"
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
const sr = audioInfo.sampleRate;
|
|
2223
|
+
if (sr !== void 0 && sr !== 44100 && sr !== 48e3) {
|
|
2224
|
+
detections.push({
|
|
2225
|
+
category: "headless",
|
|
2226
|
+
score: 0.4,
|
|
2227
|
+
confidence: 0.5,
|
|
2228
|
+
reason: `Unusual AudioContext sample rate (${sr})`
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
return detections;
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
// src/detection/detectors/lies.ts
|
|
2235
|
+
function analyzeLies(lie) {
|
|
2236
|
+
if (!lie || !lie.supported) return [];
|
|
2237
|
+
const patched = lie.patched ?? [];
|
|
2238
|
+
const count = lie.patchedCount ?? patched.length;
|
|
2239
|
+
if (count <= 0) return [];
|
|
2240
|
+
const score = Math.min(0.97, 0.7 + (count - 1) * 0.12);
|
|
2241
|
+
return [
|
|
2242
|
+
{
|
|
2243
|
+
category: "stealth",
|
|
2244
|
+
score,
|
|
2245
|
+
confidence: 0.9,
|
|
2246
|
+
reason: `Native function(s) patched to hide automation: ${patched.join(", ") || `${count} function(s)`}`,
|
|
2247
|
+
details: { patched, patchedCount: count }
|
|
2248
|
+
}
|
|
2249
|
+
];
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2133
2252
|
// src/detection/detectors/headers.ts
|
|
2134
2253
|
var SUSPICIOUS_HEADERS = /* @__PURE__ */ new Set([
|
|
2135
2254
|
"x-requested-with",
|
|
@@ -2807,6 +2926,8 @@ function analyzeAdvancedSignals(signals, userAgent) {
|
|
|
2807
2926
|
if (env.fontsInfo) detections.push(...analyzeFonts(env.fontsInfo, userAgent));
|
|
2808
2927
|
if (env.permissionsInfo) detections.push(...analyzePermissions(env.permissionsInfo));
|
|
2809
2928
|
if (env.domRectFingerprint) detections.push(...analyzeDOMRect(env.domRectFingerprint));
|
|
2929
|
+
if (env.audioInfo) detections.push(...analyzeAudioContext(env.audioInfo));
|
|
2930
|
+
if (env.lieDetection) detections.push(...analyzeLies(env.lieDetection));
|
|
2810
2931
|
return detections;
|
|
2811
2932
|
}
|
|
2812
2933
|
|
|
@@ -2908,7 +3029,7 @@ var DetectionEngine = class {
|
|
|
2908
3029
|
};
|
|
2909
3030
|
|
|
2910
3031
|
// src/captcha/service.ts
|
|
2911
|
-
var
|
|
3032
|
+
var import_crypto5 = require("crypto");
|
|
2912
3033
|
|
|
2913
3034
|
// src/captcha/secret.ts
|
|
2914
3035
|
var INSECURE_DEFAULT_SECRET = "dev-secret-change-in-production";
|
|
@@ -2931,7 +3052,7 @@ function resolveSecret(secret) {
|
|
|
2931
3052
|
}
|
|
2932
3053
|
|
|
2933
3054
|
// src/captcha/pow.ts
|
|
2934
|
-
var
|
|
3055
|
+
var import_crypto3 = require("crypto");
|
|
2935
3056
|
var EXPIRATION_MS = 5 * 60 * 1e3;
|
|
2936
3057
|
var InMemoryChallengeStore = class {
|
|
2937
3058
|
constructor() {
|
|
@@ -2979,8 +3100,8 @@ var PoWManager = class {
|
|
|
2979
3100
|
/** Generate and store a signed challenge. */
|
|
2980
3101
|
generate(siteKey, ip, difficulty) {
|
|
2981
3102
|
const resolvedDifficulty = difficulty ?? this.scaleDifficulty(siteKey, ip);
|
|
2982
|
-
const challengeId = (0,
|
|
2983
|
-
const nonce = (0,
|
|
3103
|
+
const challengeId = (0, import_crypto3.randomBytes)(16).toString("hex");
|
|
3104
|
+
const nonce = (0, import_crypto3.randomBytes)(16).toString("hex");
|
|
2984
3105
|
const timestamp = Date.now();
|
|
2985
3106
|
const expiresAt = timestamp + EXPIRATION_MS;
|
|
2986
3107
|
const challengeData = {
|
|
@@ -2995,7 +3116,7 @@ var PoWManager = class {
|
|
|
2995
3116
|
};
|
|
2996
3117
|
const { sig: _omit, ...toSign } = challengeData;
|
|
2997
3118
|
void _omit;
|
|
2998
|
-
challengeData.sig = (0,
|
|
3119
|
+
challengeData.sig = (0, import_crypto3.createHmac)("sha256", this.secret).update(JSON.stringify(toSign)).digest("hex");
|
|
2999
3120
|
this.store.put({ ...challengeData, ip, createdAt: timestamp });
|
|
3000
3121
|
return challengeData;
|
|
3001
3122
|
}
|
|
@@ -3012,7 +3133,7 @@ var PoWManager = class {
|
|
|
3012
3133
|
}
|
|
3013
3134
|
const solutionKey = `${solution.challengeId}:${solution.nonce}`;
|
|
3014
3135
|
const input = signalsHash ? `${challenge.prefix}:${signalsHash}:${solution.nonce}` : `${challenge.prefix}:${solution.nonce}`;
|
|
3015
|
-
const expectedHash = (0,
|
|
3136
|
+
const expectedHash = (0, import_crypto3.createHash)("sha256").update(input).digest("hex");
|
|
3016
3137
|
if (solution.hash !== expectedHash) {
|
|
3017
3138
|
return { valid: false, reason: "invalid_hash" };
|
|
3018
3139
|
}
|
|
@@ -3034,7 +3155,7 @@ var PoWManager = class {
|
|
|
3034
3155
|
};
|
|
3035
3156
|
|
|
3036
3157
|
// src/captcha/token.ts
|
|
3037
|
-
var
|
|
3158
|
+
var import_crypto4 = require("crypto");
|
|
3038
3159
|
var TOKEN_TTL_SECONDS = 300;
|
|
3039
3160
|
var InMemoryTokenStore = class {
|
|
3040
3161
|
constructor() {
|
|
@@ -3061,10 +3182,10 @@ var TokenManager = class {
|
|
|
3061
3182
|
site_key: siteKey,
|
|
3062
3183
|
timestamp: Math.floor(Date.now() / 1e3),
|
|
3063
3184
|
score: Math.round(score * 1e3) / 1e3,
|
|
3064
|
-
ip_hash: (0,
|
|
3185
|
+
ip_hash: (0, import_crypto4.createHash)("sha256").update(ip).digest("hex").slice(0, 8)
|
|
3065
3186
|
};
|
|
3066
3187
|
const payload = JSON.stringify(data, Object.keys(data).sort());
|
|
3067
|
-
data.sig = (0,
|
|
3188
|
+
data.sig = (0, import_crypto4.createHmac)("sha256", this.secret).update(payload).digest("hex");
|
|
3068
3189
|
return Buffer.from(JSON.stringify(data)).toString("base64url");
|
|
3069
3190
|
}
|
|
3070
3191
|
/** Verify a token: signature, expiry, replay, and optional IP binding. */
|
|
@@ -3082,17 +3203,17 @@ var TokenManager = class {
|
|
|
3082
3203
|
if (!sig) return { valid: false, reason: "invalid_signature" };
|
|
3083
3204
|
delete decoded.sig;
|
|
3084
3205
|
const payload = JSON.stringify(decoded, Object.keys(decoded).sort());
|
|
3085
|
-
const expectedSig = (0,
|
|
3206
|
+
const expectedSig = (0, import_crypto4.createHmac)("sha256", this.secret).update(payload).digest("hex");
|
|
3086
3207
|
const sigBuf = Buffer.from(sig);
|
|
3087
3208
|
const expectedBuf = Buffer.from(expectedSig);
|
|
3088
|
-
if (sigBuf.length !== expectedBuf.length || !(0,
|
|
3209
|
+
if (sigBuf.length !== expectedBuf.length || !(0, import_crypto4.timingSafeEqual)(sigBuf, expectedBuf)) {
|
|
3089
3210
|
return { valid: false, reason: "invalid_signature" };
|
|
3090
3211
|
}
|
|
3091
3212
|
if (this.store.isUsed(sig)) {
|
|
3092
3213
|
return { valid: false, reason: "token_already_used" };
|
|
3093
3214
|
}
|
|
3094
3215
|
if (ip) {
|
|
3095
|
-
const expectedIpHash = (0,
|
|
3216
|
+
const expectedIpHash = (0, import_crypto4.createHash)("sha256").update(ip).digest("hex").slice(0, 8);
|
|
3096
3217
|
if (decoded.ip_hash !== expectedIpHash) {
|
|
3097
3218
|
return { valid: false, reason: "ip_mismatch" };
|
|
3098
3219
|
}
|
|
@@ -3139,7 +3260,7 @@ var Captcha = class {
|
|
|
3139
3260
|
const extraDetections = [];
|
|
3140
3261
|
const clientSignalsHash = input.powSolution?.signalsHash ?? null;
|
|
3141
3262
|
if (input.signalsJson && clientSignalsHash) {
|
|
3142
|
-
const computed = (0,
|
|
3263
|
+
const computed = (0, import_crypto5.createHash)("sha256").update(input.signalsJson).digest("hex");
|
|
3143
3264
|
if (computed !== clientSignalsHash) {
|
|
3144
3265
|
extraDetections.push({
|
|
3145
3266
|
category: "bot",
|
|
@@ -3266,6 +3387,7 @@ function createCaptchaEndpoints(options = {}) {
|
|
|
3266
3387
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3267
3388
|
0 && (module.exports = {
|
|
3268
3389
|
Captcha,
|
|
3390
|
+
DEFAULT_TRIPWIRE_PATHS,
|
|
3269
3391
|
DEFAULT_WEIGHTS,
|
|
3270
3392
|
DetectionEngine,
|
|
3271
3393
|
FilterRule,
|
|
@@ -3277,15 +3399,18 @@ function createCaptchaEndpoints(options = {}) {
|
|
|
3277
3399
|
RateLimitRule,
|
|
3278
3400
|
RuleEngine,
|
|
3279
3401
|
TokenManager,
|
|
3402
|
+
TripwireRule,
|
|
3280
3403
|
WebDecoy,
|
|
3281
3404
|
calculateCategoryScores,
|
|
3282
3405
|
calculateFinalScore,
|
|
3283
3406
|
createCaptchaEndpoints,
|
|
3284
3407
|
filter,
|
|
3408
|
+
honeytoken,
|
|
3285
3409
|
isDatacenterIP,
|
|
3286
3410
|
isMobileUA,
|
|
3287
3411
|
parseUserAgent,
|
|
3288
3412
|
rateLimit,
|
|
3289
3413
|
recommend,
|
|
3290
|
-
resolveSecret
|
|
3414
|
+
resolveSecret,
|
|
3415
|
+
tripwire
|
|
3291
3416
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1288,6 +1288,67 @@ var FilterRule = class {
|
|
|
1288
1288
|
}
|
|
1289
1289
|
};
|
|
1290
1290
|
|
|
1291
|
+
// src/rules/tripwire-rule.ts
|
|
1292
|
+
var DEFAULT_TRIPWIRE_PATHS = [
|
|
1293
|
+
"/.git/config",
|
|
1294
|
+
"/.git/HEAD",
|
|
1295
|
+
"/.env",
|
|
1296
|
+
"/.env.local",
|
|
1297
|
+
"/.env.production",
|
|
1298
|
+
"/wp-config.php",
|
|
1299
|
+
"/config.php",
|
|
1300
|
+
"/.aws/credentials",
|
|
1301
|
+
"/.ssh/id_rsa",
|
|
1302
|
+
"/backup.zip",
|
|
1303
|
+
"/backup.sql",
|
|
1304
|
+
"/database.sql",
|
|
1305
|
+
"/dump.sql",
|
|
1306
|
+
"/.DS_Store",
|
|
1307
|
+
"/phpinfo.php",
|
|
1308
|
+
"/server-status",
|
|
1309
|
+
"/actuator/env",
|
|
1310
|
+
"/.vscode/sftp.json"
|
|
1311
|
+
];
|
|
1312
|
+
function normalizePath(path) {
|
|
1313
|
+
return path.split("?")[0].split("#")[0];
|
|
1314
|
+
}
|
|
1315
|
+
var TripwireRule = class {
|
|
1316
|
+
constructor(config = {}) {
|
|
1317
|
+
this.name = "tripwire";
|
|
1318
|
+
const paths = [...config.paths ?? []];
|
|
1319
|
+
if (config.includeDefaults ?? true) paths.push(...DEFAULT_TRIPWIRE_PATHS);
|
|
1320
|
+
this.exact = new Set(paths);
|
|
1321
|
+
this.prefixes = config.prefixes ?? [];
|
|
1322
|
+
this.patterns = config.patterns ?? [];
|
|
1323
|
+
this.action = config.action ?? "DENY";
|
|
1324
|
+
this.dryRun = config.dryRun ?? false;
|
|
1325
|
+
}
|
|
1326
|
+
evaluate(context) {
|
|
1327
|
+
const path = normalizePath(context.path);
|
|
1328
|
+
const hit = this.exact.has(path) || this.prefixes.some((prefix) => path.startsWith(prefix)) || this.patterns.some((re) => re.test(path));
|
|
1329
|
+
if (hit) {
|
|
1330
|
+
return {
|
|
1331
|
+
action: this.dryRun ? "ALLOW" : this.action,
|
|
1332
|
+
rule: this.name,
|
|
1333
|
+
reason: `Tripwire hit: ${path} \u2014 hidden honeypot path, deterministic automated-intent signal`,
|
|
1334
|
+
metadata: { path, dryRun: this.dryRun, confidence: 100 }
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
return { action: "ALLOW", rule: this.name };
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
// src/rules/honeytoken.ts
|
|
1342
|
+
import { randomBytes } from "crypto";
|
|
1343
|
+
function honeytoken(options = {}) {
|
|
1344
|
+
const base = (options.basePath ?? "/__wd").replace(/\/+$/, "");
|
|
1345
|
+
const token = options.token ?? randomBytes(6).toString("hex");
|
|
1346
|
+
const path = `${base}/${token}`;
|
|
1347
|
+
const text = options.text ?? ".";
|
|
1348
|
+
const linkHtml = `<a href="${path}" aria-hidden="true" tabindex="-1" rel="nofollow noindex" style="position:absolute;left:-9999px;top:auto;width:1px;height:1px;overflow:hidden">${text}</a>`;
|
|
1349
|
+
return { path, linkHtml };
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1291
1352
|
// src/rules/index.ts
|
|
1292
1353
|
function rateLimit(config) {
|
|
1293
1354
|
return new RateLimitRule(config);
|
|
@@ -1295,6 +1356,9 @@ function rateLimit(config) {
|
|
|
1295
1356
|
function filter(config) {
|
|
1296
1357
|
return new FilterRule(config);
|
|
1297
1358
|
}
|
|
1359
|
+
function tripwire(config = {}) {
|
|
1360
|
+
return new TripwireRule(config);
|
|
1361
|
+
}
|
|
1298
1362
|
|
|
1299
1363
|
// src/detection/weights.ts
|
|
1300
1364
|
var DEFAULT_WEIGHTS = {
|
|
@@ -1307,7 +1371,8 @@ var DEFAULT_WEIGHTS = {
|
|
|
1307
1371
|
rate_limit: 0.01,
|
|
1308
1372
|
datacenter: 0.07,
|
|
1309
1373
|
tor_vpn: 0.01,
|
|
1310
|
-
bot: 0.15
|
|
1374
|
+
bot: 0.15,
|
|
1375
|
+
stealth: 0.3
|
|
1311
1376
|
};
|
|
1312
1377
|
var AUTOMATION_UA_PATTERNS = [
|
|
1313
1378
|
/headless/i,
|
|
@@ -1568,9 +1633,7 @@ function detectVisionAI(signals) {
|
|
|
1568
1633
|
// src/detection/detectors/headless.ts
|
|
1569
1634
|
var PLAYWRIGHT_SCORE_MAP = {
|
|
1570
1635
|
playwright_globals: 0.95,
|
|
1571
|
-
webdriver_deleted: 0.8
|
|
1572
|
-
webdriver_configurable: 0.7,
|
|
1573
|
-
chrome_runtime_missing: 0.6
|
|
1636
|
+
webdriver_deleted: 0.8
|
|
1574
1637
|
};
|
|
1575
1638
|
function detectHeadless(signals, userAgent) {
|
|
1576
1639
|
const detections = [];
|
|
@@ -1637,12 +1700,13 @@ function detectHeadless(signals, userAgent) {
|
|
|
1637
1700
|
}
|
|
1638
1701
|
}
|
|
1639
1702
|
const renderer = (env.webglInfo?.renderer ?? "").toLowerCase();
|
|
1640
|
-
|
|
1703
|
+
const softwareRenderer = env.webglInfo?.suspiciousRenderer === true || ["swiftshader", "llvmpipe", "softpipe", "virtualbox", "vmware"].some((r) => renderer.includes(r));
|
|
1704
|
+
if (softwareRenderer) {
|
|
1641
1705
|
detections.push({
|
|
1642
1706
|
category: "headless",
|
|
1643
1707
|
score: 0.8,
|
|
1644
1708
|
confidence: 0.8,
|
|
1645
|
-
reason: "Software WebGL renderer detected"
|
|
1709
|
+
reason: "Software/virtualized WebGL renderer detected"
|
|
1646
1710
|
});
|
|
1647
1711
|
}
|
|
1648
1712
|
const playwright = env.playwright ?? {};
|
|
@@ -2072,6 +2136,57 @@ function detectRateAbuse(ip, siteKey, limiter) {
|
|
|
2072
2136
|
return detections;
|
|
2073
2137
|
}
|
|
2074
2138
|
|
|
2139
|
+
// src/detection/detectors/audio.ts
|
|
2140
|
+
function analyzeAudioContext(audioInfo) {
|
|
2141
|
+
if (!audioInfo) return [];
|
|
2142
|
+
const detections = [];
|
|
2143
|
+
if (audioInfo.supported === false) {
|
|
2144
|
+
detections.push({
|
|
2145
|
+
category: "headless",
|
|
2146
|
+
score: 0.6,
|
|
2147
|
+
confidence: 0.6,
|
|
2148
|
+
reason: "AudioContext unavailable (headless or blocked audio stack)"
|
|
2149
|
+
});
|
|
2150
|
+
return detections;
|
|
2151
|
+
}
|
|
2152
|
+
if (audioInfo.baseLatency === void 0 || audioInfo.baseLatency === null) {
|
|
2153
|
+
detections.push({
|
|
2154
|
+
category: "headless",
|
|
2155
|
+
score: 0.55,
|
|
2156
|
+
confidence: 0.6,
|
|
2157
|
+
reason: "AudioContext missing baseLatency (mocked/headless audio)"
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
const sr = audioInfo.sampleRate;
|
|
2161
|
+
if (sr !== void 0 && sr !== 44100 && sr !== 48e3) {
|
|
2162
|
+
detections.push({
|
|
2163
|
+
category: "headless",
|
|
2164
|
+
score: 0.4,
|
|
2165
|
+
confidence: 0.5,
|
|
2166
|
+
reason: `Unusual AudioContext sample rate (${sr})`
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
return detections;
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
// src/detection/detectors/lies.ts
|
|
2173
|
+
function analyzeLies(lie) {
|
|
2174
|
+
if (!lie || !lie.supported) return [];
|
|
2175
|
+
const patched = lie.patched ?? [];
|
|
2176
|
+
const count = lie.patchedCount ?? patched.length;
|
|
2177
|
+
if (count <= 0) return [];
|
|
2178
|
+
const score = Math.min(0.97, 0.7 + (count - 1) * 0.12);
|
|
2179
|
+
return [
|
|
2180
|
+
{
|
|
2181
|
+
category: "stealth",
|
|
2182
|
+
score,
|
|
2183
|
+
confidence: 0.9,
|
|
2184
|
+
reason: `Native function(s) patched to hide automation: ${patched.join(", ") || `${count} function(s)`}`,
|
|
2185
|
+
details: { patched, patchedCount: count }
|
|
2186
|
+
}
|
|
2187
|
+
];
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2075
2190
|
// src/detection/detectors/headers.ts
|
|
2076
2191
|
var SUSPICIOUS_HEADERS = /* @__PURE__ */ new Set([
|
|
2077
2192
|
"x-requested-with",
|
|
@@ -2749,6 +2864,8 @@ function analyzeAdvancedSignals(signals, userAgent) {
|
|
|
2749
2864
|
if (env.fontsInfo) detections.push(...analyzeFonts(env.fontsInfo, userAgent));
|
|
2750
2865
|
if (env.permissionsInfo) detections.push(...analyzePermissions(env.permissionsInfo));
|
|
2751
2866
|
if (env.domRectFingerprint) detections.push(...analyzeDOMRect(env.domRectFingerprint));
|
|
2867
|
+
if (env.audioInfo) detections.push(...analyzeAudioContext(env.audioInfo));
|
|
2868
|
+
if (env.lieDetection) detections.push(...analyzeLies(env.lieDetection));
|
|
2752
2869
|
return detections;
|
|
2753
2870
|
}
|
|
2754
2871
|
|
|
@@ -2873,7 +2990,7 @@ function resolveSecret(secret) {
|
|
|
2873
2990
|
}
|
|
2874
2991
|
|
|
2875
2992
|
// src/captcha/pow.ts
|
|
2876
|
-
import { createHash as createHash2, createHmac, randomBytes } from "crypto";
|
|
2993
|
+
import { createHash as createHash2, createHmac, randomBytes as randomBytes2 } from "crypto";
|
|
2877
2994
|
var EXPIRATION_MS = 5 * 60 * 1e3;
|
|
2878
2995
|
var InMemoryChallengeStore = class {
|
|
2879
2996
|
constructor() {
|
|
@@ -2921,8 +3038,8 @@ var PoWManager = class {
|
|
|
2921
3038
|
/** Generate and store a signed challenge. */
|
|
2922
3039
|
generate(siteKey, ip, difficulty) {
|
|
2923
3040
|
const resolvedDifficulty = difficulty ?? this.scaleDifficulty(siteKey, ip);
|
|
2924
|
-
const challengeId =
|
|
2925
|
-
const nonce =
|
|
3041
|
+
const challengeId = randomBytes2(16).toString("hex");
|
|
3042
|
+
const nonce = randomBytes2(16).toString("hex");
|
|
2926
3043
|
const timestamp = Date.now();
|
|
2927
3044
|
const expiresAt = timestamp + EXPIRATION_MS;
|
|
2928
3045
|
const challengeData = {
|
|
@@ -3207,6 +3324,7 @@ function createCaptchaEndpoints(options = {}) {
|
|
|
3207
3324
|
}
|
|
3208
3325
|
export {
|
|
3209
3326
|
Captcha,
|
|
3327
|
+
DEFAULT_TRIPWIRE_PATHS,
|
|
3210
3328
|
DEFAULT_WEIGHTS,
|
|
3211
3329
|
DetectionEngine,
|
|
3212
3330
|
FilterRule,
|
|
@@ -3218,15 +3336,18 @@ export {
|
|
|
3218
3336
|
RateLimitRule,
|
|
3219
3337
|
RuleEngine,
|
|
3220
3338
|
TokenManager,
|
|
3339
|
+
TripwireRule,
|
|
3221
3340
|
WebDecoy,
|
|
3222
3341
|
calculateCategoryScores,
|
|
3223
3342
|
calculateFinalScore,
|
|
3224
3343
|
createCaptchaEndpoints,
|
|
3225
3344
|
filter,
|
|
3345
|
+
honeytoken,
|
|
3226
3346
|
isDatacenterIP2 as isDatacenterIP,
|
|
3227
3347
|
isMobileUA,
|
|
3228
3348
|
parseUserAgent,
|
|
3229
3349
|
rateLimit,
|
|
3230
3350
|
recommend,
|
|
3231
|
-
resolveSecret
|
|
3351
|
+
resolveSecret,
|
|
3352
|
+
tripwire
|
|
3232
3353
|
};
|