@kya-os/checkpoint-shared 1.5.1 → 1.6.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 +217 -0
- package/dist/beacon-nonce/index.d.mts +36 -0
- package/dist/beacon-nonce/index.d.mts.map +1 -0
- package/dist/beacon-nonce/index.d.ts +36 -0
- package/dist/beacon-nonce/index.d.ts.map +1 -0
- package/dist/beacon-nonce/index.js +305 -0
- package/dist/beacon-nonce/index.mjs +294 -0
- package/dist/beacon-nonce/index.mjs.map +1 -0
- package/dist/beacon-types/index.d.mts +40 -0
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +40 -0
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +53 -5
- package/dist/beacon-types/index.mjs +49 -6
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/browser-posture-BuChqmH5.d.mts +169 -0
- package/dist/browser-posture-BuChqmH5.d.mts.map +1 -0
- package/dist/browser-posture-DIaVLuW3.d.ts +169 -0
- package/dist/browser-posture-DIaVLuW3.d.ts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +4 -2
- package/dist/browser-posture-cookie.d.mts.map +1 -0
- package/dist/browser-posture-cookie.d.ts +4 -2
- package/dist/browser-posture-cookie.d.ts.map +1 -0
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof.d.mts +18 -0
- package/dist/browser-posture-proof.d.mts.map +1 -0
- package/dist/browser-posture-proof.d.ts +18 -0
- package/dist/browser-posture-proof.d.ts.map +1 -0
- package/dist/browser-posture-proof.js +66 -0
- package/dist/browser-posture-proof.mjs +63 -0
- package/dist/browser-posture-proof.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +59 -2
- package/dist/browser-posture-report.d.mts.map +1 -1
- package/dist/browser-posture-report.d.ts +59 -2
- package/dist/browser-posture-report.d.ts.map +1 -1
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +1 -1
- package/dist/browser-posture-report.mjs.map +1 -1
- package/dist/browser-posture.d.mts +2 -85
- package/dist/browser-posture.d.ts +2 -85
- package/dist/browser-posture.js +207 -45
- package/dist/browser-posture.mjs +195 -45
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +0 -8
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +0 -8
- 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/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-HOfe6ucV.mjs → client-ip-B2Xeo-GK.mjs} +2 -2
- package/dist/{client-ip-HOfe6ucV.mjs.map → client-ip-B2Xeo-GK.mjs.map} +1 -1
- package/dist/{client-ip-1y2iXAYW.js → client-ip-CW6pRyLf.js} +1 -1
- package/dist/consent-handoff.d.mts +41 -0
- package/dist/consent-handoff.d.mts.map +1 -0
- package/dist/consent-handoff.d.ts +41 -0
- package/dist/consent-handoff.d.ts.map +1 -0
- package/dist/consent-handoff.js +1 -0
- package/dist/consent-handoff.mjs +2 -0
- package/dist/consent-handoff.mjs.map +1 -0
- package/dist/errors/index.d.mts +155 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +155 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +513 -9
- package/dist/errors/index.mjs +513 -10
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{external-jr_S4iSS.d.ts → external-B7WI9FyQ.d.mts} +2 -2
- package/dist/{external-jr_S4iSS.d.mts.map → external-B7WI9FyQ.d.mts.map} +1 -1
- package/dist/{external-jr_S4iSS.d.mts → external-B7WI9FyQ.d.ts} +2 -2
- package/dist/{external-jr_S4iSS.d.ts.map → external-B7WI9FyQ.d.ts.map} +1 -1
- package/dist/gateway-client-ip.d.mts +1 -1
- package/dist/gateway-client-ip.d.ts +1 -1
- package/dist/gateway-client-ip.js +2 -2
- package/dist/gateway-client-ip.mjs +2 -2
- package/dist/index.d.mts +6375 -1532
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +6375 -1532
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5629 -697
- package/dist/index.mjs +5341 -683
- package/dist/index.mjs.map +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +1 -1
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -1
- package/dist/mcpi/approval-grant/index.d.ts +1 -1
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -1
- package/dist/mcpi/approval-grant/index.js +58 -49
- package/dist/mcpi/approval-grant/index.mjs +58 -49
- package/dist/mcpi/approval-grant/index.mjs.map +1 -1
- package/dist/mcpi/dashboard-config/index.d.mts +3 -2
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -1
- package/dist/mcpi/dashboard-config/index.d.ts +3 -2
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -1
- package/dist/posture-origins/index.d.mts +41 -0
- package/dist/posture-origins/index.d.mts.map +1 -0
- package/dist/posture-origins/index.d.ts +41 -0
- package/dist/posture-origins/index.d.ts.map +1 -0
- package/dist/posture-origins/index.js +441 -0
- package/dist/posture-origins/index.mjs +430 -0
- package/dist/posture-origins/index.mjs.map +1 -0
- package/dist/posture-origins-LFkX80oF.js +627 -0
- package/dist/posture-origins-Pn-ii-Pp.mjs +533 -0
- package/dist/posture-origins-Pn-ii-Pp.mjs.map +1 -0
- package/dist/{project-verification-key-CgSVX9_m.mjs → project-verification-key-66N4edKn.mjs} +2 -2
- package/dist/{project-verification-key-CgSVX9_m.mjs.map → project-verification-key-66N4edKn.mjs.map} +1 -1
- package/dist/{project-verification-key-C3L5rd8a.js → project-verification-key-BccT12tQ.js} +1 -1
- package/dist/rules.json +0 -1
- package/dist/{schemas-DxY-dk9y.mjs → schemas-7qodsG-Z.mjs} +49 -2
- package/dist/schemas-7qodsG-Z.mjs.map +1 -0
- package/dist/{schemas-BmjNLAE7.js → schemas-YhagYDx_.js} +59 -0
- package/dist/signals/index.d.mts +75 -55
- package/dist/signals/index.d.mts.map +1 -1
- package/dist/signals/index.d.ts +75 -55
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +246 -2
- package/dist/signals/index.mjs +236 -3
- package/dist/signals/index.mjs.map +1 -1
- package/fixtures/browser-integrity/captured-java-0.2.1-missing-score.json +10 -0
- package/fixtures/browser-integrity/null-score.json +11 -0
- package/fixtures/browser-integrity/numeric-score.json +11 -0
- package/fixtures/browser-posture-claims.json +168 -0
- package/fixtures/browser-posture-headers.json +6 -0
- package/fixtures/cli-registration.v2.json +115 -0
- package/fixtures/detection/reason-codes.json +1 -1
- package/fixtures/kya-http/README.md +34 -25
- package/fixtures/kya-http/consent-handoff.codes.json +34 -0
- package/fixtures/kya-http/protected-resource-metadata.full.json +14 -5
- package/fixtures/kya-http/protected-resource-metadata.invalid-issuer.json +51 -0
- package/fixtures/kya-http/protected-resource-metadata.no-issuer.json +32 -0
- package/fixtures/reviewer-grant-revocation.v1.json +285 -0
- package/fixtures/workbench/a2a-signed-request.v1.json +255 -0
- package/fixtures/workbench/artifact-bindings.v1.json +1003 -0
- package/fixtures/workbench/delegation-management.v1.json +507 -0
- package/fixtures/workbench/didcomm-task-source.v1.json +191 -0
- package/fixtures/workbench/graph-interfaces.v1.json +1887 -0
- package/fixtures/workbench/identity-provisioning.v1.json +643 -0
- package/fixtures/workbench/linear-installation.v1.json +484 -0
- package/fixtures/workbench/management-session.v1.json +716 -0
- package/fixtures/workbench/model-credentials.v1.json +630 -0
- package/fixtures/workbench/source-claim-pooled.v1.json +50 -0
- package/fixtures/workbench/task-grant.v1.json +695 -0
- package/fixtures/workbench/task-status-projection.v1.json +591 -0
- package/fixtures/workbench/workload-enrollment.v1.json +580 -0
- package/package.json +24 -5
- package/src/data/compiled/merged-rules.json +2 -9
- package/src/data/default-rules.json +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +0 -1
- package/dist/browser-posture.d.mts.map +0 -1
- package/dist/browser-posture.d.ts.map +0 -1
- package/dist/patterns-CkRVOdtV.js +0 -243
- package/dist/patterns-DzkGy_qk.mjs +0 -173
- package/dist/patterns-DzkGy_qk.mjs.map +0 -1
- package/dist/schemas-DxY-dk9y.mjs.map +0 -1
- package/fixtures/kya-http/protected-resource-metadata.global.json +0 -28
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { D as ZodOptional, E as ZodObject, L as output, T as ZodNumber, V as $strip, _ as ZodGUID, g as ZodEnum, j as ZodString, l as ZodArray, m as ZodDefault, t as external_d_exports, u as ZodBoolean, w as ZodNullable, x as ZodLiteral } from "./external-B7WI9FyQ.mjs";
|
|
2
|
+
import { JWK, JWK as JWK$1 } from "jose";
|
|
3
|
+
//#region src/browser-posture-cookie.d.ts
|
|
4
|
+
declare function postureCookieName(projectId: string): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/beacon-types/index.d.ts
|
|
7
|
+
declare const POSTURE_TTL_SECONDS = 120;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/browser-posture-schema.d.ts
|
|
10
|
+
declare const BrowserPostureSchema: ZodObject<{
|
|
11
|
+
v: ZodLiteral<1>;
|
|
12
|
+
project_id: ZodString;
|
|
13
|
+
origin: ZodString;
|
|
14
|
+
session_id: ZodGUID;
|
|
15
|
+
binding: ZodString;
|
|
16
|
+
verdict: ZodEnum<{
|
|
17
|
+
human: "human";
|
|
18
|
+
"agent-driven": "agent-driven";
|
|
19
|
+
insufficient: "insufficient";
|
|
20
|
+
}>;
|
|
21
|
+
score: ZodNullable<ZodNumber>;
|
|
22
|
+
scorer_version: ZodNumber;
|
|
23
|
+
reasons: ZodArray<ZodString>;
|
|
24
|
+
automation_disclosed: ZodDefault<ZodBoolean>;
|
|
25
|
+
automation_corroborated: ZodDefault<ZodBoolean>;
|
|
26
|
+
detection: ZodOptional<ZodObject<{
|
|
27
|
+
class: ZodEnum<{
|
|
28
|
+
ai_agent: "ai_agent";
|
|
29
|
+
bot: "bot";
|
|
30
|
+
}>;
|
|
31
|
+
name: ZodString;
|
|
32
|
+
confidence: ZodNumber;
|
|
33
|
+
}, $strip>>;
|
|
34
|
+
cnf: ZodOptional<ZodObject<{
|
|
35
|
+
jkt: ZodString;
|
|
36
|
+
}, $strip>>;
|
|
37
|
+
iat: ZodNumber;
|
|
38
|
+
exp: ZodNumber;
|
|
39
|
+
}, $strip>;
|
|
40
|
+
type BrowserPosture = output<typeof BrowserPostureSchema>;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/browser-posture-report.d.ts
|
|
43
|
+
declare const POSTURE_VERIFICATION_STATUSES: readonly ["verified", "absent", "rejected"];
|
|
44
|
+
type PostureVerificationStatus = (typeof POSTURE_VERIFICATION_STATUSES)[number];
|
|
45
|
+
declare const BrowserPostureReportSchema: ZodObject<{
|
|
46
|
+
projectId: ZodString;
|
|
47
|
+
sessionId: ZodGUID;
|
|
48
|
+
verdict: ZodEnum<{
|
|
49
|
+
human: "human";
|
|
50
|
+
"agent-driven": "agent-driven";
|
|
51
|
+
insufficient: "insufficient";
|
|
52
|
+
}>;
|
|
53
|
+
score: ZodNullable<ZodNumber>;
|
|
54
|
+
scorerVersion: ZodNumber;
|
|
55
|
+
reasons: ZodArray<ZodString>;
|
|
56
|
+
issuedAt: ZodNumber;
|
|
57
|
+
expiresAt: ZodNumber;
|
|
58
|
+
source: ZodLiteral<"verified-posture">;
|
|
59
|
+
}, $strip>;
|
|
60
|
+
declare const BROWSER_POSTURE_REJECTION_REASONS: readonly ["malformed", "unknown-key", "bad-signature", "invalid-claims", "project-mismatch", "origin-mismatch", "audience-mismatch", "expired", "not-yet-valid", "binding-mismatch", "session-missing"];
|
|
61
|
+
type BrowserPostureRejectionReason = (typeof BROWSER_POSTURE_REJECTION_REASONS)[number];
|
|
62
|
+
declare const BrowserPostureOutcomeSchema: ZodObject<{
|
|
63
|
+
status: ZodEnum<{
|
|
64
|
+
verified: "verified";
|
|
65
|
+
absent: "absent";
|
|
66
|
+
rejected: "rejected";
|
|
67
|
+
}>;
|
|
68
|
+
reason: ZodOptional<ZodEnum<{
|
|
69
|
+
malformed: "malformed";
|
|
70
|
+
"unknown-key": "unknown-key";
|
|
71
|
+
"bad-signature": "bad-signature";
|
|
72
|
+
"invalid-claims": "invalid-claims";
|
|
73
|
+
"project-mismatch": "project-mismatch";
|
|
74
|
+
"origin-mismatch": "origin-mismatch";
|
|
75
|
+
"audience-mismatch": "audience-mismatch";
|
|
76
|
+
expired: "expired";
|
|
77
|
+
"not-yet-valid": "not-yet-valid";
|
|
78
|
+
"binding-mismatch": "binding-mismatch";
|
|
79
|
+
"session-missing": "session-missing";
|
|
80
|
+
}>>;
|
|
81
|
+
}, $strip>;
|
|
82
|
+
type BrowserPostureOutcome = output<typeof BrowserPostureOutcomeSchema>;
|
|
83
|
+
declare const BrowserPostureReportIngestSchema: ZodObject<{
|
|
84
|
+
projectId: ZodString;
|
|
85
|
+
sessionId: ZodGUID;
|
|
86
|
+
verdict: ZodEnum<{
|
|
87
|
+
human: "human";
|
|
88
|
+
"agent-driven": "agent-driven";
|
|
89
|
+
insufficient: "insufficient";
|
|
90
|
+
}>;
|
|
91
|
+
scorerVersion: ZodNumber;
|
|
92
|
+
reasons: ZodArray<ZodString>;
|
|
93
|
+
issuedAt: ZodNumber;
|
|
94
|
+
expiresAt: ZodNumber;
|
|
95
|
+
source: ZodLiteral<"verified-posture">;
|
|
96
|
+
score: ZodDefault<ZodNullable<ZodNumber>>;
|
|
97
|
+
}, $strip>;
|
|
98
|
+
declare function browserPostureReport(posture: BrowserPosture): {
|
|
99
|
+
projectId: string;
|
|
100
|
+
sessionId: string;
|
|
101
|
+
verdict: "human" | "agent-driven" | "insufficient";
|
|
102
|
+
score: number | null;
|
|
103
|
+
scorerVersion: number;
|
|
104
|
+
reasons: string[];
|
|
105
|
+
issuedAt: number;
|
|
106
|
+
expiresAt: number;
|
|
107
|
+
source: "verified-posture";
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/browser-posture.d.ts
|
|
111
|
+
declare const UNSIGNED_BROWSER_AGENT: {
|
|
112
|
+
readonly agentType: "Browser agent (unsigned)";
|
|
113
|
+
readonly detectionClass: "ai_agent";
|
|
114
|
+
readonly verificationMethod: "behavioral";
|
|
115
|
+
};
|
|
116
|
+
declare const behavioralConfidence: (score: number | null) => number;
|
|
117
|
+
interface PostureUpgrade {
|
|
118
|
+
detectionClass: 'ai_agent' | 'bot' | 'incomplete_data';
|
|
119
|
+
isAgent: boolean;
|
|
120
|
+
agentName?: string;
|
|
121
|
+
confidence: number;
|
|
122
|
+
verificationMethod: 'behavioral';
|
|
123
|
+
reasons: string[];
|
|
124
|
+
}
|
|
125
|
+
declare function postureUpgrade(posture: BrowserPosture): PostureUpgrade | undefined;
|
|
126
|
+
declare const POSTURE_ISSUER = "checkpoint:browser-posture:v1";
|
|
127
|
+
declare const POSTURE_TYPE = "checkpoint-posture+jwt";
|
|
128
|
+
interface BrowserPostureConfig {
|
|
129
|
+
publicKey: JWK;
|
|
130
|
+
keyId: string;
|
|
131
|
+
origin: string;
|
|
132
|
+
origins?: string[];
|
|
133
|
+
sessionCookieName?: string;
|
|
134
|
+
protectedRoutes?: Array<{
|
|
135
|
+
path: string;
|
|
136
|
+
scopes: string[];
|
|
137
|
+
}>;
|
|
138
|
+
}
|
|
139
|
+
declare function readPostureCookie(header: string | null | undefined, name: string): string | undefined;
|
|
140
|
+
declare function postureSessionBinding(sessionId: string): Promise<string>;
|
|
141
|
+
declare function signBrowserPosture(posture: BrowserPosture, privateKey: JWK, keyId: string): Promise<string>;
|
|
142
|
+
type PostureVerification = {
|
|
143
|
+
status: 'verified';
|
|
144
|
+
posture: BrowserPosture;
|
|
145
|
+
} | {
|
|
146
|
+
status: 'absent';
|
|
147
|
+
} | {
|
|
148
|
+
status: 'rejected';
|
|
149
|
+
reason: BrowserPostureRejectionReason;
|
|
150
|
+
};
|
|
151
|
+
declare const postureOutcomeReport: (outcome: PostureVerification) => BrowserPostureOutcome;
|
|
152
|
+
declare function inspectBrowserPosture(token: string | undefined, config: BrowserPostureConfig, projectId: string, browserSessionId: string | undefined, now?: number): Promise<PostureVerification>;
|
|
153
|
+
declare function verifyBrowserPosture(token: string | undefined, config: BrowserPostureConfig, projectId: string, browserSessionId: string | undefined, now?: number): Promise<BrowserPosture | undefined>;
|
|
154
|
+
declare const POSTURE_HEADER = "kya-posture";
|
|
155
|
+
declare const POSTURE_SESSION_HEADER = "kya-posture-session";
|
|
156
|
+
interface PostureRequest {
|
|
157
|
+
cookie?: string | null;
|
|
158
|
+
posture?: string | string[] | null;
|
|
159
|
+
session?: string | string[] | null;
|
|
160
|
+
}
|
|
161
|
+
declare function postureRequestFromHeaders(get: (lowercaseName: string) => string | string[] | null | undefined): PostureRequest;
|
|
162
|
+
declare function postureOutcomeFromRequest(request: PostureRequest, config: BrowserPostureConfig, projectId: string, now?: number): Promise<PostureVerification>;
|
|
163
|
+
declare function postureFromRequest(request: PostureRequest, config: BrowserPostureConfig, projectId: string, now?: number): Promise<BrowserPosture | undefined>;
|
|
164
|
+
declare function postureFromCookies(header: string | null | undefined, config: BrowserPostureConfig, projectId: string): Promise<BrowserPosture | undefined>;
|
|
165
|
+
declare function postureRequiredScopes(config: BrowserPostureConfig, path: string): string[] | undefined;
|
|
166
|
+
declare function validateBrowserPostureConfig(config: BrowserPostureConfig, projectId: string | undefined): void;
|
|
167
|
+
//#endregion
|
|
168
|
+
export { POSTURE_VERIFICATION_STATUSES as A, verifyBrowserPosture as C, BrowserPostureRejectionReason as D, BrowserPostureOutcomeSchema as E, POSTURE_TTL_SECONDS as F, postureCookieName as I, browserPostureReport as M, BrowserPosture as N, BrowserPostureReportIngestSchema as O, BrowserPostureSchema as P, validateBrowserPostureConfig as S, BrowserPostureOutcome as T, postureRequiredScopes as _, POSTURE_SESSION_HEADER as a, readPostureCookie as b, PostureVerification as c, inspectBrowserPosture as d, postureFromCookies as f, postureRequestFromHeaders as g, postureOutcomeReport as h, POSTURE_ISSUER as i, PostureVerificationStatus as j, BrowserPostureReportSchema as k, UNSIGNED_BROWSER_AGENT as l, postureOutcomeFromRequest as m, JWK$1 as n, POSTURE_TYPE as o, postureFromRequest as p, POSTURE_HEADER as r, PostureRequest as s, BrowserPostureConfig as t, behavioralConfidence as u, postureSessionBinding as v, BROWSER_POSTURE_REJECTION_REASONS as w, signBrowserPosture as x, postureUpgrade as y };
|
|
169
|
+
//# sourceMappingURL=browser-posture-BuChqmH5.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-BuChqmH5.d.mts","names":[],"sources":["../src/browser-posture-cookie.ts","../src/beacon-types/index.ts","../src/browser-posture-schema.ts","../src/browser-posture-report.ts","../src/browser-posture.ts"],"mappings":";;;iBAgBgB,kBAAkB;;;cC4jDrB;;;cC1kDA,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2C/B;KAGU,iBAAiB,cAAe;;;cC7C/B;KACD,oCAAoC;cAGnC,4BAA0B;;;;;;;;;;;;;;GAWrC;cAEW;KAaD,wCAAwC;cAEvC,6BAA2B;;;;;;;;;;;;;;;;;;;GAQpC;KACQ,wBAAwB,cAAe;cA2BtC,kCAAgC;;;;;;;;;;;;;;GAE3C;iBAEc,qBAAqB,SAAS;;;;;;;;;;;;;cClDjC;;;;;cAKA,uBAAwB;UAG3B;EACR;EACA;EACA;EACA;EACA;EACA;;iBAGc,eAAe,SAAS,iBAAiB;cAyC5C;cAGA;UAEI;EAEf,WAAW;EACX;EAEA;EACA;EACA;EAEA,kBAAkB;IAAQ;IAAc;;;iBAI1B,kBACd,mCACA;iBAcoB,sBAAsB,oBAAoB;iBAc1C,mBACpB,SAAS,gBACT,YAAY,KACZ,gBACC;KAqBS;EACN;EAAoB,SAAS;;EAC7B;;EACA;EAAoB,QAAQ;;cAOrB,uBAAwB,SAAS,wBAAsB;iBAM9C,sBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;iBA2EW,qBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;cAYE;cACA;UAGI;EACf;EAEA;EAEA;;iBAIc,0BACd,MAAM,iEACL;iBA6BmB,0BACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAcW,mBACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAIW,mBACpB,mCACA,QAAQ,sBACR,oBACC,QAAQ;iBAKK,sBACd,QAAQ,sBACR;iBAmBc,6BACd,QAAQ,sBACR"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { D as ZodOptional, E as ZodObject, L as output, T as ZodNumber, V as $strip, _ as ZodGUID, g as ZodEnum, j as ZodString, l as ZodArray, m as ZodDefault, t as external_d_exports, u as ZodBoolean, w as ZodNullable, x as ZodLiteral } from "./external-B7WI9FyQ.js";
|
|
2
|
+
import { JWK, JWK as JWK$1 } from "jose";
|
|
3
|
+
//#region src/browser-posture-cookie.d.ts
|
|
4
|
+
declare function postureCookieName(projectId: string): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/beacon-types/index.d.ts
|
|
7
|
+
declare const POSTURE_TTL_SECONDS = 120;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/browser-posture-schema.d.ts
|
|
10
|
+
declare const BrowserPostureSchema: ZodObject<{
|
|
11
|
+
v: ZodLiteral<1>;
|
|
12
|
+
project_id: ZodString;
|
|
13
|
+
origin: ZodString;
|
|
14
|
+
session_id: ZodGUID;
|
|
15
|
+
binding: ZodString;
|
|
16
|
+
verdict: ZodEnum<{
|
|
17
|
+
human: "human";
|
|
18
|
+
"agent-driven": "agent-driven";
|
|
19
|
+
insufficient: "insufficient";
|
|
20
|
+
}>;
|
|
21
|
+
score: ZodNullable<ZodNumber>;
|
|
22
|
+
scorer_version: ZodNumber;
|
|
23
|
+
reasons: ZodArray<ZodString>;
|
|
24
|
+
automation_disclosed: ZodDefault<ZodBoolean>;
|
|
25
|
+
automation_corroborated: ZodDefault<ZodBoolean>;
|
|
26
|
+
detection: ZodOptional<ZodObject<{
|
|
27
|
+
class: ZodEnum<{
|
|
28
|
+
ai_agent: "ai_agent";
|
|
29
|
+
bot: "bot";
|
|
30
|
+
}>;
|
|
31
|
+
name: ZodString;
|
|
32
|
+
confidence: ZodNumber;
|
|
33
|
+
}, $strip>>;
|
|
34
|
+
cnf: ZodOptional<ZodObject<{
|
|
35
|
+
jkt: ZodString;
|
|
36
|
+
}, $strip>>;
|
|
37
|
+
iat: ZodNumber;
|
|
38
|
+
exp: ZodNumber;
|
|
39
|
+
}, $strip>;
|
|
40
|
+
type BrowserPosture = output<typeof BrowserPostureSchema>;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/browser-posture-report.d.ts
|
|
43
|
+
declare const POSTURE_VERIFICATION_STATUSES: readonly ["verified", "absent", "rejected"];
|
|
44
|
+
type PostureVerificationStatus = (typeof POSTURE_VERIFICATION_STATUSES)[number];
|
|
45
|
+
declare const BrowserPostureReportSchema: ZodObject<{
|
|
46
|
+
projectId: ZodString;
|
|
47
|
+
sessionId: ZodGUID;
|
|
48
|
+
verdict: ZodEnum<{
|
|
49
|
+
human: "human";
|
|
50
|
+
"agent-driven": "agent-driven";
|
|
51
|
+
insufficient: "insufficient";
|
|
52
|
+
}>;
|
|
53
|
+
score: ZodNullable<ZodNumber>;
|
|
54
|
+
scorerVersion: ZodNumber;
|
|
55
|
+
reasons: ZodArray<ZodString>;
|
|
56
|
+
issuedAt: ZodNumber;
|
|
57
|
+
expiresAt: ZodNumber;
|
|
58
|
+
source: ZodLiteral<"verified-posture">;
|
|
59
|
+
}, $strip>;
|
|
60
|
+
declare const BROWSER_POSTURE_REJECTION_REASONS: readonly ["malformed", "unknown-key", "bad-signature", "invalid-claims", "project-mismatch", "origin-mismatch", "audience-mismatch", "expired", "not-yet-valid", "binding-mismatch", "session-missing"];
|
|
61
|
+
type BrowserPostureRejectionReason = (typeof BROWSER_POSTURE_REJECTION_REASONS)[number];
|
|
62
|
+
declare const BrowserPostureOutcomeSchema: ZodObject<{
|
|
63
|
+
status: ZodEnum<{
|
|
64
|
+
verified: "verified";
|
|
65
|
+
absent: "absent";
|
|
66
|
+
rejected: "rejected";
|
|
67
|
+
}>;
|
|
68
|
+
reason: ZodOptional<ZodEnum<{
|
|
69
|
+
malformed: "malformed";
|
|
70
|
+
"unknown-key": "unknown-key";
|
|
71
|
+
"bad-signature": "bad-signature";
|
|
72
|
+
"invalid-claims": "invalid-claims";
|
|
73
|
+
"project-mismatch": "project-mismatch";
|
|
74
|
+
"origin-mismatch": "origin-mismatch";
|
|
75
|
+
"audience-mismatch": "audience-mismatch";
|
|
76
|
+
expired: "expired";
|
|
77
|
+
"not-yet-valid": "not-yet-valid";
|
|
78
|
+
"binding-mismatch": "binding-mismatch";
|
|
79
|
+
"session-missing": "session-missing";
|
|
80
|
+
}>>;
|
|
81
|
+
}, $strip>;
|
|
82
|
+
type BrowserPostureOutcome = output<typeof BrowserPostureOutcomeSchema>;
|
|
83
|
+
declare const BrowserPostureReportIngestSchema: ZodObject<{
|
|
84
|
+
projectId: ZodString;
|
|
85
|
+
sessionId: ZodGUID;
|
|
86
|
+
verdict: ZodEnum<{
|
|
87
|
+
human: "human";
|
|
88
|
+
"agent-driven": "agent-driven";
|
|
89
|
+
insufficient: "insufficient";
|
|
90
|
+
}>;
|
|
91
|
+
scorerVersion: ZodNumber;
|
|
92
|
+
reasons: ZodArray<ZodString>;
|
|
93
|
+
issuedAt: ZodNumber;
|
|
94
|
+
expiresAt: ZodNumber;
|
|
95
|
+
source: ZodLiteral<"verified-posture">;
|
|
96
|
+
score: ZodDefault<ZodNullable<ZodNumber>>;
|
|
97
|
+
}, $strip>;
|
|
98
|
+
declare function browserPostureReport(posture: BrowserPosture): {
|
|
99
|
+
projectId: string;
|
|
100
|
+
sessionId: string;
|
|
101
|
+
verdict: "human" | "agent-driven" | "insufficient";
|
|
102
|
+
score: number | null;
|
|
103
|
+
scorerVersion: number;
|
|
104
|
+
reasons: string[];
|
|
105
|
+
issuedAt: number;
|
|
106
|
+
expiresAt: number;
|
|
107
|
+
source: "verified-posture";
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/browser-posture.d.ts
|
|
111
|
+
declare const UNSIGNED_BROWSER_AGENT: {
|
|
112
|
+
readonly agentType: "Browser agent (unsigned)";
|
|
113
|
+
readonly detectionClass: "ai_agent";
|
|
114
|
+
readonly verificationMethod: "behavioral";
|
|
115
|
+
};
|
|
116
|
+
declare const behavioralConfidence: (score: number | null) => number;
|
|
117
|
+
interface PostureUpgrade {
|
|
118
|
+
detectionClass: 'ai_agent' | 'bot' | 'incomplete_data';
|
|
119
|
+
isAgent: boolean;
|
|
120
|
+
agentName?: string;
|
|
121
|
+
confidence: number;
|
|
122
|
+
verificationMethod: 'behavioral';
|
|
123
|
+
reasons: string[];
|
|
124
|
+
}
|
|
125
|
+
declare function postureUpgrade(posture: BrowserPosture): PostureUpgrade | undefined;
|
|
126
|
+
declare const POSTURE_ISSUER = "checkpoint:browser-posture:v1";
|
|
127
|
+
declare const POSTURE_TYPE = "checkpoint-posture+jwt";
|
|
128
|
+
interface BrowserPostureConfig {
|
|
129
|
+
publicKey: JWK;
|
|
130
|
+
keyId: string;
|
|
131
|
+
origin: string;
|
|
132
|
+
origins?: string[];
|
|
133
|
+
sessionCookieName?: string;
|
|
134
|
+
protectedRoutes?: Array<{
|
|
135
|
+
path: string;
|
|
136
|
+
scopes: string[];
|
|
137
|
+
}>;
|
|
138
|
+
}
|
|
139
|
+
declare function readPostureCookie(header: string | null | undefined, name: string): string | undefined;
|
|
140
|
+
declare function postureSessionBinding(sessionId: string): Promise<string>;
|
|
141
|
+
declare function signBrowserPosture(posture: BrowserPosture, privateKey: JWK, keyId: string): Promise<string>;
|
|
142
|
+
type PostureVerification = {
|
|
143
|
+
status: 'verified';
|
|
144
|
+
posture: BrowserPosture;
|
|
145
|
+
} | {
|
|
146
|
+
status: 'absent';
|
|
147
|
+
} | {
|
|
148
|
+
status: 'rejected';
|
|
149
|
+
reason: BrowserPostureRejectionReason;
|
|
150
|
+
};
|
|
151
|
+
declare const postureOutcomeReport: (outcome: PostureVerification) => BrowserPostureOutcome;
|
|
152
|
+
declare function inspectBrowserPosture(token: string | undefined, config: BrowserPostureConfig, projectId: string, browserSessionId: string | undefined, now?: number): Promise<PostureVerification>;
|
|
153
|
+
declare function verifyBrowserPosture(token: string | undefined, config: BrowserPostureConfig, projectId: string, browserSessionId: string | undefined, now?: number): Promise<BrowserPosture | undefined>;
|
|
154
|
+
declare const POSTURE_HEADER = "kya-posture";
|
|
155
|
+
declare const POSTURE_SESSION_HEADER = "kya-posture-session";
|
|
156
|
+
interface PostureRequest {
|
|
157
|
+
cookie?: string | null;
|
|
158
|
+
posture?: string | string[] | null;
|
|
159
|
+
session?: string | string[] | null;
|
|
160
|
+
}
|
|
161
|
+
declare function postureRequestFromHeaders(get: (lowercaseName: string) => string | string[] | null | undefined): PostureRequest;
|
|
162
|
+
declare function postureOutcomeFromRequest(request: PostureRequest, config: BrowserPostureConfig, projectId: string, now?: number): Promise<PostureVerification>;
|
|
163
|
+
declare function postureFromRequest(request: PostureRequest, config: BrowserPostureConfig, projectId: string, now?: number): Promise<BrowserPosture | undefined>;
|
|
164
|
+
declare function postureFromCookies(header: string | null | undefined, config: BrowserPostureConfig, projectId: string): Promise<BrowserPosture | undefined>;
|
|
165
|
+
declare function postureRequiredScopes(config: BrowserPostureConfig, path: string): string[] | undefined;
|
|
166
|
+
declare function validateBrowserPostureConfig(config: BrowserPostureConfig, projectId: string | undefined): void;
|
|
167
|
+
//#endregion
|
|
168
|
+
export { POSTURE_VERIFICATION_STATUSES as A, verifyBrowserPosture as C, BrowserPostureRejectionReason as D, BrowserPostureOutcomeSchema as E, POSTURE_TTL_SECONDS as F, postureCookieName as I, browserPostureReport as M, BrowserPosture as N, BrowserPostureReportIngestSchema as O, BrowserPostureSchema as P, validateBrowserPostureConfig as S, BrowserPostureOutcome as T, postureRequiredScopes as _, POSTURE_SESSION_HEADER as a, readPostureCookie as b, PostureVerification as c, inspectBrowserPosture as d, postureFromCookies as f, postureRequestFromHeaders as g, postureOutcomeReport as h, POSTURE_ISSUER as i, PostureVerificationStatus as j, BrowserPostureReportSchema as k, UNSIGNED_BROWSER_AGENT as l, postureOutcomeFromRequest as m, JWK$1 as n, POSTURE_TYPE as o, postureFromRequest as p, POSTURE_HEADER as r, PostureRequest as s, BrowserPostureConfig as t, behavioralConfidence as u, postureSessionBinding as v, BROWSER_POSTURE_REJECTION_REASONS as w, signBrowserPosture as x, postureUpgrade as y };
|
|
169
|
+
//# sourceMappingURL=browser-posture-DIaVLuW3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-DIaVLuW3.d.ts","names":[],"sources":["../src/browser-posture-cookie.ts","../src/beacon-types/index.ts","../src/browser-posture-schema.ts","../src/browser-posture-report.ts","../src/browser-posture.ts"],"mappings":";;;iBAgBgB,kBAAkB;;;cC4jDrB;;;cC1kDA,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2C/B;KAGU,iBAAiB,cAAe;;;cC7C/B;KACD,oCAAoC;cAGnC,4BAA0B;;;;;;;;;;;;;;GAWrC;cAEW;KAaD,wCAAwC;cAEvC,6BAA2B;;;;;;;;;;;;;;;;;;;GAQpC;KACQ,wBAAwB,cAAe;cA2BtC,kCAAgC;;;;;;;;;;;;;;GAE3C;iBAEc,qBAAqB,SAAS;;;;;;;;;;;;;cClDjC;;;;;cAKA,uBAAwB;UAG3B;EACR;EACA;EACA;EACA;EACA;EACA;;iBAGc,eAAe,SAAS,iBAAiB;cAyC5C;cAGA;UAEI;EAEf,WAAW;EACX;EAEA;EACA;EACA;EAEA,kBAAkB;IAAQ;IAAc;;;iBAI1B,kBACd,mCACA;iBAcoB,sBAAsB,oBAAoB;iBAc1C,mBACpB,SAAS,gBACT,YAAY,KACZ,gBACC;KAqBS;EACN;EAAoB,SAAS;;EAC7B;;EACA;EAAoB,QAAQ;;cAOrB,uBAAwB,SAAS,wBAAsB;iBAM9C,sBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;iBA2EW,qBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;cAYE;cACA;UAGI;EACf;EAEA;EAEA;;iBAIc,0BACd,MAAM,iEACL;iBA6BmB,0BACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAcW,mBACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAIW,mBACpB,mCACA,QAAQ,sBACR,oBACC,QAAQ;iBAKK,sBACd,QAAQ,sBACR;iBAmBc,6BACd,QAAQ,sBACR"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
//#region src/browser-posture-cookie.d.ts
|
|
2
|
+
export declare function postureCookieName(projectId: string): string;
|
|
3
|
+
//#endregion
|
|
4
|
+
//# sourceMappingURL=browser-posture-cookie.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-cookie.d.mts","names":[],"sources":["../src/browser-posture-cookie.ts"],"mappings":";wBAgBgB,kBAAkB"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
//#region src/browser-posture-cookie.d.ts
|
|
2
|
+
export declare function postureCookieName(projectId: string): string;
|
|
3
|
+
//#endregion
|
|
4
|
+
//# sourceMappingURL=browser-posture-cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-cookie.d.ts","names":[],"sources":["../src/browser-posture-cookie.ts"],"mappings":";wBAgBgB,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-posture-cookie.mjs","names":[],"sources":["../src/constants/patterns.ts","../src/browser-posture-cookie.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.\n// The beacon inlines that leaf (`noExternal`), which pushed its gzipped\n// bundle from 29,337 to 30,123 against a 29,696-byte CI budget.\n//\n// UUID pattern: accepts versions 0-5 (0 is nil UUID, 1-5 are standard versions)\n// Variants: 0 (nil), 8-9-a-b (standard variants)\nexport const UUID_PATTERN =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][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: /(?:Google-Extended|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","// Imports the single hoisted pattern, not the whole `VALIDATION_PATTERNS`\n// object — same definition, but it keeps this leaf actually dependency-free\n// under rolldown, which does not property-shake object literals.\nimport { UUID_PATTERN } from './constants/patterns';\n\n/**\n * The browser-posture cookie name. Kept in its own dependency-free leaf so the\n * beacon (bundle-size budgeted, no `jose`) derives the name from the SAME\n * function every SDK reader uses via `./browser-posture`; two independent\n * derivations of this name is exactly the drift that dropped the cookie.\n *\n * The lowercase UUID only: the issuer signs `project_id` as the database's\n * lowercase project UUID and cookie names compare case-sensitively, so a\n * friendly id, or the same UUID in upper case, can never name a cookie a\n * reader will look for.\n */\nexport function postureCookieName(projectId: string): string {\n if (!UUID_PATTERN.test(projectId) || projectId !== projectId.toLowerCase())\n throw new Error('Invalid posture project id');\n return `__Host-checkpoint_posture_${projectId}`;\n}\n"],"mappings":"AAsBA,MAAa,EACX,8ECPF,SAAgB,EAAkB,EAA2B,CAC3D,GAAI,CAAC,EAAa,KAAK,CAAS,GAAK,IAAc,EAAU,YAAY,EACvE,MAAU,MAAM,4BAA4B,EAC9C,MAAO,6BAA6B,GACtC"}
|
|
1
|
+
{"version":3,"file":"browser-posture-cookie.mjs","names":[],"sources":["../src/constants/patterns.ts","../src/browser-posture-cookie.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.\n// The beacon inlines that leaf (`noExternal`), which pushed its gzipped\n// bundle from 29,337 to 30,123 against a 29,696-byte CI budget.\n//\n// UUID pattern: accepts versions 0-5 (0 is nil UUID, 1-5 are standard versions)\n// Variants: 0 (nil), 8-9-a-b (standard variants)\nexport const UUID_PATTERN =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][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","// Imports the single hoisted pattern, not the whole `VALIDATION_PATTERNS`\n// object — same definition, but it keeps this leaf actually dependency-free\n// under rolldown, which does not property-shake object literals.\nimport { UUID_PATTERN } from './constants/patterns';\n\n/**\n * The browser-posture cookie name. Kept in its own dependency-free leaf so the\n * beacon (bundle-size budgeted, no `jose`) derives the name from the SAME\n * function every SDK reader uses via `./browser-posture`; two independent\n * derivations of this name is exactly the drift that dropped the cookie.\n *\n * The lowercase UUID only: the issuer signs `project_id` as the database's\n * lowercase project UUID and cookie names compare case-sensitively, so a\n * friendly id, or the same UUID in upper case, can never name a cookie a\n * reader will look for.\n */\nexport function postureCookieName(projectId: string): string {\n if (!UUID_PATTERN.test(projectId) || projectId !== projectId.toLowerCase())\n throw new Error('Invalid posture project id');\n return `__Host-checkpoint_posture_${projectId}`;\n}\n"],"mappings":"AAsBA,MAAa,EACX,8ECPF,SAAgB,EAAkB,EAA2B,CAC3D,GAAI,CAAC,EAAa,KAAK,CAAS,GAAK,IAAc,EAAU,YAAY,EACvE,MAAU,MAAM,4BAA4B,EAC9C,MAAO,6BAA6B,GACtC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { E as ZodObject, L as output, T as ZodNumber, V as $strip, j as ZodString, t as external_d_exports } from "./external-B7WI9FyQ.mjs";
|
|
2
|
+
import { N as BrowserPosture } from "./browser-posture-BuChqmH5.mjs";
|
|
3
|
+
//#region src/browser-posture-proof.d.ts
|
|
4
|
+
export declare const POSTURE_PROOF_TYPE = "dpop+jwt";
|
|
5
|
+
export declare const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
|
|
6
|
+
export declare const BrowserPostureProofSchema: ZodObject<{
|
|
7
|
+
jti: ZodString;
|
|
8
|
+
htm: ZodString;
|
|
9
|
+
htu: ZodString;
|
|
10
|
+
iat: ZodNumber;
|
|
11
|
+
}, $strip>;
|
|
12
|
+
export type BrowserPostureProof = output<typeof BrowserPostureProofSchema>;
|
|
13
|
+
export declare function verifyBrowserPostureProof(proofJws: string | undefined, posture: BrowserPosture, request: {
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}, now?: number, maxAgeSeconds?: number): Promise<BrowserPostureProof | undefined>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//# sourceMappingURL=browser-posture-proof.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-proof.d.mts","names":[],"sources":["../src/browser-posture-proof.ts"],"mappings":";;;qBAYa;qBAKA;qBAEA,2BAAyB;;;;;GAKpC;YACU,sBAAsB,cAAe;wBAgB3B,0BACpB,8BACA,SAAS,gBACT;EAAW;EAAgB;GAC3B,cACA,yBACC,QAAQ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { E as ZodObject, L as output, T as ZodNumber, V as $strip, j as ZodString, t as external_d_exports } from "./external-B7WI9FyQ.js";
|
|
2
|
+
import { N as BrowserPosture } from "./browser-posture-DIaVLuW3.js";
|
|
3
|
+
//#region src/browser-posture-proof.d.ts
|
|
4
|
+
export declare const POSTURE_PROOF_TYPE = "dpop+jwt";
|
|
5
|
+
export declare const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
|
|
6
|
+
export declare const BrowserPostureProofSchema: ZodObject<{
|
|
7
|
+
jti: ZodString;
|
|
8
|
+
htm: ZodString;
|
|
9
|
+
htu: ZodString;
|
|
10
|
+
iat: ZodNumber;
|
|
11
|
+
}, $strip>;
|
|
12
|
+
export type BrowserPostureProof = output<typeof BrowserPostureProofSchema>;
|
|
13
|
+
export declare function verifyBrowserPostureProof(proofJws: string | undefined, posture: BrowserPosture, request: {
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}, now?: number, maxAgeSeconds?: number): Promise<BrowserPostureProof | undefined>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//# sourceMappingURL=browser-posture-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-proof.d.ts","names":[],"sources":["../src/browser-posture-proof.ts"],"mappings":";;;qBAYa;qBAKA;qBAEA,2BAAyB;;;;;GAKpC;YACU,sBAAsB,cAAe;wBAgB3B,0BACpB,8BACA,SAAS,gBACT;EAAW;EAAgB;GAC3B,cACA,yBACC,QAAQ"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_schemas = require('./schemas-YhagYDx_.js');
|
|
3
|
+
let jose = require("jose");
|
|
4
|
+
|
|
5
|
+
//#region src/browser-posture-proof.ts
|
|
6
|
+
/**
|
|
7
|
+
* RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture
|
|
8
|
+
* token to a non-extractable key the page holds, so the posture token's
|
|
9
|
+
* TTL stops being the whole replay window. The literal RFC 9449 `typ`
|
|
10
|
+
* value, not a project-specific string like the posture token's own
|
|
11
|
+
* `checkpoint-posture+jwt` - adopting the registered value buys real
|
|
12
|
+
* interoperability with any existing DPoP-aware tooling for no cost.
|
|
13
|
+
*/
|
|
14
|
+
const POSTURE_PROOF_TYPE = "dpop+jwt";
|
|
15
|
+
/** Half the posture TTL: a per-request, single-use artifact needs a much
|
|
16
|
+
* tighter freshness window than a session-scoped token. A caller-supplied
|
|
17
|
+
* parameter, not a private constant - this must never repeat
|
|
18
|
+
* `POSTURE_TTL_SECONDS`'s own hardcoding mistake. */
|
|
19
|
+
const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
|
|
20
|
+
const BrowserPostureProofSchema = require_schemas.object({
|
|
21
|
+
jti: require_schemas.string().min(1).max(255),
|
|
22
|
+
htm: require_schemas.string().min(1).max(16),
|
|
23
|
+
htu: require_schemas.string().url(),
|
|
24
|
+
iat: require_schemas.number().int().nonnegative()
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Verifies a DPoP-shaped proof (RFC 9449) against an ALREADY-VERIFIED
|
|
28
|
+
* `BrowserPosture` (call `verifyBrowserPosture` first). Checks, in order:
|
|
29
|
+
* the proof's own header shape (`typ`, `alg`, embedded `jwk`); that the
|
|
30
|
+
* embedded key's RFC 7638 thumbprint matches `posture.cnf.jkt`; the
|
|
31
|
+
* proof's ES256 signature against that same embedded key; `htm`/`htu`
|
|
32
|
+
* against the real request; `iat` freshness. Returns `undefined` on ANY
|
|
33
|
+
* failure, including when `posture.cnf` is absent (no binding to check
|
|
34
|
+
* against), never throws.
|
|
35
|
+
*
|
|
36
|
+
* Does NOT check `jti` replay: that needs a store this library does not
|
|
37
|
+
* own. The caller checks the returned proof's `jti` against their own
|
|
38
|
+
* replay store as the final step before trusting the request.
|
|
39
|
+
*/
|
|
40
|
+
async function verifyBrowserPostureProof(proofJws, posture, request, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
|
|
41
|
+
if (!proofJws || proofJws.length > 2e3 || !posture.cnf) return void 0;
|
|
42
|
+
try {
|
|
43
|
+
const decoded = JSON.parse(Buffer.from(proofJws.split(".")[0], "base64url").toString("utf8"));
|
|
44
|
+
if (decoded.typ !== "dpop+jwt" || decoded.alg !== "ES256" || !decoded.jwk || decoded.jwk.kty !== "EC" || decoded.jwk.crv !== "P-256" || decoded.jwk.d) return void 0;
|
|
45
|
+
if (await (0, jose.calculateJwkThumbprint)(decoded.jwk, "sha256") !== posture.cnf.jkt) return void 0;
|
|
46
|
+
const key = await (0, jose.importJWK)(decoded.jwk, "ES256");
|
|
47
|
+
const { payload } = await (0, jose.jwtVerify)(proofJws, key, {
|
|
48
|
+
algorithms: ["ES256"],
|
|
49
|
+
typ: POSTURE_PROOF_TYPE,
|
|
50
|
+
currentDate: /* @__PURE__ */ new Date(now * 1e3)
|
|
51
|
+
});
|
|
52
|
+
const parsed = BrowserPostureProofSchema.safeParse(payload);
|
|
53
|
+
if (!parsed.success) return void 0;
|
|
54
|
+
const claims = parsed.data;
|
|
55
|
+
if (claims.htm.toUpperCase() !== request.method.toUpperCase() || claims.htu !== request.url || Math.abs(now - claims.iat) > maxAgeSeconds) return void 0;
|
|
56
|
+
return claims;
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.BrowserPostureProofSchema = BrowserPostureProofSchema;
|
|
64
|
+
exports.DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS;
|
|
65
|
+
exports.POSTURE_PROOF_TYPE = POSTURE_PROOF_TYPE;
|
|
66
|
+
exports.verifyBrowserPostureProof = verifyBrowserPostureProof;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { C as string, v as number, y as object } from "./schemas-7qodsG-Z.mjs";
|
|
2
|
+
import { calculateJwkThumbprint, importJWK, jwtVerify } from "jose";
|
|
3
|
+
|
|
4
|
+
//#region src/browser-posture-proof.ts
|
|
5
|
+
/**
|
|
6
|
+
* RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture
|
|
7
|
+
* token to a non-extractable key the page holds, so the posture token's
|
|
8
|
+
* TTL stops being the whole replay window. The literal RFC 9449 `typ`
|
|
9
|
+
* value, not a project-specific string like the posture token's own
|
|
10
|
+
* `checkpoint-posture+jwt` - adopting the registered value buys real
|
|
11
|
+
* interoperability with any existing DPoP-aware tooling for no cost.
|
|
12
|
+
*/
|
|
13
|
+
const POSTURE_PROOF_TYPE = "dpop+jwt";
|
|
14
|
+
/** Half the posture TTL: a per-request, single-use artifact needs a much
|
|
15
|
+
* tighter freshness window than a session-scoped token. A caller-supplied
|
|
16
|
+
* parameter, not a private constant - this must never repeat
|
|
17
|
+
* `POSTURE_TTL_SECONDS`'s own hardcoding mistake. */
|
|
18
|
+
const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
|
|
19
|
+
const BrowserPostureProofSchema = object({
|
|
20
|
+
jti: string().min(1).max(255),
|
|
21
|
+
htm: string().min(1).max(16),
|
|
22
|
+
htu: string().url(),
|
|
23
|
+
iat: number().int().nonnegative()
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Verifies a DPoP-shaped proof (RFC 9449) against an ALREADY-VERIFIED
|
|
27
|
+
* `BrowserPosture` (call `verifyBrowserPosture` first). Checks, in order:
|
|
28
|
+
* the proof's own header shape (`typ`, `alg`, embedded `jwk`); that the
|
|
29
|
+
* embedded key's RFC 7638 thumbprint matches `posture.cnf.jkt`; the
|
|
30
|
+
* proof's ES256 signature against that same embedded key; `htm`/`htu`
|
|
31
|
+
* against the real request; `iat` freshness. Returns `undefined` on ANY
|
|
32
|
+
* failure, including when `posture.cnf` is absent (no binding to check
|
|
33
|
+
* against), never throws.
|
|
34
|
+
*
|
|
35
|
+
* Does NOT check `jti` replay: that needs a store this library does not
|
|
36
|
+
* own. The caller checks the returned proof's `jti` against their own
|
|
37
|
+
* replay store as the final step before trusting the request.
|
|
38
|
+
*/
|
|
39
|
+
async function verifyBrowserPostureProof(proofJws, posture, request, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
|
|
40
|
+
if (!proofJws || proofJws.length > 2e3 || !posture.cnf) return void 0;
|
|
41
|
+
try {
|
|
42
|
+
const decoded = JSON.parse(Buffer.from(proofJws.split(".")[0], "base64url").toString("utf8"));
|
|
43
|
+
if (decoded.typ !== "dpop+jwt" || decoded.alg !== "ES256" || !decoded.jwk || decoded.jwk.kty !== "EC" || decoded.jwk.crv !== "P-256" || decoded.jwk.d) return void 0;
|
|
44
|
+
if (await calculateJwkThumbprint(decoded.jwk, "sha256") !== posture.cnf.jkt) return void 0;
|
|
45
|
+
const key = await importJWK(decoded.jwk, "ES256");
|
|
46
|
+
const { payload } = await jwtVerify(proofJws, key, {
|
|
47
|
+
algorithms: ["ES256"],
|
|
48
|
+
typ: POSTURE_PROOF_TYPE,
|
|
49
|
+
currentDate: /* @__PURE__ */ new Date(now * 1e3)
|
|
50
|
+
});
|
|
51
|
+
const parsed = BrowserPostureProofSchema.safeParse(payload);
|
|
52
|
+
if (!parsed.success) return void 0;
|
|
53
|
+
const claims = parsed.data;
|
|
54
|
+
if (claims.htm.toUpperCase() !== request.method.toUpperCase() || claims.htu !== request.url || Math.abs(now - claims.iat) > maxAgeSeconds) return void 0;
|
|
55
|
+
return claims;
|
|
56
|
+
} catch {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { BrowserPostureProofSchema, DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS, POSTURE_PROOF_TYPE, verifyBrowserPostureProof };
|
|
63
|
+
//# sourceMappingURL=browser-posture-proof.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-proof.mjs","names":["z.object","z.string","z.number"],"sources":["../src/browser-posture-proof.ts"],"sourcesContent":["import { calculateJwkThumbprint, importJWK, jwtVerify, type JWK } from 'jose';\nimport { z } from 'zod';\nimport type { BrowserPosture } from './browser-posture';\n\n/**\n * RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture\n * token to a non-extractable key the page holds, so the posture token's\n * TTL stops being the whole replay window. The literal RFC 9449 `typ`\n * value, not a project-specific string like the posture token's own\n * `checkpoint-posture+jwt` - adopting the registered value buys real\n * interoperability with any existing DPoP-aware tooling for no cost.\n */\nexport const POSTURE_PROOF_TYPE = 'dpop+jwt';\n/** Half the posture TTL: a per-request, single-use artifact needs a much\n * tighter freshness window than a session-scoped token. A caller-supplied\n * parameter, not a private constant - this must never repeat\n * `POSTURE_TTL_SECONDS`'s own hardcoding mistake. */\nexport const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;\n\nexport const BrowserPostureProofSchema = z.object({\n jti: z.string().min(1).max(255),\n htm: z.string().min(1).max(16),\n htu: z.string().url(),\n iat: z.number().int().nonnegative(),\n});\nexport type BrowserPostureProof = z.infer<typeof BrowserPostureProofSchema>;\n\n/**\n * Verifies a DPoP-shaped proof (RFC 9449) against an ALREADY-VERIFIED\n * `BrowserPosture` (call `verifyBrowserPosture` first). Checks, in order:\n * the proof's own header shape (`typ`, `alg`, embedded `jwk`); that the\n * embedded key's RFC 7638 thumbprint matches `posture.cnf.jkt`; the\n * proof's ES256 signature against that same embedded key; `htm`/`htu`\n * against the real request; `iat` freshness. Returns `undefined` on ANY\n * failure, including when `posture.cnf` is absent (no binding to check\n * against), never throws.\n *\n * Does NOT check `jti` replay: that needs a store this library does not\n * own. The caller checks the returned proof's `jti` against their own\n * replay store as the final step before trusting the request.\n */\nexport async function verifyBrowserPostureProof(\n proofJws: string | undefined,\n posture: BrowserPosture,\n request: { method: string; url: string },\n now = Math.floor(Date.now() / 1000),\n maxAgeSeconds = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS\n): Promise<BrowserPostureProof | undefined> {\n if (!proofJws || proofJws.length > 2000 || !posture.cnf) return undefined;\n try {\n // `proofJws` is already a non-empty, length-bounded string (checked\n // above), so `split('.')[0]` always yields a string, never `undefined`\n // - no `?? ''` fallback to dead-code around.\n const decoded = JSON.parse(\n Buffer.from(proofJws.split('.')[0], 'base64url').toString('utf8')\n ) as { typ?: string; alg?: string; jwk?: JWK };\n if (\n decoded.typ !== POSTURE_PROOF_TYPE ||\n decoded.alg !== 'ES256' ||\n !decoded.jwk ||\n decoded.jwk.kty !== 'EC' ||\n decoded.jwk.crv !== 'P-256' ||\n decoded.jwk.d\n )\n return undefined;\n const thumbprint = await calculateJwkThumbprint(decoded.jwk, 'sha256');\n if (thumbprint !== posture.cnf.jkt) return undefined;\n const key = await importJWK(decoded.jwk, 'ES256');\n const { payload } = await jwtVerify(proofJws, key, {\n algorithms: ['ES256'],\n typ: POSTURE_PROOF_TYPE,\n currentDate: new Date(now * 1000),\n });\n const parsed = BrowserPostureProofSchema.safeParse(payload);\n if (!parsed.success) return undefined;\n const claims = parsed.data;\n if (\n claims.htm.toUpperCase() !== request.method.toUpperCase() ||\n claims.htu !== request.url ||\n Math.abs(now - claims.iat) > maxAgeSeconds\n )\n return undefined;\n return claims;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,qBAAqB;;;;;AAKlC,MAAa,wCAAwC;AAErD,MAAa,4BAA4BA,OAAS;CAChD,KAAKC,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC9B,KAAKA,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;CAC7B,KAAKA,OAAS,CAAC,CAAC,IAAI;CACpB,KAAKC,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY;AACpC,CAAC;;;;;;;;;;;;;;;AAiBD,eAAsB,0BACpB,UACA,SACA,SACA,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,GAClC,oBAC0C;CAC1C,IAAI,CAAC,YAAY,SAAS,SAAS,OAAQ,CAAC,QAAQ,KAAK,OAAO;CAChE,IAAI;EAIF,MAAM,UAAU,KAAK,MACnB,OAAO,KAAK,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,SAAS,MAAM,CAClE;EACA,IACE,QAAQ,sBACR,QAAQ,QAAQ,WAChB,CAAC,QAAQ,OACT,QAAQ,IAAI,QAAQ,QACpB,QAAQ,IAAI,QAAQ,WACpB,QAAQ,IAAI,GAEZ,OAAO;EAET,IAAI,MADqB,uBAAuB,QAAQ,KAAK,QAAQ,MAClD,QAAQ,IAAI,KAAK,OAAO;EAC3C,MAAM,MAAM,MAAM,UAAU,QAAQ,KAAK,OAAO;EAChD,MAAM,EAAE,YAAY,MAAM,UAAU,UAAU,KAAK;GACjD,YAAY,CAAC,OAAO;GACpB,KAAK;GACL,6BAAa,IAAI,KAAK,MAAM,GAAI;EAClC,CAAC;EACD,MAAM,SAAS,0BAA0B,UAAU,OAAO;EAC1D,IAAI,CAAC,OAAO,SAAS,OAAO;EAC5B,MAAM,SAAS,OAAO;EACtB,IACE,OAAO,IAAI,YAAY,MAAM,QAAQ,OAAO,YAAY,KACxD,OAAO,QAAQ,QAAQ,OACvB,KAAK,IAAI,MAAM,OAAO,GAAG,IAAI,eAE7B,OAAO;EACT,OAAO;CACT,QAAQ;EACN;CACF;AACF"}
|