@kya-os/checkpoint-shared 1.5.1 → 1.5.2

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.
Files changed (141) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/dist/beacon-nonce/index.d.mts +36 -0
  3. package/dist/beacon-nonce/index.d.mts.map +1 -0
  4. package/dist/beacon-nonce/index.d.ts +36 -0
  5. package/dist/beacon-nonce/index.d.ts.map +1 -0
  6. package/dist/beacon-nonce/index.js +305 -0
  7. package/dist/beacon-nonce/index.mjs +294 -0
  8. package/dist/beacon-nonce/index.mjs.map +1 -0
  9. package/dist/beacon-types/index.d.mts +29 -0
  10. package/dist/beacon-types/index.d.mts.map +1 -1
  11. package/dist/beacon-types/index.d.ts +29 -0
  12. package/dist/beacon-types/index.d.ts.map +1 -1
  13. package/dist/beacon-types/index.js +36 -5
  14. package/dist/beacon-types/index.mjs +33 -6
  15. package/dist/beacon-types/index.mjs.map +1 -1
  16. package/dist/browser-posture-D4j2a5gi.d.ts +169 -0
  17. package/dist/browser-posture-D4j2a5gi.d.ts.map +1 -0
  18. package/dist/browser-posture-DVoHMHjY.d.mts +169 -0
  19. package/dist/browser-posture-DVoHMHjY.d.mts.map +1 -0
  20. package/dist/browser-posture-cookie.d.mts +4 -2
  21. package/dist/browser-posture-cookie.d.mts.map +1 -0
  22. package/dist/browser-posture-cookie.d.ts +4 -2
  23. package/dist/browser-posture-cookie.d.ts.map +1 -0
  24. package/dist/browser-posture-cookie.mjs.map +1 -1
  25. package/dist/browser-posture-proof.d.mts +18 -0
  26. package/dist/browser-posture-proof.d.mts.map +1 -0
  27. package/dist/browser-posture-proof.d.ts +18 -0
  28. package/dist/browser-posture-proof.d.ts.map +1 -0
  29. package/dist/browser-posture-proof.js +66 -0
  30. package/dist/browser-posture-proof.mjs +63 -0
  31. package/dist/browser-posture-proof.mjs.map +1 -0
  32. package/dist/browser-posture-report.d.mts +59 -2
  33. package/dist/browser-posture-report.d.mts.map +1 -1
  34. package/dist/browser-posture-report.d.ts +59 -2
  35. package/dist/browser-posture-report.d.ts.map +1 -1
  36. package/dist/browser-posture-report.js +1 -1
  37. package/dist/browser-posture-report.mjs +1 -1
  38. package/dist/browser-posture-report.mjs.map +1 -1
  39. package/dist/browser-posture.d.mts +2 -85
  40. package/dist/browser-posture.d.ts +2 -85
  41. package/dist/browser-posture.js +205 -43
  42. package/dist/browser-posture.mjs +194 -44
  43. package/dist/browser-posture.mjs.map +1 -1
  44. package/dist/browser.d.mts +0 -8
  45. package/dist/browser.d.mts.map +1 -1
  46. package/dist/browser.d.ts +0 -8
  47. package/dist/browser.d.ts.map +1 -1
  48. package/dist/browser.js +1 -1
  49. package/dist/browser.mjs +1 -1
  50. package/dist/browser.mjs.map +1 -1
  51. package/dist/clearance.d.mts +1 -1
  52. package/dist/clearance.d.ts +1 -1
  53. package/dist/{client-ip-HOfe6ucV.mjs → client-ip-B2Xeo-GK.mjs} +2 -2
  54. package/dist/{client-ip-HOfe6ucV.mjs.map → client-ip-B2Xeo-GK.mjs.map} +1 -1
  55. package/dist/{client-ip-1y2iXAYW.js → client-ip-CW6pRyLf.js} +1 -1
  56. package/dist/consent-handoff.d.mts +41 -0
  57. package/dist/consent-handoff.d.mts.map +1 -0
  58. package/dist/consent-handoff.d.ts +41 -0
  59. package/dist/consent-handoff.d.ts.map +1 -0
  60. package/dist/consent-handoff.js +1 -0
  61. package/dist/consent-handoff.mjs +2 -0
  62. package/dist/consent-handoff.mjs.map +1 -0
  63. package/dist/errors/index.d.mts +138 -0
  64. package/dist/errors/index.d.mts.map +1 -1
  65. package/dist/errors/index.d.ts +138 -0
  66. package/dist/errors/index.d.ts.map +1 -1
  67. package/dist/errors/index.js +441 -9
  68. package/dist/errors/index.mjs +441 -10
  69. package/dist/errors/index.mjs.map +1 -1
  70. package/dist/{external-jr_S4iSS.d.mts → external-Ct8j_hto.d.mts} +2 -2
  71. package/dist/{external-jr_S4iSS.d.mts.map → external-Ct8j_hto.d.mts.map} +1 -1
  72. package/dist/{external-jr_S4iSS.d.ts → external-Ct8j_hto.d.ts} +2 -2
  73. package/dist/{external-jr_S4iSS.d.ts.map → external-Ct8j_hto.d.ts.map} +1 -1
  74. package/dist/gateway-client-ip.d.mts +1 -1
  75. package/dist/gateway-client-ip.d.ts +1 -1
  76. package/dist/gateway-client-ip.js +1 -1
  77. package/dist/gateway-client-ip.mjs +1 -1
  78. package/dist/index.d.mts +5131 -967
  79. package/dist/index.d.mts.map +1 -1
  80. package/dist/index.d.ts +5131 -967
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +3678 -546
  83. package/dist/index.mjs +3446 -534
  84. package/dist/index.mjs.map +1 -1
  85. package/dist/mcpi/approval-grant/index.d.mts +1 -1
  86. package/dist/mcpi/approval-grant/index.d.mts.map +1 -1
  87. package/dist/mcpi/approval-grant/index.d.ts +1 -1
  88. package/dist/mcpi/approval-grant/index.d.ts.map +1 -1
  89. package/dist/mcpi/approval-grant/index.js +48 -48
  90. package/dist/mcpi/approval-grant/index.mjs +48 -48
  91. package/dist/mcpi/approval-grant/index.mjs.map +1 -1
  92. package/dist/posture-origins/index.d.mts +41 -0
  93. package/dist/posture-origins/index.d.mts.map +1 -0
  94. package/dist/posture-origins/index.d.ts +41 -0
  95. package/dist/posture-origins/index.d.ts.map +1 -0
  96. package/dist/posture-origins/index.js +441 -0
  97. package/dist/posture-origins/index.mjs +430 -0
  98. package/dist/posture-origins/index.mjs.map +1 -0
  99. package/dist/posture-origins-CEm83u4D.js +621 -0
  100. package/dist/posture-origins-Dl7i8j93.mjs +533 -0
  101. package/dist/posture-origins-Dl7i8j93.mjs.map +1 -0
  102. package/dist/rules.json +0 -1
  103. package/dist/signals/index.d.mts +75 -55
  104. package/dist/signals/index.d.mts.map +1 -1
  105. package/dist/signals/index.d.ts +75 -55
  106. package/dist/signals/index.d.ts.map +1 -1
  107. package/dist/signals/index.js +246 -2
  108. package/dist/signals/index.mjs +236 -3
  109. package/dist/signals/index.mjs.map +1 -1
  110. package/fixtures/browser-integrity/captured-java-0.2.1-missing-score.json +10 -0
  111. package/fixtures/browser-integrity/null-score.json +11 -0
  112. package/fixtures/browser-integrity/numeric-score.json +11 -0
  113. package/fixtures/browser-posture-claims.json +168 -0
  114. package/fixtures/browser-posture-headers.json +6 -0
  115. package/fixtures/kya-http/README.md +1 -0
  116. package/fixtures/kya-http/consent-handoff.codes.json +34 -0
  117. package/fixtures/workbench/a2a-signed-request.v1.json +255 -0
  118. package/fixtures/workbench/artifact-bindings.v1.json +1003 -0
  119. package/fixtures/workbench/delegation-management.v1.json +507 -0
  120. package/fixtures/workbench/didcomm-task-source.v1.json +191 -0
  121. package/fixtures/workbench/graph-interfaces.v1.json +1887 -0
  122. package/fixtures/workbench/identity-provisioning.v1.json +643 -0
  123. package/fixtures/workbench/linear-installation.v1.json +484 -0
  124. package/fixtures/workbench/management-session.v1.json +716 -0
  125. package/fixtures/workbench/model-credentials.v1.json +630 -0
  126. package/fixtures/workbench/source-claim-pooled.v1.json +50 -0
  127. package/fixtures/workbench/task-grant.v1.json +695 -0
  128. package/fixtures/workbench/task-status-projection.v1.json +591 -0
  129. package/fixtures/workbench/workload-enrollment.v1.json +580 -0
  130. package/package.json +21 -2
  131. package/src/data/compiled/merged-rules.json +2 -9
  132. package/src/data/default-rules.json +0 -1
  133. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +0 -5
  134. package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +0 -1
  135. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +0 -5
  136. package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +0 -1
  137. package/dist/browser-posture.d.mts.map +0 -1
  138. package/dist/browser-posture.d.ts.map +0 -1
  139. package/dist/patterns-CkRVOdtV.js +0 -243
  140. package/dist/patterns-DzkGy_qk.mjs +0 -173
  141. package/dist/patterns-DzkGy_qk.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
- import { _ as number, c as boolean, f as guid, h as literal, i as _enum, s as array, v as object, x as string } from "./schemas-DxY-dk9y.mjs";
2
- import { c as VALIDATION_PATTERNS, s as UUID_PATTERN } from "./patterns-DzkGy_qk.mjs";
1
+ import { C as unknown, _ as number, b as record, c as boolean, f as guid, h as literal, i as _enum, s as array, v as object, x as string } from "./schemas-DxY-dk9y.mjs";
2
+ import { d as VALIDATION_PATTERNS, n as parseOriginPattern, t as matchAllowedOrigin, u as UUID_PATTERN } from "./posture-origins-Dl7i8j93.mjs";
3
3
  import { t as projectVerificationKey } from "./project-verification-key-CgSVX9_m.mjs";
4
- import { SignJWT, importJWK, jwtVerify } from "jose";
4
+ import { SignJWT, compactVerify, decodeProtectedHeader, importJWK } from "jose";
5
5
 
6
6
  //#region src/browser-posture-cookie.ts
7
7
  /**
@@ -29,8 +29,41 @@ function postureCookieName(projectId) {
29
29
  */
30
30
  const POSTURE_TTL_SECONDS = 120;
31
31
 
32
+ //#endregion
33
+ //#region src/browser-posture-schema.ts
34
+ const BrowserPostureSchema = object({
35
+ v: literal(1),
36
+ project_id: string().min(1).max(128),
37
+ origin: string().url(),
38
+ session_id: guid(),
39
+ binding: string().regex(/^[a-f0-9]{64}$/),
40
+ verdict: _enum([
41
+ "agent-driven",
42
+ "human",
43
+ "insufficient"
44
+ ]),
45
+ score: number().min(0).max(1).nullable(),
46
+ scorer_version: number().int().positive().max(2147483647),
47
+ reasons: array(string().max(160)).max(8),
48
+ automation_disclosed: boolean().default(false),
49
+ automation_corroborated: boolean().default(false),
50
+ detection: object({
51
+ class: _enum(["ai_agent", "bot"]),
52
+ name: string().min(1).max(64).regex(/^[^\p{Cc}]+$/u),
53
+ confidence: number().int().min(0).max(100)
54
+ }).optional(),
55
+ cnf: object({ jkt: string().min(1).max(255) }).optional(),
56
+ iat: number().int().nonnegative(),
57
+ exp: number().int().positive()
58
+ });
59
+
32
60
  //#endregion
33
61
  //#region src/browser-posture-report.ts
62
+ const POSTURE_VERIFICATION_STATUSES = [
63
+ "verified",
64
+ "absent",
65
+ "rejected"
66
+ ];
34
67
  /** Audit projection: no token, cookie binding, raw counters, or credential fields. */
35
68
  const BrowserPostureReportSchema = object({
36
69
  projectId: string().min(1).max(128),
@@ -47,6 +80,31 @@ const BrowserPostureReportSchema = object({
47
80
  expiresAt: number().int().positive(),
48
81
  source: literal("verified-posture")
49
82
  });
83
+ const BROWSER_POSTURE_REJECTION_REASONS = [
84
+ "malformed",
85
+ "unknown-key",
86
+ "bad-signature",
87
+ "invalid-claims",
88
+ "project-mismatch",
89
+ "origin-mismatch",
90
+ "audience-mismatch",
91
+ "expired",
92
+ "not-yet-valid",
93
+ "binding-mismatch",
94
+ "session-missing"
95
+ ];
96
+ const BrowserPostureOutcomeSchema = object({
97
+ status: _enum(POSTURE_VERIFICATION_STATUSES),
98
+ reason: _enum(BROWSER_POSTURE_REJECTION_REASONS).optional()
99
+ }).refine((outcome) => outcome.status === "rejected" === (outcome.reason !== void 0), {
100
+ message: "reason is required if and only if status is rejected",
101
+ path: ["reason"]
102
+ });
103
+ const BROWSER_POSTURE_REASON_PATTERN = /^[a-z][a-z-]{0,31}$/;
104
+ const BROWSER_POSTURE_REJECTIONS_MAX_ENTRIES = 50;
105
+ const BROWSER_POSTURE_REJECTION_COUNT_MAX = 1e6;
106
+ const BrowserPostureRejectionsSchema = record(string(), unknown()).transform((counts) => Object.fromEntries(Object.entries(counts).filter((entry) => BROWSER_POSTURE_REASON_PATTERN.test(entry[0]) && typeof entry[1] === "number" && Number.isInteger(entry[1]) && entry[1] > 0).slice(0, 50).map(([reason, count]) => [reason, Math.min(count, BROWSER_POSTURE_REJECTION_COUNT_MAX)])));
107
+ const BrowserPostureReportIngestSchema = BrowserPostureReportSchema.extend({ score: BrowserPostureReportSchema.shape.score.default(null) });
50
108
  function browserPostureReport(posture) {
51
109
  return {
52
110
  projectId: posture.project_id,
@@ -69,27 +127,43 @@ const UNSIGNED_BROWSER_AGENT = {
69
127
  verificationMethod: "behavioral"
70
128
  };
71
129
  const behavioralConfidence = (score) => Math.min(85, Math.max(50, Math.round((score ?? .5) * 100)));
130
+ function postureUpgrade(posture) {
131
+ const { detection, reasons } = posture;
132
+ const verificationMethod = "behavioral";
133
+ if (detection) return {
134
+ detectionClass: detection.class,
135
+ isAgent: true,
136
+ agentName: detection.name,
137
+ confidence: detection.confidence,
138
+ verificationMethod,
139
+ reasons
140
+ };
141
+ if (posture.automation_disclosed) return {
142
+ detectionClass: "bot",
143
+ isAgent: true,
144
+ agentName: "Automation Tools",
145
+ confidence: 80,
146
+ verificationMethod,
147
+ reasons
148
+ };
149
+ if (posture.verdict === "agent-driven") return {
150
+ detectionClass: UNSIGNED_BROWSER_AGENT.detectionClass,
151
+ isAgent: true,
152
+ agentName: UNSIGNED_BROWSER_AGENT.agentType,
153
+ confidence: behavioralConfidence(posture.score),
154
+ verificationMethod,
155
+ reasons
156
+ };
157
+ if (posture.automation_corroborated) return {
158
+ detectionClass: "incomplete_data",
159
+ isAgent: false,
160
+ confidence: 40,
161
+ verificationMethod,
162
+ reasons
163
+ };
164
+ }
72
165
  const POSTURE_ISSUER = "checkpoint:browser-posture:v1";
73
166
  const POSTURE_TYPE = "checkpoint-posture+jwt";
74
- const BrowserPostureSchema = object({
75
- v: literal(1),
76
- project_id: string().min(1).max(128),
77
- origin: string().url(),
78
- session_id: guid(),
79
- binding: string().regex(/^[a-f0-9]{64}$/),
80
- verdict: _enum([
81
- "agent-driven",
82
- "human",
83
- "insufficient"
84
- ]),
85
- score: number().min(0).max(1).nullable(),
86
- scorer_version: number().int().positive().max(2147483647),
87
- reasons: array(string().max(160)).max(8),
88
- automation_disclosed: boolean().default(false),
89
- automation_corroborated: boolean().default(false),
90
- iat: number().int().nonnegative(),
91
- exp: number().int().positive()
92
- });
93
167
  /** Duplicate cookies are ambiguous, so none is trusted. */
94
168
  function readPostureCookie(header, name) {
95
169
  const matches = (header ?? "").split(";").map((s) => s.trim()).filter((s) => s.startsWith(`${name}=`));
@@ -107,7 +181,7 @@ async function postureSessionBinding(sessionId) {
107
181
  function validOrigin(origin) {
108
182
  try {
109
183
  const url = new URL(origin);
110
- return url.protocol === "https:" && url.origin === origin;
184
+ return url.protocol === "https:" && url.origin === origin && /^[^.*][^*]*$/.test(url.hostname);
111
185
  } catch {
112
186
  return false;
113
187
  }
@@ -122,31 +196,101 @@ async function signBrowserPosture(posture, privateKey, keyId) {
122
196
  kid: keyId
123
197
  }).setIssuer(POSTURE_ISSUER).setAudience(claims.origin).sign(key);
124
198
  }
125
- async function verifyBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
126
- if (!token || token.length > 3800 || !browserSessionId || browserSessionId.length > 255 || !validOrigin(config.origin) || config.publicKey.d || config.publicKey.kty !== "EC" || config.publicKey.crv !== "P-256") return void 0;
199
+ const BASE64URL = /^[A-Za-z0-9_-]+$/;
200
+ const rejected = (reason) => ({
201
+ status: "rejected",
202
+ reason
203
+ });
204
+ const postureOutcomeReport = (outcome) => outcome.status === "verified" ? { status: "verified" } : outcome;
205
+ const verifiedPosture = (outcome) => outcome.status === "verified" ? outcome.posture : void 0;
206
+ async function inspectBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
207
+ if (!token) return { status: "absent" };
208
+ if (!browserSessionId || browserSessionId.length > 255) return rejected("session-missing");
209
+ const parts = token.split(".");
210
+ if (token.length > 3800 || parts.length !== 3 || !parts.every((part) => BASE64URL.test(part)) || parts[0].length % 4 === 1) return rejected("malformed");
211
+ let header;
127
212
  try {
128
- const publicKey = projectVerificationKey(token, config, now);
129
- if (!publicKey) return void 0;
130
- const key = await importJWK(publicKey, "ES256");
131
- const { payload, protectedHeader } = await jwtVerify(token, key, {
132
- algorithms: ["ES256"],
133
- issuer: POSTURE_ISSUER,
134
- audience: config.origin,
135
- typ: POSTURE_TYPE,
136
- currentDate: /* @__PURE__ */ new Date(now * 1e3)
137
- });
138
- if ("crit" in protectedHeader || "b64" in protectedHeader || Array.isArray(payload.aud) && payload.aud.some((audience) => typeof audience !== "string")) return void 0;
139
- const parsed = BrowserPostureSchema.safeParse(payload);
140
- if (!parsed.success) return void 0;
141
- const claims = parsed.data;
142
- if (claims.project_id !== projectId || claims.origin !== config.origin || claims.iat > now + 5 || claims.exp <= now || claims.exp <= claims.iat || claims.exp - claims.iat > 120 || claims.binding !== await postureSessionBinding(browserSessionId)) return void 0;
143
- return claims;
213
+ header = decodeProtectedHeader(token);
144
214
  } catch {
145
- return;
215
+ return rejected("malformed");
146
216
  }
217
+ if (header.alg !== "ES256" || header.typ !== "checkpoint-posture+jwt" || typeof header.kid !== "string" || "crit" in header || "b64" in header) return rejected("malformed");
218
+ const publicKey = validOrigin(config.origin) && !config.publicKey.d && config.publicKey.kty === "EC" && config.publicKey.crv === "P-256" ? projectVerificationKey(token, config, now) : void 0;
219
+ const key = publicKey && await importJWK(publicKey, "ES256").catch(() => void 0);
220
+ if (!key) return rejected("unknown-key");
221
+ let signed;
222
+ try {
223
+ signed = await compactVerify(token, key, { algorithms: ["ES256"] });
224
+ } catch {
225
+ return rejected("bad-signature");
226
+ }
227
+ let json;
228
+ try {
229
+ json = JSON.parse(new TextDecoder().decode(signed.payload));
230
+ } catch {
231
+ return rejected("malformed");
232
+ }
233
+ const record$1 = record(string(), unknown()).safeParse(json);
234
+ if (!record$1.success) return rejected("invalid-claims");
235
+ const audiences = [record$1.data.aud].flat();
236
+ if (audiences.some((audience) => typeof audience !== "string")) return rejected("malformed");
237
+ const notBefore = record$1.data.nbf;
238
+ const parsed = BrowserPostureSchema.safeParse(record$1.data);
239
+ if (!parsed.success || record$1.data.iss !== "checkpoint:browser-posture:v1" || notBefore !== void 0 && typeof notBefore !== "number" || record$1.data.origin !== parsed.data.origin || !validOrigin(parsed.data.origin)) return rejected("invalid-claims");
240
+ const claims = parsed.data;
241
+ if (claims.project_id !== projectId) return rejected("project-mismatch");
242
+ if (claims.origin !== config.origin && !matchAllowedOrigin(claims.origin, config.origins ?? [])) return rejected("origin-mismatch");
243
+ if (!audiences.includes(claims.origin)) return rejected("audience-mismatch");
244
+ if (claims.exp <= now) return rejected("expired");
245
+ if (claims.iat > now + 5 || notBefore !== void 0 && notBefore > now) return rejected("not-yet-valid");
246
+ if (claims.exp <= claims.iat || claims.exp - claims.iat > 120) return rejected("invalid-claims");
247
+ if (claims.binding !== await postureSessionBinding(browserSessionId)) return rejected("binding-mismatch");
248
+ return {
249
+ status: "verified",
250
+ posture: claims
251
+ };
252
+ }
253
+ async function verifyBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
254
+ return verifiedPosture(await inspectBrowserPosture(token, config, projectId, browserSessionId, now));
255
+ }
256
+ /**
257
+ * Request headers a page sends when its posture cookies cannot reach the
258
+ * server: a request to another host (the cookies are host-only) or a browser
259
+ * that blocks cookies. The page reads both values from the beacon's
260
+ * `onReceipt`.
261
+ */
262
+ const POSTURE_HEADER = "kya-posture";
263
+ const POSTURE_SESSION_HEADER = "kya-posture-session";
264
+ /** The `PostureRequest` of any header store, read through its own lowercase-name getter. */
265
+ function postureRequestFromHeaders(get) {
266
+ const cookie = get("cookie");
267
+ return {
268
+ cookie: Array.isArray(cookie) ? cookie.join("; ") : cookie,
269
+ posture: get(POSTURE_HEADER),
270
+ session: get(POSTURE_SESSION_HEADER)
271
+ };
272
+ }
273
+ /**
274
+ * A header, when the request carries a non-empty one, wins over its cookie.
275
+ * A header sent twice, or joined into one comma-separated value, is ambiguous,
276
+ * so neither copy is trusted and the cookie is not consulted either: the page
277
+ * chose the header. Every runtime applies the same rule
278
+ * (`tests/browser-posture/vectors.json` `requests`).
279
+ */
280
+ function postureRequestValue(header, cookieHeader, cookieName) {
281
+ const values = (Array.isArray(header) ? header : [header]).map((value) => value?.trim()).filter((value) => Boolean(value));
282
+ if (values.length === 0) return readPostureCookie(cookieHeader, cookieName);
283
+ return values.length === 1 && !values[0].includes(",") ? values[0] : void 0;
284
+ }
285
+ /** Read and verify posture from the `KYA-Posture` headers, falling back to the cookies. */
286
+ async function postureOutcomeFromRequest(request, config, projectId, now) {
287
+ return inspectBrowserPosture(postureRequestValue(request.posture, request.cookie, postureCookieName(projectId)), config, projectId, postureRequestValue(request.session, request.cookie, config.sessionCookieName ?? "_as_beacon_session"), now);
288
+ }
289
+ async function postureFromRequest(request, config, projectId, now) {
290
+ return verifiedPosture(await postureOutcomeFromRequest(request, config, projectId, now));
147
291
  }
148
292
  async function postureFromCookies(header, config, projectId) {
149
- return verifyBrowserPosture(readPostureCookie(header, postureCookieName(projectId)), config, projectId, readPostureCookie(header, config.sessionCookieName ?? "_as_beacon_session"));
293
+ return postureFromRequest({ cookie: header }, config, projectId);
150
294
  }
151
295
  /** Exact paths or an explicit subtree ending in /*. Longest designation wins. */
152
296
  function postureRequiredScopes(config, path) {
@@ -159,6 +303,12 @@ function postureRequiredScopes(config, path) {
159
303
  function validateBrowserPostureConfig(config, projectId) {
160
304
  if (!projectId || !VALIDATION_PATTERNS.UUID.test(projectId) || projectId !== projectId.toLowerCase()) throw new Error("Browser posture requires projectId to be the lowercase project UUID (the friendly id is not accepted)");
161
305
  if (!validOrigin(config.origin) || !config.keyId || config.publicKey.kty !== "EC" || config.publicKey.crv !== "P-256" || !config.publicKey.x || !config.publicKey.y || config.publicKey.d) throw new Error("Browser posture requires projectId, an exact HTTPS origin, and a public ES256 key");
306
+ const origins = config.origins ?? [];
307
+ if (origins.length > 20) throw new Error(`Browser posture accepts at most ${20} additional origins`);
308
+ for (const entry of origins) {
309
+ const parsed = parseOriginPattern(entry);
310
+ if (!parsed.ok) throw new Error(`Invalid browser posture origin "${entry}": ${parsed.error}`);
311
+ }
162
312
  const paths = /* @__PURE__ */ new Set();
163
313
  for (const route of config.protectedRoutes ?? []) {
164
314
  if (!/^\/(?:[^?#*\\]*)(?:\/\*)?$/.test(route.path) && route.path !== "/*") throw new Error("Invalid integrity-protected path");
@@ -172,5 +322,5 @@ function validateBrowserPostureConfig(config, projectId) {
172
322
  }
173
323
 
174
324
  //#endregion
175
- export { BrowserPostureReportSchema, BrowserPostureSchema, POSTURE_ISSUER, POSTURE_TTL_SECONDS, POSTURE_TYPE, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, postureCookieName, postureFromCookies, postureRequiredScopes, postureSessionBinding, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
325
+ export { BROWSER_POSTURE_REJECTION_REASONS, BrowserPostureOutcomeSchema, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
176
326
  //# sourceMappingURL=browser-posture.mjs.map