@kya-os/checkpoint-shared 1.7.0 → 1.9.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/CHANGELOG.md +159 -9
- package/README.md +24 -7
- package/dist/agent-catalog.d.mts +12 -0
- package/dist/agent-catalog.d.mts.map +1 -0
- package/dist/agent-catalog.d.ts +12 -0
- package/dist/agent-catalog.d.ts.map +1 -0
- package/dist/agent-catalog.js +105 -0
- package/dist/agent-catalog.mjs +105 -0
- package/dist/agent-catalog.mjs.map +1 -0
- package/dist/beacon-nonce/index.d.mts +1 -0
- package/dist/beacon-nonce/index.d.mts.map +1 -1
- package/dist/beacon-nonce/index.d.ts +1 -0
- package/dist/beacon-nonce/index.d.ts.map +1 -1
- package/dist/beacon-nonce/index.js +9 -3
- package/dist/beacon-nonce/index.mjs +9 -4
- package/dist/beacon-nonce/index.mjs.map +1 -1
- package/dist/beacon-types/index.d.mts +41 -1
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +41 -1
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +153 -4
- package/dist/beacon-types/index.mjs +139 -4
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/{browser-posture-BLhw-MON.d.mts → browser-posture-5fPrsxx7.d.mts} +6 -6
- package/dist/{browser-posture-BLhw-MON.d.mts.map → browser-posture-5fPrsxx7.d.mts.map} +1 -1
- package/dist/{browser-posture-B8YiPa5c.d.ts → browser-posture-CCR1kh5e.d.ts} +6 -6
- package/dist/{browser-posture-B8YiPa5c.d.ts.map → browser-posture-CCR1kh5e.d.ts.map} +1 -1
- package/dist/browser-posture-cookie.js +1 -1
- package/dist/browser-posture-cookie.mjs +1 -1
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof-verifier-DvsOmFrM.js +202 -0
- package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs +180 -0
- package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs.map +1 -0
- package/dist/browser-posture-proof-verifier.d.mts +25 -0
- package/dist/browser-posture-proof-verifier.d.mts.map +1 -0
- package/dist/browser-posture-proof-verifier.d.ts +25 -0
- package/dist/browser-posture-proof-verifier.d.ts.map +1 -0
- package/dist/browser-posture-proof-verifier.js +7 -0
- package/dist/browser-posture-proof-verifier.mjs +3 -0
- package/dist/browser-posture-proof.d.mts +4 -5
- package/dist/browser-posture-proof.d.mts.map +1 -1
- package/dist/browser-posture-proof.d.ts +4 -5
- package/dist/browser-posture-proof.d.ts.map +1 -1
- package/dist/browser-posture-proof.js +10 -79
- package/dist/browser-posture-proof.mjs +6 -77
- package/dist/browser-posture-proof.mjs.map +1 -1
- package/dist/browser-posture.d.mts +1 -1
- package/dist/browser-posture.d.ts +1 -1
- package/dist/browser-posture.js +6 -5
- package/dist/browser-posture.mjs +4 -3
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +25 -286
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +25 -286
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/canonical-signer/index.js +30 -28
- package/dist/canonical-signer/index.mjs +31 -1
- package/dist/canonical-signer/index.mjs.map +1 -1
- package/dist/clearance.d.mts +1 -1
- package/dist/clearance.d.ts +1 -1
- package/dist/clearance.js +2 -2
- package/dist/clearance.mjs +2 -2
- package/dist/client-ip-B7w-uHfS.d.mts +55 -0
- package/dist/client-ip-B7w-uHfS.d.mts.map +1 -0
- package/dist/client-ip-B7w-uHfS.d.ts +55 -0
- package/dist/client-ip-B7w-uHfS.d.ts.map +1 -0
- package/dist/{client-ip-CW6pRyLf.js → client-ip-B8wFzJ5f.js} +117 -7
- package/dist/{client-ip-B2Xeo-GK.mjs → client-ip-DIJyr6px.mjs} +113 -9
- package/dist/client-ip-DIJyr6px.mjs.map +1 -0
- package/dist/client-ip.d.mts +2 -2
- package/dist/client-ip.d.ts +2 -2
- package/dist/client-ip.js +3 -2
- package/dist/client-ip.mjs +2 -2
- package/dist/consent-handoff.d.mts +0 -3
- package/dist/consent-handoff.d.mts.map +1 -1
- package/dist/consent-handoff.d.ts +0 -3
- package/dist/consent-handoff.d.ts.map +1 -1
- package/dist/consent-handoff.mjs.map +1 -1
- package/dist/default-sign-in-host.d.mts +10 -0
- package/dist/default-sign-in-host.d.mts.map +1 -0
- package/dist/default-sign-in-host.d.ts +10 -0
- package/dist/default-sign-in-host.d.ts.map +1 -0
- package/dist/default-sign-in-host.js +72 -0
- package/dist/default-sign-in-host.mjs +66 -0
- package/dist/default-sign-in-host.mjs.map +1 -0
- package/dist/detection-reason-mapping-B9RSkOs8.js +277 -0
- package/dist/detection-reason-mapping-BGymWIPl.mjs +249 -0
- package/dist/detection-reason-mapping-BGymWIPl.mjs.map +1 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.mts +52 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.mts.map +1 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.ts +52 -0
- package/dist/detection-reason-mapping-CQexNvR7.d.ts.map +1 -0
- package/dist/engine-enforcing-AYEcgNsb.js +39 -0
- package/dist/engine-enforcing-B5eNfCpG.mjs +29 -0
- package/dist/engine-enforcing-B5eNfCpG.mjs.map +1 -0
- package/dist/engine-enforcing-DiOclGqf.d.mts +11 -0
- package/dist/engine-enforcing-DiOclGqf.d.mts.map +1 -0
- package/dist/engine-enforcing-DiOclGqf.d.ts +11 -0
- package/dist/engine-enforcing-DiOclGqf.d.ts.map +1 -0
- package/dist/engine-info.d.mts +2 -0
- package/dist/engine-info.d.ts +2 -0
- package/dist/engine-info.js +4 -0
- package/dist/engine-info.mjs +3 -0
- package/dist/errors/index.d.mts +6 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +28 -6
- package/dist/errors/index.mjs +28 -6
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{external-B7WI9FyQ.d.ts → external-m3Kmafwj.d.mts} +2 -2
- package/dist/{external-B7WI9FyQ.d.mts.map → external-m3Kmafwj.d.mts.map} +1 -1
- package/dist/{external-B7WI9FyQ.d.mts → external-m3Kmafwj.d.ts} +2 -2
- package/dist/{external-B7WI9FyQ.d.ts.map → external-m3Kmafwj.d.ts.map} +1 -1
- package/dist/fetcher-C8qvwdnA.d.ts +44 -0
- package/dist/fetcher-C8qvwdnA.d.ts.map +1 -0
- package/dist/fetcher-D2vjr7jB.d.mts +44 -0
- package/dist/fetcher-D2vjr7jB.d.mts.map +1 -0
- package/dist/gateway-client-ip.d.mts +1 -3
- package/dist/gateway-client-ip.d.mts.map +1 -1
- package/dist/gateway-client-ip.d.ts +1 -3
- package/dist/gateway-client-ip.d.ts.map +1 -1
- package/dist/gateway-client-ip.js +2 -2
- package/dist/gateway-client-ip.mjs +2 -2
- package/dist/gateway-client-ip.mjs.map +1 -1
- package/dist/host-adapter/index.d.mts +2 -2
- package/dist/host-adapter/index.d.ts +2 -2
- package/dist/host-adapter/index.js +2 -1
- package/dist/host-adapter/index.mjs +2 -2
- package/dist/{host-adapter-C-4IxmqM.mjs → host-adapter-BKdQHwbi.mjs} +56 -3
- package/dist/{host-adapter-C-4IxmqM.mjs.map → host-adapter-BKdQHwbi.mjs.map} +1 -1
- package/dist/{host-adapter-CwW9YB0U.js → host-adapter-bWftXA9T.js} +60 -1
- package/dist/index-DnFsmr_o.d.ts +156 -0
- package/dist/index-DnFsmr_o.d.ts.map +1 -0
- package/dist/index-rvw5Bz-r.d.mts +156 -0
- package/dist/index-rvw5Bz-r.d.mts.map +1 -0
- package/dist/index.d.mts +6681 -11335
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +6681 -11335
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2322 -6900
- package/dist/index.mjs +2236 -6574
- package/dist/index.mjs.map +1 -1
- package/dist/{kya-http-error-codes-UYb1zpGM.js → kya-http-error-codes-B4rUmUEI.js} +2 -0
- package/dist/{kya-http-error-codes-7ewV5RuK.d.ts → kya-http-error-codes-C14E4gi3.d.mts} +2 -1
- package/dist/kya-http-error-codes-C14E4gi3.d.mts.map +1 -0
- package/dist/{kya-http-error-codes-7ewV5RuK.d.mts → kya-http-error-codes-C14E4gi3.d.ts} +2 -1
- package/dist/kya-http-error-codes-C14E4gi3.d.ts.map +1 -0
- package/dist/{kya-http-error-codes-C2JiWPsi.mjs → kya-http-error-codes-DSBrxNry.mjs} +3 -1
- package/dist/kya-http-error-codes-DSBrxNry.mjs.map +1 -0
- package/dist/kya-http.d.mts +3 -3
- package/dist/kya-http.d.ts +3 -3
- package/dist/kya-http.js +10 -2
- package/dist/kya-http.mjs +4 -3
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -1
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -1
- package/dist/mcpi/dashboard-config/index.mjs.map +1 -1
- package/dist/mcpi/status-list/index.d.mts +72 -0
- package/dist/mcpi/status-list/index.d.mts.map +1 -0
- package/dist/mcpi/status-list/index.d.ts +72 -0
- package/dist/mcpi/status-list/index.d.ts.map +1 -0
- package/dist/mcpi/status-list/index.js +703 -0
- package/dist/mcpi/status-list/index.mjs +684 -0
- package/dist/mcpi/status-list/index.mjs.map +1 -0
- package/dist/patterns-Bp40cwh2.d.mts +110 -0
- package/dist/patterns-Bp40cwh2.d.mts.map +1 -0
- package/dist/patterns-Bp40cwh2.d.ts +110 -0
- package/dist/patterns-Bp40cwh2.d.ts.map +1 -0
- package/dist/patterns-CiMpbdAF.js +243 -0
- package/dist/patterns-D4OAsNQY.mjs +173 -0
- package/dist/patterns-D4OAsNQY.mjs.map +1 -0
- package/dist/patterns.d.mts +2 -0
- package/dist/patterns.d.ts +2 -0
- package/dist/patterns.js +15 -0
- package/dist/patterns.mjs +3 -0
- package/dist/policy/enforcement.d.mts +3 -2
- package/dist/policy/enforcement.d.ts +3 -2
- package/dist/policy/enforcement.js +8 -2
- package/dist/policy/enforcement.mjs +3 -2
- package/dist/policy/fetcher.d.mts +2 -0
- package/dist/policy/fetcher.d.ts +2 -0
- package/dist/policy/fetcher.js +240 -0
- package/dist/policy/fetcher.mjs +238 -0
- package/dist/policy/fetcher.mjs.map +1 -0
- package/dist/policy/schemas.d.mts +3 -0
- package/dist/policy/schemas.d.ts +3 -0
- package/dist/policy/schemas.js +27 -0
- package/dist/policy/schemas.mjs +4 -0
- package/dist/{posture-origins-Ba83O0cD.mjs → posture-origins-Ci6k4Zh1.js} +24 -173
- package/dist/{posture-origins-CdVOdiMT.js → posture-origins-DGyS4Vuk.mjs} +2 -267
- package/dist/posture-origins-DGyS4Vuk.mjs.map +1 -0
- package/dist/{project-verification-key-BccT12tQ.js → project-verification-key-B-L3D2nC.js} +1 -1
- package/dist/{project-verification-key-66N4edKn.mjs → project-verification-key-CWXdu3-n.mjs} +2 -2
- package/dist/{project-verification-key-66N4edKn.mjs.map → project-verification-key-CWXdu3-n.mjs.map} +1 -1
- package/dist/provider-registry.d.mts +2 -0
- package/dist/provider-registry.d.ts +2 -0
- package/dist/provider-registry.js +51 -0
- package/dist/provider-registry.mjs +3 -0
- package/dist/reason-codes.d.mts +2 -0
- package/dist/reason-codes.d.ts +2 -0
- package/dist/reason-codes.js +8 -0
- package/dist/reason-codes.mjs +3 -0
- package/dist/{registered-sid-hUl-bvM5.mjs → registered-sid-26hNxp6t.mjs} +11 -2
- package/dist/registered-sid-26hNxp6t.mjs.map +1 -0
- package/dist/registered-sid-D6KCaT1E.d.mts +33 -0
- package/dist/registered-sid-D6KCaT1E.d.mts.map +1 -0
- package/dist/registered-sid-D6KCaT1E.d.ts +33 -0
- package/dist/registered-sid-D6KCaT1E.d.ts.map +1 -0
- package/dist/{registered-sid-eLCNZvIF.js → registered-sid-DVGTSH0L.js} +15 -0
- package/dist/ruleset-hash-Cmv8MSO5.js +34 -0
- package/dist/ruleset-hash-IRN5eI9H.d.mts +5 -0
- package/dist/ruleset-hash-IRN5eI9H.d.mts.map +1 -0
- package/dist/ruleset-hash-IRN5eI9H.d.ts +5 -0
- package/dist/ruleset-hash-IRN5eI9H.d.ts.map +1 -0
- package/dist/ruleset-hash-QQIaLuPi.mjs +30 -0
- package/dist/ruleset-hash-QQIaLuPi.mjs.map +1 -0
- package/dist/{schemas-YhagYDx_.js → schemas-BlScS1it.js} +0 -20
- package/dist/{index-HaqfPtaL.d.ts → schemas-CGKHzcMV.d.ts} +23 -195
- package/dist/schemas-CGKHzcMV.d.ts.map +1 -0
- package/dist/schemas-Cm4C4Z5G.js +703 -0
- package/dist/schemas-DPIT8usF.mjs +525 -0
- package/dist/schemas-DPIT8usF.mjs.map +1 -0
- package/dist/{schemas-7qodsG-Z.mjs → schemas-IHAhH3gV.mjs} +2 -16
- package/dist/schemas-IHAhH3gV.mjs.map +1 -0
- package/dist/{index-B7rTovHa.d.mts → schemas-m-GqyfyO.d.mts} +23 -195
- package/dist/schemas-m-GqyfyO.d.mts.map +1 -0
- package/dist/{step-up-COlmWJN8.mjs → step-up-BK0oBi11.mjs} +91 -41
- package/dist/step-up-BK0oBi11.mjs.map +1 -0
- package/dist/{step-up-C2d8C20x.js → step-up-Bp8RAQwv.js} +117 -55
- package/dist/{step-up-BjP--hG-.d.mts → step-up-Bz12gYKT.d.mts} +28 -12
- package/dist/step-up-Bz12gYKT.d.mts.map +1 -0
- package/dist/{step-up-BjP--hG-.d.ts → step-up-Bz12gYKT.d.ts} +28 -12
- package/dist/step-up-Bz12gYKT.d.ts.map +1 -0
- package/dist/test-fixtures/index.d.mts +4 -4
- package/dist/test-fixtures/index.d.mts.map +1 -1
- package/dist/test-fixtures/index.d.ts +4 -4
- package/dist/test-fixtures/index.d.ts.map +1 -1
- package/dist/test-fixtures/index.js +4 -4
- package/dist/test-fixtures/index.mjs +4 -4
- package/dist/test-fixtures/index.mjs.map +1 -1
- package/dist/tool-protection/index.d.mts +12 -0
- package/dist/tool-protection/index.d.mts.map +1 -1
- package/dist/tool-protection/index.d.ts +12 -0
- package/dist/tool-protection/index.d.ts.map +1 -1
- package/dist/tool-protection/index.js +46 -0
- package/dist/tool-protection/index.mjs +44 -1
- package/dist/tool-protection/index.mjs.map +1 -1
- package/dist/verification-BAw9N8Pt.js +181 -0
- package/dist/verification-Cvvv86TT.mjs +123 -0
- package/dist/verification-Cvvv86TT.mjs.map +1 -0
- package/fixtures/client-ip-resolution.n01.json +101 -0
- package/fixtures/kya-http/error-codes.json +2 -1
- package/fixtures/reviewer-grant-revocation.v1.json +53 -81
- package/package.json +55 -4
- package/dist/client-ip-B2Xeo-GK.mjs.map +0 -1
- package/dist/client-ip-DFamiNoz.d.mts +0 -34
- package/dist/client-ip-DFamiNoz.d.mts.map +0 -1
- package/dist/client-ip-DFamiNoz.d.ts +0 -34
- package/dist/client-ip-DFamiNoz.d.ts.map +0 -1
- package/dist/index-B7rTovHa.d.mts.map +0 -1
- package/dist/index-HaqfPtaL.d.ts.map +0 -1
- package/dist/kya-http-error-codes-7ewV5RuK.d.mts.map +0 -1
- package/dist/kya-http-error-codes-7ewV5RuK.d.ts.map +0 -1
- package/dist/kya-http-error-codes-C2JiWPsi.mjs.map +0 -1
- package/dist/posture-origins-Ba83O0cD.mjs.map +0 -1
- package/dist/registered-sid-D3g-gZQF.d.mts +0 -11
- package/dist/registered-sid-D3g-gZQF.d.mts.map +0 -1
- package/dist/registered-sid-D3g-gZQF.d.ts +0 -11
- package/dist/registered-sid-D3g-gZQF.d.ts.map +0 -1
- package/dist/registered-sid-hUl-bvM5.mjs.map +0 -1
- package/dist/schemas-7qodsG-Z.mjs.map +0 -1
- package/dist/step-up-BjP--hG-.d.mts.map +0 -1
- package/dist/step-up-BjP--hG-.d.ts.map +0 -1
- package/dist/step-up-COlmWJN8.mjs.map +0 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
//#region src/constants/patterns.ts
|
|
2
|
+
/**
|
|
3
|
+
* Regular Expression Patterns
|
|
4
|
+
*
|
|
5
|
+
* Common regex patterns used for validation and detection
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validation Patterns
|
|
9
|
+
*/
|
|
10
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
11
|
+
const VALIDATION_PATTERNS = {
|
|
12
|
+
UUID: UUID_PATTERN,
|
|
13
|
+
ULID: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
14
|
+
SLUG: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
|
|
15
|
+
IPV4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
|
16
|
+
IPV6: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,
|
|
17
|
+
IP: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,
|
|
18
|
+
CIDR: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:[0-9]|[12][0-9]|3[0-2])$/,
|
|
19
|
+
DOMAIN: /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,
|
|
20
|
+
HOSTNAME: /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/,
|
|
21
|
+
URL: /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,
|
|
22
|
+
EMAIL: /^[a-zA-Z0-9](?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]|\.(?!\.))*[a-zA-Z0-9]?@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/,
|
|
23
|
+
PHONE: /^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/,
|
|
24
|
+
JWT: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/,
|
|
25
|
+
BASE64: /^[A-Za-z0-9+\/]*={0,2}$/,
|
|
26
|
+
HEX: /^[0-9a-fA-F]+$/,
|
|
27
|
+
MD5: /^[a-f0-9]{32}$/i,
|
|
28
|
+
SHA1: /^[a-f0-9]{40}$/i,
|
|
29
|
+
SHA256: /^[a-f0-9]{64}$/i,
|
|
30
|
+
SEMVER: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,
|
|
31
|
+
FILENAME: /^[a-zA-Z0-9](?:[a-zA-Z0-9 ._-]*[a-zA-Z0-9])?\.[a-zA-Z0-9_-]+$/,
|
|
32
|
+
PATH: /^(\/[^/ ]*)+\/?$/,
|
|
33
|
+
API_KEY: /^[A-Za-z0-9_-]{32,}$/,
|
|
34
|
+
SECRET_KEY: /^[A-Za-z0-9_-]{64,}$/,
|
|
35
|
+
PIXEL_ID: /^px_[A-Za-z0-9]{16}$/
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* User Agent Patterns for Agent Detection
|
|
39
|
+
*/
|
|
40
|
+
const USER_AGENT_PATTERNS = {
|
|
41
|
+
OPENAI: /(?:GPTBot|ChatGPT-User|OpenAI)/i,
|
|
42
|
+
ANTHROPIC: /(?:Claude-Web|Claude-User|anthropic-ai|claude-web|claude-user|ClaudeBot)/i,
|
|
43
|
+
PERPLEXITY: /(?:PerplexityBot|Perplexica)/i,
|
|
44
|
+
GOOGLE_AI: /(?:Bard|Google-InspectionTool)/i,
|
|
45
|
+
MICROSOFT_AI: /(?:BingPreview\/.*ChatGPT|Copilot)/i,
|
|
46
|
+
GOOGLEBOT: /Googlebot/i,
|
|
47
|
+
BINGBOT: /(?:bingbot|BingPreview|msnbot)/i,
|
|
48
|
+
DUCKDUCKBOT: /DuckDuckBot/i,
|
|
49
|
+
BAIDUBOT: /Baiduspider/i,
|
|
50
|
+
YANDEXBOT: /YandexBot/i,
|
|
51
|
+
FACEBOOK: /(?:facebookexternalhit|facebookcatalog)/i,
|
|
52
|
+
TWITTER: /(?:Twitterbot|TwitterImageProxy)/i,
|
|
53
|
+
LINKEDIN: /LinkedInBot/i,
|
|
54
|
+
WHATSAPP: /WhatsApp/i,
|
|
55
|
+
TELEGRAM: /TelegramBot/i,
|
|
56
|
+
DISCORD: /Discordbot/i,
|
|
57
|
+
SLACK: /Slackbot/i,
|
|
58
|
+
GENERIC_BOT: /(?:bot|crawler|spider|scraper|agent)/i,
|
|
59
|
+
SCRAPY: /Scrapy/i,
|
|
60
|
+
PUPPETEER: /(?:HeadlessChrome|Puppeteer)/i,
|
|
61
|
+
PLAYWRIGHT: /Playwright/i,
|
|
62
|
+
SELENIUM: /(?:selenium|webdriver)/i,
|
|
63
|
+
POSTMAN: /PostmanRuntime/i,
|
|
64
|
+
INSOMNIA: /insomnia/i,
|
|
65
|
+
CURL: /curl/i,
|
|
66
|
+
WGET: /Wget/i,
|
|
67
|
+
HTTPIE: /HTTPie/i,
|
|
68
|
+
UPTIMEROBOT: /UptimeRobot/i,
|
|
69
|
+
PINGDOM: /Pingdom/i,
|
|
70
|
+
NEWRELIC: /NewRelicPinger/i,
|
|
71
|
+
DATADOG: /Datadog/i
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Header Patterns for Agent Detection
|
|
75
|
+
*/
|
|
76
|
+
const HEADER_PATTERNS = {
|
|
77
|
+
AI_HEADERS: /^(?:X-(?:OpenAI|Anthropic|AI|Bot|Agent|LLM))/i,
|
|
78
|
+
AUTOMATION_HEADERS: /^(?:X-(?:Automated|Robot|Crawler|Scraper))/i,
|
|
79
|
+
MISSING_ACCEPT: /^$/,
|
|
80
|
+
MISSING_ACCEPT_LANGUAGE: /^$/,
|
|
81
|
+
MISSING_ACCEPT_ENCODING: /^$/,
|
|
82
|
+
GENERIC_ACCEPT: /^\*\/\*$/,
|
|
83
|
+
NO_COOKIES: /^$/,
|
|
84
|
+
PROXY_HEADERS: /^(?:X-Forwarded-|X-Real-IP|X-Originating-IP|Via|Forwarded)/i,
|
|
85
|
+
CLOUD_HEADERS: /^(?:X-(?:AWS|Azure|GCP|Cloudflare))/i
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Browser Patterns
|
|
89
|
+
*/
|
|
90
|
+
const BROWSER_PATTERNS = {
|
|
91
|
+
CHROME: /Chrome\/([0-9.]+)/,
|
|
92
|
+
FIREFOX: /Firefox\/([0-9.]+)/,
|
|
93
|
+
SAFARI: /Version\/([0-9.]+).*Safari/,
|
|
94
|
+
EDGE: /Edg\/([0-9.]+)/,
|
|
95
|
+
OPERA: /OPR\/([0-9.]+)/,
|
|
96
|
+
IE: /MSIE ([0-9.]+)/
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Operating System Patterns
|
|
100
|
+
*/
|
|
101
|
+
const OS_PATTERNS = {
|
|
102
|
+
WINDOWS: /Windows NT ([0-9.]+)/,
|
|
103
|
+
MACOS: /Mac OS X ([0-9_]+)/,
|
|
104
|
+
LINUX: /Linux/,
|
|
105
|
+
ANDROID: /Android ([0-9.]+)/,
|
|
106
|
+
IOS: /OS ([0-9_]+) like Mac OS X/
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Mobile Device Patterns
|
|
110
|
+
*/
|
|
111
|
+
const MOBILE_PATTERNS = {
|
|
112
|
+
MOBILE: /(?:Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini)/i,
|
|
113
|
+
TABLET: /(?:iPad|Android.*Tablet|Tablet.*Android|Kindle|Silk)/i,
|
|
114
|
+
DESKTOP: /(?:Windows NT|Mac OS X|Linux|CrOS)/i
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Suspicious Behavior Patterns
|
|
118
|
+
*/
|
|
119
|
+
const SUSPICIOUS_PATTERNS = {
|
|
120
|
+
RAPID_REQUESTS: /^[0-9]{1,3}$/,
|
|
121
|
+
SEQUENTIAL_URLS: /\?(?:page|offset|id)=[0-9]+/,
|
|
122
|
+
API_ENDPOINTS: /\/api\/|\.json$|\.xml$/i,
|
|
123
|
+
DIRECT_POST: /^POST$/,
|
|
124
|
+
SQL_INJECTION: /(?:union|select|insert|update|delete|drop|create|alter|exec|script|javascript|onerror|onload|eval|src=)/i,
|
|
125
|
+
XSS_ATTEMPT: /(?:<script|javascript:|onerror=|onclick=|<iframe|<embed|<object)/i,
|
|
126
|
+
PATH_TRAVERSAL: /(?:\.\.\/|\.\.\\|%2e%2e%2f|%252e%252e%252f)/i,
|
|
127
|
+
URL_ENCODED: /%[0-9a-f]{2}/i,
|
|
128
|
+
BASE64_DATA: /data:[^;]+;base64,/i
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Maximum input length for pattern matching. UAs, header values, and
|
|
132
|
+
* detection payloads are bounded in practice (<4KB even for the most
|
|
133
|
+
* verbose Chrome/Firefox UAs). Caps worst-case complexity for any
|
|
134
|
+
* polynomial-shaped pattern an external caller might supply to
|
|
135
|
+
* `testPattern` / `extractMatch`; CodeQL flagged the unbounded path
|
|
136
|
+
* (js/polynomial-redos) on PR #2576.
|
|
137
|
+
*/
|
|
138
|
+
const MAX_PATTERN_INPUT_LENGTH = 4096;
|
|
139
|
+
/**
|
|
140
|
+
* Helper function to test a pattern. Returns `false` on inputs longer
|
|
141
|
+
* than {@link MAX_PATTERN_INPUT_LENGTH} — an abuse signal we'd rather
|
|
142
|
+
* reject than process.
|
|
143
|
+
*/
|
|
144
|
+
function testPattern(pattern, value) {
|
|
145
|
+
if (value.length > MAX_PATTERN_INPUT_LENGTH) return false;
|
|
146
|
+
return pattern.test(value);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Helper function to extract match from pattern. Returns `null` on
|
|
150
|
+
* over-long inputs (same ReDoS defense as `testPattern`).
|
|
151
|
+
*/
|
|
152
|
+
function extractMatch(pattern, value) {
|
|
153
|
+
if (value.length > MAX_PATTERN_INPUT_LENGTH) return null;
|
|
154
|
+
const match = value.match(pattern);
|
|
155
|
+
return match ? match[1] || match[0] : null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Helper function to test multiple patterns
|
|
159
|
+
*/
|
|
160
|
+
function testPatterns(patterns, value) {
|
|
161
|
+
return patterns.some((pattern) => testPattern(pattern, value));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Helper function to find matching pattern
|
|
165
|
+
*/
|
|
166
|
+
function findMatchingPattern(patterns, value) {
|
|
167
|
+
for (const [name, pattern] of Object.entries(patterns)) if (testPattern(pattern, value)) return name;
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
export { SUSPICIOUS_PATTERNS as a, VALIDATION_PATTERNS as c, testPattern as d, testPatterns as f, OS_PATTERNS as i, extractMatch as l, HEADER_PATTERNS as n, USER_AGENT_PATTERNS as o, MOBILE_PATTERNS as r, UUID_PATTERN as s, BROWSER_PATTERNS as t, findMatchingPattern as u };
|
|
173
|
+
//# sourceMappingURL=patterns-D4OAsNQY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns-D4OAsNQY.mjs","names":[],"sources":["../src/constants/patterns.ts"],"sourcesContent":["/**\n * Regular Expression Patterns\n *\n * Common regex patterns used for validation and detection\n */\n\n/**\n * Validation Patterns\n */\n// Hoisted out of the object literal below so bundle-size-critical leaves can\n// import JUST this one pattern. `VALIDATION_PATTERNS` re-exports it, so there\n// is still exactly one definition and no drift.\n//\n// Why it matters: rolldown (via tsdown) does not do property-level DCE on a\n// const object literal the way esbuild did. `browser-posture-cookie.ts` uses\n// only `.UUID`, but importing the whole object dragged every pattern —\n// ULID, SLUG, IPV4, IPV6 — into that leaf, taking it from 272 to 2,870 bytes.\nexport const UUID_PATTERN =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nexport const VALIDATION_PATTERNS = {\n // Identifiers\n UUID: UUID_PATTERN,\n ULID: /^[0-9A-HJKMNP-TV-Z]{26}$/,\n SLUG: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,\n\n // Network\n IPV4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,\n IPV6: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,\n IP: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,\n // eslint-disable-next-line no-useless-escape\n // CIDR pattern: uses IPV4 pattern and restricts mask to 0-32\n CIDR: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\/(?:[0-9]|[12][0-9]|3[0-2])$/,\n // eslint-disable-next-line no-useless-escape\n DOMAIN: /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,\n HOSTNAME:\n /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/,\n // eslint-disable-next-line no-useless-escape\n URL: /^https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,\n\n // Contact\n // Email pattern: stricter validation (rejects consecutive dots, requires TLD)\n // Local part: alphanumeric start/end, dots allowed but not consecutive\n EMAIL:\n /^[a-zA-Z0-9](?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]|\\.(?!\\.))*[a-zA-Z0-9]?@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/,\n PHONE: /^[+]?[(]?[0-9]{3}[)]?[-\\s.]?[0-9]{3}[-\\s.]?[0-9]{4,6}$/,\n\n // Security\n // JWT pattern: requires 3 parts (header.payload.signature) - signature cannot be empty\n JWT: /^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+$/,\n // eslint-disable-next-line no-useless-escape\n BASE64: /^[A-Za-z0-9+\\/]*={0,2}$/,\n HEX: /^[0-9a-fA-F]+$/,\n MD5: /^[a-f0-9]{32}$/i,\n SHA1: /^[a-f0-9]{40}$/i,\n SHA256: /^[a-f0-9]{64}$/i,\n\n // Versions\n SEMVER:\n /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/,\n\n // Files\n FILENAME: /^[a-zA-Z0-9](?:[a-zA-Z0-9 ._-]*[a-zA-Z0-9])?\\.[a-zA-Z0-9_-]+$/,\n PATH: /^(\\/[^/ ]*)+\\/?$/,\n\n // Keys\n API_KEY: /^[A-Za-z0-9_-]{32,}$/,\n SECRET_KEY: /^[A-Za-z0-9_-]{64,}$/,\n PIXEL_ID: /^px_[A-Za-z0-9]{16}$/,\n} as const;\n\n/**\n * User Agent Patterns for Agent Detection\n */\nexport const USER_AGENT_PATTERNS = {\n // AI Agents\n OPENAI: /(?:GPTBot|ChatGPT-User|OpenAI)/i,\n ANTHROPIC: /(?:Claude-Web|Claude-User|anthropic-ai|claude-web|claude-user|ClaudeBot)/i,\n PERPLEXITY: /(?:PerplexityBot|Perplexica)/i,\n GOOGLE_AI: /(?:Bard|Google-InspectionTool)/i,\n MICROSOFT_AI: /(?:BingPreview\\/.*ChatGPT|Copilot)/i,\n\n // Search Bots\n GOOGLEBOT: /Googlebot/i,\n BINGBOT: /(?:bingbot|BingPreview|msnbot)/i,\n DUCKDUCKBOT: /DuckDuckBot/i,\n BAIDUBOT: /Baiduspider/i,\n YANDEXBOT: /YandexBot/i,\n\n // Social Media Bots\n FACEBOOK: /(?:facebookexternalhit|facebookcatalog)/i,\n TWITTER: /(?:Twitterbot|TwitterImageProxy)/i,\n LINKEDIN: /LinkedInBot/i,\n WHATSAPP: /WhatsApp/i,\n TELEGRAM: /TelegramBot/i,\n DISCORD: /Discordbot/i,\n SLACK: /Slackbot/i,\n\n // Crawlers and Scrapers\n GENERIC_BOT: /(?:bot|crawler|spider|scraper|agent)/i,\n SCRAPY: /Scrapy/i,\n PUPPETEER: /(?:HeadlessChrome|Puppeteer)/i,\n PLAYWRIGHT: /Playwright/i,\n SELENIUM: /(?:selenium|webdriver)/i,\n\n // Development Tools\n POSTMAN: /PostmanRuntime/i,\n INSOMNIA: /insomnia/i,\n CURL: /curl/i,\n WGET: /Wget/i,\n HTTPIE: /HTTPie/i,\n\n // Monitoring Services\n UPTIMEROBOT: /UptimeRobot/i,\n PINGDOM: /Pingdom/i,\n NEWRELIC: /NewRelicPinger/i,\n DATADOG: /Datadog/i,\n} as const;\n\n/**\n * Header Patterns for Agent Detection\n */\nexport const HEADER_PATTERNS = {\n // AI-specific headers\n AI_HEADERS: /^(?:X-(?:OpenAI|Anthropic|AI|Bot|Agent|LLM))/i,\n\n // Automation headers\n AUTOMATION_HEADERS: /^(?:X-(?:Automated|Robot|Crawler|Scraper))/i,\n\n // Missing standard headers\n MISSING_ACCEPT: /^$/,\n MISSING_ACCEPT_LANGUAGE: /^$/,\n MISSING_ACCEPT_ENCODING: /^$/,\n\n // Suspicious patterns\n GENERIC_ACCEPT: /^\\*\\/\\*$/,\n NO_COOKIES: /^$/,\n\n // Known proxy headers\n PROXY_HEADERS: /^(?:X-Forwarded-|X-Real-IP|X-Originating-IP|Via|Forwarded)/i,\n\n // Cloud provider headers\n CLOUD_HEADERS: /^(?:X-(?:AWS|Azure|GCP|Cloudflare))/i,\n} as const;\n\n/**\n * Browser Patterns\n */\nexport const BROWSER_PATTERNS = {\n CHROME: /Chrome\\/([0-9.]+)/,\n FIREFOX: /Firefox\\/([0-9.]+)/,\n SAFARI: /Version\\/([0-9.]+).*Safari/,\n EDGE: /Edg\\/([0-9.]+)/,\n OPERA: /OPR\\/([0-9.]+)/,\n IE: /MSIE ([0-9.]+)/,\n} as const;\n\n/**\n * Operating System Patterns\n */\nexport const OS_PATTERNS = {\n WINDOWS: /Windows NT ([0-9.]+)/,\n MACOS: /Mac OS X ([0-9_]+)/,\n LINUX: /Linux/,\n ANDROID: /Android ([0-9.]+)/,\n IOS: /OS ([0-9_]+) like Mac OS X/,\n} as const;\n\n/**\n * Mobile Device Patterns\n */\nexport const MOBILE_PATTERNS = {\n MOBILE: /(?:Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini)/i,\n TABLET: /(?:iPad|Android.*Tablet|Tablet.*Android|Kindle|Silk)/i,\n DESKTOP: /(?:Windows NT|Mac OS X|Linux|CrOS)/i,\n} as const;\n\n/**\n * Suspicious Behavior Patterns\n */\nexport const SUSPICIOUS_PATTERNS = {\n // Rapid requests\n RAPID_REQUESTS: /^[0-9]{1,3}$/,\n\n // Sequential access\n SEQUENTIAL_URLS: /\\?(?:page|offset|id)=[0-9]+/,\n\n // Data extraction\n API_ENDPOINTS: /\\/api\\/|\\.json$|\\.xml$/i,\n\n // Form submission without interaction\n DIRECT_POST: /^POST$/,\n\n // Known attack patterns\n SQL_INJECTION:\n /(?:union|select|insert|update|delete|drop|create|alter|exec|script|javascript|onerror|onload|eval|src=)/i,\n XSS_ATTEMPT: /(?:<script|javascript:|onerror=|onclick=|<iframe|<embed|<object)/i,\n PATH_TRAVERSAL: /(?:\\.\\.\\/|\\.\\.\\\\|%2e%2e%2f|%252e%252e%252f)/i,\n\n // Encoding attempts\n URL_ENCODED: /%[0-9a-f]{2}/i,\n BASE64_DATA: /data:[^;]+;base64,/i,\n} as const;\n\n/**\n * Maximum input length for pattern matching. UAs, header values, and\n * detection payloads are bounded in practice (<4KB even for the most\n * verbose Chrome/Firefox UAs). Caps worst-case complexity for any\n * polynomial-shaped pattern an external caller might supply to\n * `testPattern` / `extractMatch`; CodeQL flagged the unbounded path\n * (js/polynomial-redos) on PR #2576.\n */\nconst MAX_PATTERN_INPUT_LENGTH = 4096;\n\n/**\n * Helper function to test a pattern. Returns `false` on inputs longer\n * than {@link MAX_PATTERN_INPUT_LENGTH} — an abuse signal we'd rather\n * reject than process.\n */\nexport function testPattern(pattern: RegExp, value: string): boolean {\n if (value.length > MAX_PATTERN_INPUT_LENGTH) return false;\n return pattern.test(value);\n}\n\n/**\n * Helper function to extract match from pattern. Returns `null` on\n * over-long inputs (same ReDoS defense as `testPattern`).\n */\nexport function extractMatch(pattern: RegExp, value: string): string | null {\n if (value.length > MAX_PATTERN_INPUT_LENGTH) return null;\n const match = value.match(pattern);\n return match ? match[1] || match[0] : null;\n}\n\n/**\n * Helper function to test multiple patterns\n */\nexport function testPatterns(patterns: RegExp[], value: string): boolean {\n return patterns.some((pattern) => testPattern(pattern, value));\n}\n\n/**\n * Helper function to find matching pattern\n */\nexport function findMatchingPattern(\n patterns: Record<string, RegExp>,\n value: string\n): string | null {\n for (const [name, pattern] of Object.entries(patterns)) {\n if (testPattern(pattern, value)) {\n return name;\n }\n }\n return null;\n}\n"],"mappings":";;;;;;;;;AAiBA,MAAa,eACX;AAEF,MAAa,sBAAsB;CAEjC,MAAM;CACN,MAAM;CACN,MAAM;CAGN,MAAM;CACN,MAAM;CACN,IAAI;CAGJ,MAAM;CAEN,QAAQ;CACR,UACE;CAEF,KAAK;CAKL,OACE;CACF,OAAO;CAIP,KAAK;CAEL,QAAQ;CACR,KAAK;CACL,KAAK;CACL,MAAM;CACN,QAAQ;CAGR,QACE;CAGF,UAAU;CACV,MAAM;CAGN,SAAS;CACT,YAAY;CACZ,UAAU;AACZ;;;;AAKA,MAAa,sBAAsB;CAEjC,QAAQ;CACR,WAAW;CACX,YAAY;CACZ,WAAW;CACX,cAAc;CAGd,WAAW;CACX,SAAS;CACT,aAAa;CACb,UAAU;CACV,WAAW;CAGX,UAAU;CACV,SAAS;CACT,UAAU;CACV,UAAU;CACV,UAAU;CACV,SAAS;CACT,OAAO;CAGP,aAAa;CACb,QAAQ;CACR,WAAW;CACX,YAAY;CACZ,UAAU;CAGV,SAAS;CACT,UAAU;CACV,MAAM;CACN,MAAM;CACN,QAAQ;CAGR,aAAa;CACb,SAAS;CACT,UAAU;CACV,SAAS;AACX;;;;AAKA,MAAa,kBAAkB;CAE7B,YAAY;CAGZ,oBAAoB;CAGpB,gBAAgB;CAChB,yBAAyB;CACzB,yBAAyB;CAGzB,gBAAgB;CAChB,YAAY;CAGZ,eAAe;CAGf,eAAe;AACjB;;;;AAKA,MAAa,mBAAmB;CAC9B,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,MAAM;CACN,OAAO;CACP,IAAI;AACN;;;;AAKA,MAAa,cAAc;CACzB,SAAS;CACT,OAAO;CACP,OAAO;CACP,SAAS;CACT,KAAK;AACP;;;;AAKA,MAAa,kBAAkB;CAC7B,QAAQ;CACR,QAAQ;CACR,SAAS;AACX;;;;AAKA,MAAa,sBAAsB;CAEjC,gBAAgB;CAGhB,iBAAiB;CAGjB,eAAe;CAGf,aAAa;CAGb,eACE;CACF,aAAa;CACb,gBAAgB;CAGhB,aAAa;CACb,aAAa;AACf;;;;;;;;;AAUA,MAAM,2BAA2B;;;;;;AAOjC,SAAgB,YAAY,SAAiB,OAAwB;CACnE,IAAI,MAAM,SAAS,0BAA0B,OAAO;CACpD,OAAO,QAAQ,KAAK,KAAK;AAC3B;;;;;AAMA,SAAgB,aAAa,SAAiB,OAA8B;CAC1E,IAAI,MAAM,SAAS,0BAA0B,OAAO;CACpD,MAAM,QAAQ,MAAM,MAAM,OAAO;CACjC,OAAO,QAAQ,MAAM,MAAM,MAAM,KAAK;AACxC;;;;AAKA,SAAgB,aAAa,UAAoB,OAAwB;CACvE,OAAO,SAAS,MAAM,YAAY,YAAY,SAAS,KAAK,CAAC;AAC/D;;;;AAKA,SAAgB,oBACd,UACA,OACe;CACf,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,QAAQ,GACnD,IAAI,YAAY,SAAS,KAAK,GAC5B,OAAO;CAGX,OAAO;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SUSPICIOUS_PATTERNS, c as VALIDATION_PATTERNS, d as testPattern, f as testPatterns, i as OS_PATTERNS, l as extractMatch, n as HEADER_PATTERNS, o as USER_AGENT_PATTERNS, r as MOBILE_PATTERNS, s as UUID_PATTERN, t as BROWSER_PATTERNS, u as findMatchingPattern } from "./patterns-Bp40cwh2.mjs";
|
|
2
|
+
export { BROWSER_PATTERNS, HEADER_PATTERNS, MOBILE_PATTERNS, OS_PATTERNS, SUSPICIOUS_PATTERNS, USER_AGENT_PATTERNS, UUID_PATTERN, VALIDATION_PATTERNS, extractMatch, findMatchingPattern, testPattern, testPatterns };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SUSPICIOUS_PATTERNS, c as VALIDATION_PATTERNS, d as testPattern, f as testPatterns, i as OS_PATTERNS, l as extractMatch, n as HEADER_PATTERNS, o as USER_AGENT_PATTERNS, r as MOBILE_PATTERNS, s as UUID_PATTERN, t as BROWSER_PATTERNS, u as findMatchingPattern } from "./patterns-Bp40cwh2.js";
|
|
2
|
+
export { BROWSER_PATTERNS, HEADER_PATTERNS, MOBILE_PATTERNS, OS_PATTERNS, SUSPICIOUS_PATTERNS, USER_AGENT_PATTERNS, UUID_PATTERN, VALIDATION_PATTERNS, extractMatch, findMatchingPattern, testPattern, testPatterns };
|
package/dist/patterns.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_patterns = require('./patterns-CiMpbdAF.js');
|
|
3
|
+
|
|
4
|
+
exports.BROWSER_PATTERNS = require_patterns.BROWSER_PATTERNS;
|
|
5
|
+
exports.HEADER_PATTERNS = require_patterns.HEADER_PATTERNS;
|
|
6
|
+
exports.MOBILE_PATTERNS = require_patterns.MOBILE_PATTERNS;
|
|
7
|
+
exports.OS_PATTERNS = require_patterns.OS_PATTERNS;
|
|
8
|
+
exports.SUSPICIOUS_PATTERNS = require_patterns.SUSPICIOUS_PATTERNS;
|
|
9
|
+
exports.USER_AGENT_PATTERNS = require_patterns.USER_AGENT_PATTERNS;
|
|
10
|
+
exports.UUID_PATTERN = require_patterns.UUID_PATTERN;
|
|
11
|
+
exports.VALIDATION_PATTERNS = require_patterns.VALIDATION_PATTERNS;
|
|
12
|
+
exports.extractMatch = require_patterns.extractMatch;
|
|
13
|
+
exports.findMatchingPattern = require_patterns.findMatchingPattern;
|
|
14
|
+
exports.testPattern = require_patterns.testPattern;
|
|
15
|
+
exports.testPatterns = require_patterns.testPatterns;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as SUSPICIOUS_PATTERNS, c as VALIDATION_PATTERNS, d as testPattern, f as testPatterns, i as OS_PATTERNS, l as extractMatch, n as HEADER_PATTERNS, o as USER_AGENT_PATTERNS, r as MOBILE_PATTERNS, s as UUID_PATTERN, t as BROWSER_PATTERNS, u as findMatchingPattern } from "./patterns-D4OAsNQY.mjs";
|
|
2
|
+
|
|
3
|
+
export { BROWSER_PATTERNS, HEADER_PATTERNS, MOBILE_PATTERNS, OS_PATTERNS, SUSPICIOUS_PATTERNS, USER_AGENT_PATTERNS, UUID_PATTERN, VALIDATION_PATTERNS, extractMatch, findMatchingPattern, testPattern, testPatterns };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-DiOclGqf.mjs";
|
|
2
|
+
import { A as NO_EVIDENCE_EQUALITY_TERM, F as FAIL_CLOSED_HEADERS, I as FAIL_CLOSED_STATUS, M as withNoEvidenceExclusion, N as matchPath, P as FAIL_CLOSED_BODY, _ as requiredScopesForRequest, a as ApprovalQuorum, b as analyzePolicySource, c as BESPOKE_POLICY_IDS, g as ByteBoundedMemo, h as decisionPolicyId, i as validateStepUpQuorum, j as NO_EVIDENCE_EXCLUSION_TERM, k as NO_EVIDENCE_CATEGORY, l as BespokePolicyId, m as DecisionLike, n as StepUpQuorumCheck, o as approvalQuorumForRequest, r as StepUpQuorumLike, t as InvalidStepUpReason, v as PolicyHazardAnalysis, y as RequestFacts } from "../step-up-Bz12gYKT.mjs";
|
|
3
|
+
export { type ApprovalQuorum, BESPOKE_POLICY_IDS, type BespokePolicyId, ByteBoundedMemo, type DecisionLike, FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS, type InvalidStepUpReason, NO_EVIDENCE_CATEGORY, NO_EVIDENCE_EQUALITY_TERM, NO_EVIDENCE_EXCLUSION_TERM, type PolicyHazardAnalysis, type RequestFacts, type StepUpQuorumCheck, type StepUpQuorumLike, analyzePolicySource, approvalQuorumForRequest, decisionPolicyId, isEngineEnforcing, matchPath, normalizeChallengeType, requiredScopesForRequest, validateStepUpQuorum, withNoEvidenceExclusion };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-DiOclGqf.js";
|
|
2
|
+
import { A as NO_EVIDENCE_EQUALITY_TERM, F as FAIL_CLOSED_HEADERS, I as FAIL_CLOSED_STATUS, M as withNoEvidenceExclusion, N as matchPath, P as FAIL_CLOSED_BODY, _ as requiredScopesForRequest, a as ApprovalQuorum, b as analyzePolicySource, c as BESPOKE_POLICY_IDS, g as ByteBoundedMemo, h as decisionPolicyId, i as validateStepUpQuorum, j as NO_EVIDENCE_EXCLUSION_TERM, k as NO_EVIDENCE_CATEGORY, l as BespokePolicyId, m as DecisionLike, n as StepUpQuorumCheck, o as approvalQuorumForRequest, r as StepUpQuorumLike, t as InvalidStepUpReason, v as PolicyHazardAnalysis, y as RequestFacts } from "../step-up-Bz12gYKT.js";
|
|
3
|
+
export { type ApprovalQuorum, BESPOKE_POLICY_IDS, type BespokePolicyId, ByteBoundedMemo, type DecisionLike, FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS, type InvalidStepUpReason, NO_EVIDENCE_CATEGORY, NO_EVIDENCE_EQUALITY_TERM, NO_EVIDENCE_EXCLUSION_TERM, type PolicyHazardAnalysis, type RequestFacts, type StepUpQuorumCheck, type StepUpQuorumLike, analyzePolicySource, approvalQuorumForRequest, decisionPolicyId, isEngineEnforcing, matchPath, normalizeChallengeType, requiredScopesForRequest, validateStepUpQuorum, withNoEvidenceExclusion };
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_engine_enforcing = require('../engine-enforcing-AYEcgNsb.js');
|
|
3
|
+
const require_step_up = require('../step-up-Bp8RAQwv.js');
|
|
3
4
|
|
|
5
|
+
exports.BESPOKE_POLICY_IDS = require_step_up.BESPOKE_POLICY_IDS;
|
|
6
|
+
exports.ByteBoundedMemo = require_step_up.ByteBoundedMemo;
|
|
4
7
|
exports.FAIL_CLOSED_BODY = require_step_up.FAIL_CLOSED_BODY;
|
|
5
8
|
exports.FAIL_CLOSED_HEADERS = require_step_up.FAIL_CLOSED_HEADERS;
|
|
6
9
|
exports.FAIL_CLOSED_STATUS = require_step_up.FAIL_CLOSED_STATUS;
|
|
7
10
|
exports.NO_EVIDENCE_CATEGORY = require_step_up.NO_EVIDENCE_CATEGORY;
|
|
8
11
|
exports.NO_EVIDENCE_EQUALITY_TERM = require_step_up.NO_EVIDENCE_EQUALITY_TERM;
|
|
9
12
|
exports.NO_EVIDENCE_EXCLUSION_TERM = require_step_up.NO_EVIDENCE_EXCLUSION_TERM;
|
|
13
|
+
exports.analyzePolicySource = require_step_up.analyzePolicySource;
|
|
10
14
|
exports.approvalQuorumForRequest = require_step_up.approvalQuorumForRequest;
|
|
11
15
|
exports.decisionPolicyId = require_step_up.decisionPolicyId;
|
|
12
|
-
exports.isEngineEnforcing =
|
|
16
|
+
exports.isEngineEnforcing = require_engine_enforcing.isEngineEnforcing;
|
|
17
|
+
exports.matchPath = require_step_up.matchPath;
|
|
18
|
+
exports.normalizeChallengeType = require_engine_enforcing.normalizeChallengeType;
|
|
13
19
|
exports.requiredScopesForRequest = require_step_up.requiredScopesForRequest;
|
|
14
20
|
exports.validateStepUpQuorum = require_step_up.validateStepUpQuorum;
|
|
15
21
|
exports.withNoEvidenceExclusion = require_step_up.withNoEvidenceExclusion;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as normalizeChallengeType, t as isEngineEnforcing } from "../engine-enforcing-B5eNfCpG.mjs";
|
|
2
|
+
import { A as matchPath, C as NO_EVIDENCE_CATEGORY, E as withNoEvidenceExclusion, M as FAIL_CLOSED_HEADERS, N as FAIL_CLOSED_STATUS, T as NO_EVIDENCE_EXCLUSION_TERM, d as ByteBoundedMemo, f as analyzePolicySource, i as BESPOKE_POLICY_IDS, j as FAIL_CLOSED_BODY, l as decisionPolicyId, n as approvalQuorumForRequest, t as validateStepUpQuorum, u as requiredScopesForRequest, w as NO_EVIDENCE_EQUALITY_TERM } from "../step-up-BK0oBi11.mjs";
|
|
2
3
|
|
|
3
|
-
export { FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS, NO_EVIDENCE_CATEGORY, NO_EVIDENCE_EQUALITY_TERM, NO_EVIDENCE_EXCLUSION_TERM, approvalQuorumForRequest, decisionPolicyId, isEngineEnforcing, requiredScopesForRequest, validateStepUpQuorum, withNoEvidenceExclusion };
|
|
4
|
+
export { BESPOKE_POLICY_IDS, ByteBoundedMemo, FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS, NO_EVIDENCE_CATEGORY, NO_EVIDENCE_EQUALITY_TERM, NO_EVIDENCE_EXCLUSION_TERM, analyzePolicySource, approvalQuorumForRequest, decisionPolicyId, isEngineEnforcing, matchPath, normalizeChallengeType, requiredScopesForRequest, validateStepUpQuorum, withNoEvidenceExclusion };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PolicyUnavailableError, i as PolicyFetcherConfig, n as PolicyCacheAdapter, o as isPolicyUnavailableError, r as PolicyFetcher, t as CachedPolicy } from "../fetcher-D2vjr7jB.mjs";
|
|
2
|
+
export { CachedPolicy, PolicyCacheAdapter, PolicyFetcher, PolicyFetcherConfig, PolicyUnavailableError, isPolicyUnavailableError };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PolicyUnavailableError, i as PolicyFetcherConfig, n as PolicyCacheAdapter, o as isPolicyUnavailableError, r as PolicyFetcher, t as CachedPolicy } from "../fetcher-C8qvwdnA.js";
|
|
2
|
+
export { CachedPolicy, PolicyCacheAdapter, PolicyFetcher, PolicyFetcherConfig, PolicyUnavailableError, isPolicyUnavailableError };
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_schemas = require('../schemas-Cm4C4Z5G.js');
|
|
3
|
+
|
|
4
|
+
//#region src/policy/fetcher.ts
|
|
5
|
+
/**
|
|
6
|
+
* Policy Fetcher
|
|
7
|
+
*
|
|
8
|
+
* Runtime-agnostic policy fetching with caching support.
|
|
9
|
+
* Works in Edge (Cloudflare Workers, Next.js Edge), Node.js, and browser environments.
|
|
10
|
+
*
|
|
11
|
+
* The fetcher supports:
|
|
12
|
+
* - In-memory caching with TTL
|
|
13
|
+
* - Origin reads for legacy adapters that cannot coordinate shared invalidation
|
|
14
|
+
* - Fallback to default policy on errors
|
|
15
|
+
* - Configurable API endpoints
|
|
16
|
+
*/
|
|
17
|
+
function looksLikePolicyApiBody(data) {
|
|
18
|
+
if (typeof data !== "object" || data === null) return false;
|
|
19
|
+
const threshold = data.blockThreshold;
|
|
20
|
+
return typeof threshold === "number" && Number.isFinite(threshold);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The policy API serves the allow list as agent names (the `string[]` the
|
|
24
|
+
* gateway Worker reads), while the policy schema models each entry as an
|
|
25
|
+
* object. Read a name as `{ clientName }` before validating; anything else is
|
|
26
|
+
* left for the schema to judge.
|
|
27
|
+
*/
|
|
28
|
+
function fromPolicyApiBody(data) {
|
|
29
|
+
const { allowList } = data;
|
|
30
|
+
if (!Array.isArray(allowList)) return data;
|
|
31
|
+
return {
|
|
32
|
+
...data,
|
|
33
|
+
allowList: allowList.map((entry) => typeof entry === "string" ? { clientName: entry } : entry)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var PolicyUnavailableError = class extends Error {
|
|
37
|
+
code = "POLICY_UNAVAILABLE";
|
|
38
|
+
constructor() {
|
|
39
|
+
super("Current policy could not be loaded within the permitted bound");
|
|
40
|
+
this.name = "PolicyUnavailableError";
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/** Recognize the same failure across independently loaded SDK package copies. */
|
|
44
|
+
function isPolicyUnavailableError(error) {
|
|
45
|
+
return error instanceof Error && error.name === "PolicyUnavailableError" && "code" in error && error.code === "POLICY_UNAVAILABLE";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Simple in-memory cache with TTL support
|
|
49
|
+
*/
|
|
50
|
+
var MemoryCache = class {
|
|
51
|
+
cache = /* @__PURE__ */ new Map();
|
|
52
|
+
get(key) {
|
|
53
|
+
const entry = this.cache.get(key);
|
|
54
|
+
if (!entry) return null;
|
|
55
|
+
if (Date.now() > entry.expiresAt) {
|
|
56
|
+
this.cache.delete(key);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return entry.value;
|
|
60
|
+
}
|
|
61
|
+
set(key, value, ttlSeconds) {
|
|
62
|
+
this.cache.set(key, {
|
|
63
|
+
value,
|
|
64
|
+
expiresAt: Date.now() + ttlSeconds * 1e3
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
delete(key) {
|
|
68
|
+
return this.cache.delete(key);
|
|
69
|
+
}
|
|
70
|
+
clear() {
|
|
71
|
+
this.cache.clear();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const globalMemoryCache = new MemoryCache();
|
|
75
|
+
const globalPolicyCacheKeys = /* @__PURE__ */ new Map();
|
|
76
|
+
const fallbackCachePrefix = `${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}:${Math.random().toString(36).slice(2)}`;
|
|
77
|
+
let fallbackCacheSequence = 0;
|
|
78
|
+
function nextCacheRevision() {
|
|
79
|
+
return globalThis.crypto?.randomUUID?.() ?? `${fallbackCachePrefix}:${++fallbackCacheSequence}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Policy fetcher with caching and fallback support
|
|
83
|
+
*/
|
|
84
|
+
var PolicyFetcher = class {
|
|
85
|
+
config;
|
|
86
|
+
memoryCache;
|
|
87
|
+
constructor(config) {
|
|
88
|
+
this.config = {
|
|
89
|
+
apiBaseUrl: config.apiBaseUrl,
|
|
90
|
+
apiKey: config.apiKey,
|
|
91
|
+
cacheTtlSeconds: config.cacheTtlSeconds ?? require_schemas.CACHE_TTL.POLICY,
|
|
92
|
+
cacheAdapter: config.cacheAdapter,
|
|
93
|
+
disableMemoryCache: config.disableMemoryCache ?? false,
|
|
94
|
+
timeoutMs: config.timeoutMs ?? 5e3,
|
|
95
|
+
throwOnUnavailable: config.throwOnUnavailable ?? false,
|
|
96
|
+
fetchFn: config.fetchFn ?? globalThis.fetch
|
|
97
|
+
};
|
|
98
|
+
this.memoryCache = config.disableMemoryCache ? new MemoryCache() : globalMemoryCache;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate a cache key that includes the API base URL and TTL to prevent
|
|
102
|
+
* cache collisions when multiple fetchers use different backends or TTL settings.
|
|
103
|
+
*/
|
|
104
|
+
getBaseCacheKey(projectId) {
|
|
105
|
+
return `policy:${this.config.apiBaseUrl.split("").reduce((hash, char) => (hash << 5) - hash + char.charCodeAt(0) | 0, 0).toString(36)}:${this.config.cacheTtlSeconds}:${projectId}`;
|
|
106
|
+
}
|
|
107
|
+
getCacheKey(projectId) {
|
|
108
|
+
const baseKey = this.getBaseCacheKey(projectId);
|
|
109
|
+
return globalPolicyCacheKeys.get(baseKey) ?? baseKey;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get policy for a project, with caching
|
|
113
|
+
*/
|
|
114
|
+
async getPolicy(projectId) {
|
|
115
|
+
const deadline = Date.now() + this.config.timeoutMs;
|
|
116
|
+
if (!Number.isFinite(deadline) || this.config.timeoutMs <= 0) throw new PolicyUnavailableError();
|
|
117
|
+
const controller = new AbortController();
|
|
118
|
+
const requireActiveLoad = () => {
|
|
119
|
+
if (controller.signal.aborted || Date.now() >= deadline) throw new PolicyUnavailableError();
|
|
120
|
+
};
|
|
121
|
+
let timer;
|
|
122
|
+
const expired = new Promise((_resolve, reject) => {
|
|
123
|
+
timer = setTimeout(() => {
|
|
124
|
+
const failure = new PolicyUnavailableError();
|
|
125
|
+
controller.abort(failure);
|
|
126
|
+
reject(failure);
|
|
127
|
+
}, this.config.timeoutMs);
|
|
128
|
+
});
|
|
129
|
+
const useMemoryCache = !this.config.disableMemoryCache && !this.config.cacheAdapter;
|
|
130
|
+
try {
|
|
131
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
132
|
+
requireActiveLoad();
|
|
133
|
+
const cacheKey = this.getCacheKey(projectId);
|
|
134
|
+
if (useMemoryCache) {
|
|
135
|
+
const memoryCached = this.memoryCache.get(cacheKey);
|
|
136
|
+
if (memoryCached) {
|
|
137
|
+
const cached = JSON.parse(memoryCached);
|
|
138
|
+
requireActiveLoad();
|
|
139
|
+
if (!this.isExpired(cached.expiresAt)) return cached.policy;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const policy = await Promise.race([this.fetchPolicyFromApi(projectId, controller.signal), expired]);
|
|
144
|
+
requireActiveLoad();
|
|
145
|
+
if (cacheKey !== this.getCacheKey(projectId)) continue;
|
|
146
|
+
if (useMemoryCache) {
|
|
147
|
+
const now = /* @__PURE__ */ new Date();
|
|
148
|
+
const cached = {
|
|
149
|
+
policy,
|
|
150
|
+
projectId,
|
|
151
|
+
cachedAt: now.toISOString(),
|
|
152
|
+
expiresAt: new Date(now.getTime() + this.config.cacheTtlSeconds * 1e3).toISOString()
|
|
153
|
+
};
|
|
154
|
+
const cacheValue = JSON.stringify(cached);
|
|
155
|
+
requireActiveLoad();
|
|
156
|
+
this.memoryCache.set(cacheKey, cacheValue, this.config.cacheTtlSeconds);
|
|
157
|
+
}
|
|
158
|
+
requireActiveLoad();
|
|
159
|
+
return policy;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
requireActiveLoad();
|
|
162
|
+
if (isPolicyUnavailableError(error)) throw error;
|
|
163
|
+
if (cacheKey !== this.getCacheKey(projectId)) continue;
|
|
164
|
+
console.error(`[PolicyFetcher] Failed to fetch policy for ${projectId}:`, error);
|
|
165
|
+
if (this.config.throwOnUnavailable) throw new PolicyUnavailableError();
|
|
166
|
+
return this.getDefaultPolicy();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
throw new PolicyUnavailableError();
|
|
170
|
+
} finally {
|
|
171
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Fetch policy from the API
|
|
176
|
+
*/
|
|
177
|
+
async fetchPolicyFromApi(projectId, signal) {
|
|
178
|
+
const url = `${this.config.apiBaseUrl}/api/internal/policies/${projectId}`;
|
|
179
|
+
const headers = {
|
|
180
|
+
"Content-Type": "application/json",
|
|
181
|
+
"User-Agent": "AgentShield-PolicyFetcher/1.0"
|
|
182
|
+
};
|
|
183
|
+
if (this.config.apiKey) headers["Authorization"] = `Bearer ${this.config.apiKey}`;
|
|
184
|
+
const response = await this.config.fetchFn(url, {
|
|
185
|
+
method: "GET",
|
|
186
|
+
headers,
|
|
187
|
+
signal,
|
|
188
|
+
cache: "no-store"
|
|
189
|
+
});
|
|
190
|
+
if (!response.ok) throw new Error(`API returned ${response.status}: ${response.statusText}`);
|
|
191
|
+
const data = await response.json();
|
|
192
|
+
if (!looksLikePolicyApiBody(data)) throw new Error("Policy response is not from the policy API");
|
|
193
|
+
const policy = require_schemas.safeParsePolicyConfig(fromPolicyApiBody(data));
|
|
194
|
+
if (!policy) throw new Error("Invalid policy response format");
|
|
195
|
+
return policy;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get the default policy
|
|
199
|
+
*/
|
|
200
|
+
getDefaultPolicy() {
|
|
201
|
+
return require_schemas.PolicyConfigSchema.parse(require_schemas.DEFAULT_POLICY);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Retire this runtime's cached policy key before any asynchronous cleanup.
|
|
205
|
+
* Older reads and writes cannot restore the retired entry for these fetchers.
|
|
206
|
+
*/
|
|
207
|
+
async invalidateCache(projectId) {
|
|
208
|
+
const cacheKey = this.getCacheKey(projectId);
|
|
209
|
+
const baseKey = this.getBaseCacheKey(projectId);
|
|
210
|
+
globalPolicyCacheKeys.set(baseKey, `${baseKey}:${nextCacheRevision()}`);
|
|
211
|
+
globalMemoryCache.delete(cacheKey);
|
|
212
|
+
if (this.config.cacheAdapter?.delete) {
|
|
213
|
+
const keys = cacheKey === baseKey ? [baseKey] : [cacheKey, baseKey];
|
|
214
|
+
await Promise.all(keys.map(async (key) => {
|
|
215
|
+
try {
|
|
216
|
+
await this.config.cacheAdapter.delete(key);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error("[PolicyFetcher] Failed to delete from external cache:", error);
|
|
219
|
+
}
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Clear all cached policies
|
|
225
|
+
*/
|
|
226
|
+
clearCache() {
|
|
227
|
+
if (!this.config.disableMemoryCache) this.memoryCache.clear();
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check if a date string is expired
|
|
231
|
+
*/
|
|
232
|
+
isExpired(dateString) {
|
|
233
|
+
return new Date(dateString).getTime() < Date.now();
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
exports.PolicyFetcher = PolicyFetcher;
|
|
239
|
+
exports.PolicyUnavailableError = PolicyUnavailableError;
|
|
240
|
+
exports.isPolicyUnavailableError = isPolicyUnavailableError;
|