@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,2 +1,2 @@
1
- import{z as e}from"zod";const t=e.object({projectId:e.string().min(1).max(128),sessionId:e.guid(),verdict:e.enum([`human`,`agent-driven`,`insufficient`]),score:e.number().min(0).max(1).nullable(),scorerVersion:e.number().int().positive(),reasons:e.array(e.string().max(160)).max(8),issuedAt:e.number().int().nonnegative(),expiresAt:e.number().int().positive(),source:e.literal(`verified-posture`)});function n(e){return{projectId:e.project_id,sessionId:e.session_id,verdict:e.verdict,score:e.score,scorerVersion:e.scorer_version,reasons:e.reasons,issuedAt:e.iat,expiresAt:e.exp,source:`verified-posture`}}export{t as BrowserPostureReportSchema,n as browserPostureReport};
1
+ import{z as e}from"zod";const t=[`verified`,`absent`,`rejected`],n=e.object({projectId:e.string().min(1).max(128),sessionId:e.guid(),verdict:e.enum([`human`,`agent-driven`,`insufficient`]),score:e.number().min(0).max(1).nullable(),scorerVersion:e.number().int().positive(),reasons:e.array(e.string().max(160)).max(8),issuedAt:e.number().int().nonnegative(),expiresAt:e.number().int().positive(),source:e.literal(`verified-posture`)}),r=[`malformed`,`unknown-key`,`bad-signature`,`invalid-claims`,`project-mismatch`,`origin-mismatch`,`audience-mismatch`,`expired`,`not-yet-valid`,`binding-mismatch`,`session-missing`],i=e.object({status:e.enum(t),reason:e.enum(r).optional()}).refine(e=>e.status===`rejected`==(e.reason!==void 0),{message:`reason is required if and only if status is rejected`,path:[`reason`]}),a=/^[a-z][a-z-]{0,31}$/,o=50,s=1e6,c=e.record(e.string(),e.unknown()).transform(e=>Object.fromEntries(Object.entries(e).filter(e=>a.test(e[0])&&typeof e[1]==`number`&&Number.isInteger(e[1])&&e[1]>0).slice(0,50).map(([e,t])=>[e,Math.min(t,s)]))),l=n.extend({score:n.shape.score.default(null)});function u(e){return{projectId:e.project_id,sessionId:e.session_id,verdict:e.verdict,score:e.score,scorerVersion:e.scorer_version,reasons:e.reasons,issuedAt:e.iat,expiresAt:e.exp,source:`verified-posture`}}export{a as BROWSER_POSTURE_REASON_PATTERN,o as BROWSER_POSTURE_REJECTIONS_MAX_ENTRIES,s as BROWSER_POSTURE_REJECTION_COUNT_MAX,r as BROWSER_POSTURE_REJECTION_REASONS,i as BrowserPostureOutcomeSchema,c as BrowserPostureRejectionsSchema,l as BrowserPostureReportIngestSchema,n as BrowserPostureReportSchema,t as POSTURE_VERIFICATION_STATUSES,u as browserPostureReport};
2
2
  //# sourceMappingURL=browser-posture-report.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-report.mjs","names":[],"sources":["../src/browser-posture-report.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { BrowserPosture } from './browser-posture';\n\n/** Audit projection: no token, cookie binding, raw counters, or credential fields. */\nexport const BrowserPostureReportSchema = z.object({\n projectId: z.string().min(1).max(128),\n // Match the signed posture's MD5-derived consolidated session IDs.\n sessionId: z.guid(),\n verdict: z.enum(['human', 'agent-driven', 'insufficient']),\n score: z.number().min(0).max(1).nullable(),\n scorerVersion: z.number().int().positive(),\n reasons: z.array(z.string().max(160)).max(8),\n issuedAt: z.number().int().nonnegative(),\n expiresAt: z.number().int().positive(),\n source: z.literal('verified-posture'),\n});\nexport function browserPostureReport(posture: BrowserPosture) {\n return {\n projectId: posture.project_id,\n sessionId: posture.session_id,\n verdict: posture.verdict,\n score: posture.score,\n scorerVersion: posture.scorer_version,\n reasons: posture.reasons,\n issuedAt: posture.iat,\n expiresAt: posture.exp,\n source: 'verified-posture' as const,\n };\n}\n"],"mappings":"wBAIA,MAAa,EAA6B,EAAE,OAAO,CACjD,UAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,EAEpC,UAAW,EAAE,KAAK,EAClB,QAAS,EAAE,KAAK,CAAC,QAAS,eAAgB,cAAc,CAAC,EACzD,MAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EACzC,cAAe,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EACzC,QAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAC3C,SAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EACvC,UAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EACrC,OAAQ,EAAE,QAAQ,kBAAkB,CACtC,CAAC,EACD,SAAgB,EAAqB,EAAyB,CAC5D,MAAO,CACL,UAAW,EAAQ,WACnB,UAAW,EAAQ,WACnB,QAAS,EAAQ,QACjB,MAAO,EAAQ,MACf,cAAe,EAAQ,eACvB,QAAS,EAAQ,QACjB,SAAU,EAAQ,IAClB,UAAW,EAAQ,IACnB,OAAQ,kBACV,CACF"}
1
+ {"version":3,"file":"browser-posture-report.mjs","names":[],"sources":["../src/browser-posture-report.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { BrowserPosture } from './browser-posture-schema';\n\nexport const POSTURE_VERIFICATION_STATUSES = ['verified', 'absent', 'rejected'] as const;\nexport type PostureVerificationStatus = (typeof POSTURE_VERIFICATION_STATUSES)[number];\n\n/** Audit projection: no token, cookie binding, raw counters, or credential fields. */\nexport const BrowserPostureReportSchema = z.object({\n projectId: z.string().min(1).max(128),\n // Match the signed posture's MD5-derived consolidated session IDs.\n sessionId: z.guid(),\n verdict: z.enum(['human', 'agent-driven', 'insufficient']),\n score: z.number().min(0).max(1).nullable(),\n scorerVersion: z.number().int().positive(),\n reasons: z.array(z.string().max(160)).max(8),\n issuedAt: z.number().int().nonnegative(),\n expiresAt: z.number().int().positive(),\n source: z.literal('verified-posture'),\n});\n\nexport const BROWSER_POSTURE_REJECTION_REASONS = [\n 'malformed',\n 'unknown-key',\n 'bad-signature',\n 'invalid-claims',\n 'project-mismatch',\n 'origin-mismatch',\n 'audience-mismatch',\n 'expired',\n 'not-yet-valid',\n 'binding-mismatch',\n 'session-missing',\n] as const;\nexport type BrowserPostureRejectionReason = (typeof BROWSER_POSTURE_REJECTION_REASONS)[number];\n\nexport const BrowserPostureOutcomeSchema = z\n .object({\n status: z.enum(POSTURE_VERIFICATION_STATUSES),\n reason: z.enum(BROWSER_POSTURE_REJECTION_REASONS).optional(),\n })\n .refine((outcome) => (outcome.status === 'rejected') === (outcome.reason !== undefined), {\n message: 'reason is required if and only if status is rejected',\n path: ['reason'],\n });\nexport type BrowserPostureOutcome = z.infer<typeof BrowserPostureOutcomeSchema>;\n\nexport const BROWSER_POSTURE_REASON_PATTERN = /^[a-z][a-z-]{0,31}$/;\nexport const BROWSER_POSTURE_REJECTIONS_MAX_ENTRIES = 50;\nexport const BROWSER_POSTURE_REJECTION_COUNT_MAX = 1_000_000;\n\nexport const BrowserPostureRejectionsSchema = z\n .record(z.string(), z.unknown())\n .transform((counts) =>\n Object.fromEntries(\n Object.entries(counts)\n .filter(\n (entry): entry is [string, number] =>\n BROWSER_POSTURE_REASON_PATTERN.test(entry[0]) &&\n typeof entry[1] === 'number' &&\n Number.isInteger(entry[1]) &&\n entry[1] > 0\n )\n .slice(0, BROWSER_POSTURE_REJECTIONS_MAX_ENTRIES)\n .map(([reason, count]): [string, number] => [\n reason,\n Math.min(count, BROWSER_POSTURE_REJECTION_COUNT_MAX),\n ])\n )\n );\nexport type BrowserPostureRejections = z.infer<typeof BrowserPostureRejectionsSchema>;\n\nexport const BrowserPostureReportIngestSchema = BrowserPostureReportSchema.extend({\n score: BrowserPostureReportSchema.shape.score.default(null),\n});\n\nexport function browserPostureReport(posture: BrowserPosture) {\n return {\n projectId: posture.project_id,\n sessionId: posture.session_id,\n verdict: posture.verdict,\n score: posture.score,\n scorerVersion: posture.scorer_version,\n reasons: posture.reasons,\n issuedAt: posture.iat,\n expiresAt: posture.exp,\n source: 'verified-posture' as const,\n };\n}\n"],"mappings":"wBAGA,MAAa,EAAgC,CAAC,WAAY,SAAU,UAAU,EAIjE,EAA6B,EAAE,OAAO,CACjD,UAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,EAEpC,UAAW,EAAE,KAAK,EAClB,QAAS,EAAE,KAAK,CAAC,QAAS,eAAgB,cAAc,CAAC,EACzD,MAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EACzC,cAAe,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EACzC,QAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAC3C,SAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EACvC,UAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EACrC,OAAQ,EAAE,QAAQ,kBAAkB,CACtC,CAAC,EAEY,EAAoC,CAC/C,YACA,cACA,gBACA,iBACA,mBACA,kBACA,oBACA,UACA,gBACA,mBACA,iBACF,EAGa,EAA8B,EACxC,OAAO,CACN,OAAQ,EAAE,KAAK,CAA6B,EAC5C,OAAQ,EAAE,KAAK,CAAiC,CAAC,CAAC,SAAS,CAC7D,CAAC,CAAC,CACD,OAAQ,GAAa,EAAQ,SAAW,aAAiB,EAAQ,SAAW,IAAA,IAAY,CACvF,QAAS,uDACT,KAAM,CAAC,QAAQ,CACjB,CAAC,EAGU,EAAiC,sBACjC,EAAyC,GACzC,EAAsC,IAEtC,EAAiC,EAC3C,OAAO,EAAE,OAAO,EAAG,EAAE,QAAQ,CAAC,CAAC,CAC/B,UAAW,GACV,OAAO,YACL,OAAO,QAAQ,CAAM,CAAC,CACnB,OACE,GACC,EAA+B,KAAK,EAAM,EAAE,GAC5C,OAAO,EAAM,IAAO,UACpB,OAAO,UAAU,EAAM,EAAE,GACzB,EAAM,GAAK,CACf,CAAC,CACA,MAAM,EAAA,EAAyC,CAAC,CAChD,KAAK,CAAC,EAAQ,KAA6B,CAC1C,EACA,KAAK,IAAI,EAAO,CAAmC,CACrD,CAAC,CACL,CACF,EAGW,EAAmC,EAA2B,OAAO,CAChF,MAAO,EAA2B,MAAM,MAAM,QAAQ,IAAI,CAC5D,CAAC,EAED,SAAgB,EAAqB,EAAyB,CAC5D,MAAO,CACL,UAAW,EAAQ,WACnB,UAAW,EAAQ,WACnB,QAAS,EAAQ,QACjB,MAAO,EAAQ,MACf,cAAe,EAAQ,eACvB,QAAS,EAAQ,QACjB,SAAU,EAAQ,IAClB,UAAW,EAAQ,IACnB,OAAQ,kBACV,CACF"}
@@ -1,85 +1,2 @@
1
- import { C as ZodObject, O as ZodString, P as output, R as $strip, S as ZodNumber, b as ZodLiteral, g as ZodGUID, h as ZodEnum, l as ZodArray, p as ZodDefault, t as external_d_exports, u as ZodBoolean, x as ZodNullable } from "./external-jr_S4iSS.mjs";
2
- import { JWK, JWK as JWK$1 } from "jose";
3
- //#region src/browser-posture-cookie.d.ts
4
- export declare function postureCookieName(projectId: string): string;
5
- //#endregion
6
- //#region src/beacon-types/index.d.ts
7
- export declare const POSTURE_TTL_SECONDS = 120;
8
- //#endregion
9
- //#region src/browser-posture-report.d.ts
10
- export declare const BrowserPostureReportSchema: ZodObject<{
11
- projectId: ZodString;
12
- sessionId: ZodGUID;
13
- verdict: ZodEnum<{
14
- "agent-driven": "agent-driven";
15
- human: "human";
16
- insufficient: "insufficient";
17
- }>;
18
- score: ZodNullable<ZodNumber>;
19
- scorerVersion: ZodNumber;
20
- reasons: ZodArray<ZodString>;
21
- issuedAt: ZodNumber;
22
- expiresAt: ZodNumber;
23
- source: ZodLiteral<"verified-posture">;
24
- }, $strip>;
25
- export declare function browserPostureReport(posture: BrowserPosture): {
26
- projectId: string;
27
- sessionId: string;
28
- verdict: "agent-driven" | "human" | "insufficient";
29
- score: number | null;
30
- scorerVersion: number;
31
- reasons: string[];
32
- issuedAt: number;
33
- expiresAt: number;
34
- source: "verified-posture";
35
- };
36
- //#endregion
37
- //#region src/browser-posture.d.ts
38
- export declare const UNSIGNED_BROWSER_AGENT: {
39
- readonly agentType: "Browser agent (unsigned)";
40
- readonly detectionClass: "ai_agent";
41
- readonly verificationMethod: "behavioral";
42
- };
43
- export declare const behavioralConfidence: (score: number | null) => number;
44
- export declare const POSTURE_ISSUER = "checkpoint:browser-posture:v1";
45
- export declare const POSTURE_TYPE = "checkpoint-posture+jwt";
46
- export declare const BrowserPostureSchema: ZodObject<{
47
- v: ZodLiteral<1>;
48
- project_id: ZodString;
49
- origin: ZodString;
50
- session_id: ZodGUID;
51
- binding: ZodString;
52
- verdict: ZodEnum<{
53
- "agent-driven": "agent-driven";
54
- human: "human";
55
- insufficient: "insufficient";
56
- }>;
57
- score: ZodNullable<ZodNumber>;
58
- scorer_version: ZodNumber;
59
- reasons: ZodArray<ZodString>;
60
- automation_disclosed: ZodDefault<ZodBoolean>;
61
- automation_corroborated: ZodDefault<ZodBoolean>;
62
- iat: ZodNumber;
63
- exp: ZodNumber;
64
- }, $strip>;
65
- export type BrowserPosture = output<typeof BrowserPostureSchema>;
66
- export interface BrowserPostureConfig {
67
- publicKey: JWK$1;
68
- keyId: string;
69
- origin: string;
70
- sessionCookieName?: string;
71
- protectedRoutes?: Array<{
72
- path: string;
73
- scopes: string[];
74
- }>;
75
- }
76
- export declare function readPostureCookie(header: string | null | undefined, name: string): string | undefined;
77
- export declare function postureSessionBinding(sessionId: string): Promise<string>;
78
- export declare function signBrowserPosture(posture: BrowserPosture, privateKey: JWK$1, keyId: string): Promise<string>;
79
- export declare function verifyBrowserPosture(token: string | undefined, config: BrowserPostureConfig, projectId: string, browserSessionId: string | undefined, now?: number): Promise<BrowserPosture | undefined>;
80
- export declare function postureFromCookies(header: string | null | undefined, config: BrowserPostureConfig, projectId: string): Promise<BrowserPosture | undefined>;
81
- export declare function postureRequiredScopes(config: BrowserPostureConfig, path: string): string[] | undefined;
82
- export declare function validateBrowserPostureConfig(config: BrowserPostureConfig, projectId: string | undefined): void;
83
- //#endregion
84
- export type { JWK };
85
- //# sourceMappingURL=browser-posture.d.mts.map
1
+ import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-DVoHMHjY.mjs";
2
+ export { BROWSER_POSTURE_REJECTION_REASONS, type BrowserPosture, BrowserPostureConfig, type BrowserPostureOutcome, BrowserPostureOutcomeSchema, type BrowserPostureRejectionReason, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, type JWK, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, PostureRequest, PostureVerification, type PostureVerificationStatus, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
@@ -1,85 +1,2 @@
1
- import { C as ZodObject, O as ZodString, P as output, R as $strip, S as ZodNumber, b as ZodLiteral, g as ZodGUID, h as ZodEnum, l as ZodArray, p as ZodDefault, t as external_d_exports, u as ZodBoolean, x as ZodNullable } from "./external-jr_S4iSS.js";
2
- import { JWK, JWK as JWK$1 } from "jose";
3
- //#region src/browser-posture-cookie.d.ts
4
- export declare function postureCookieName(projectId: string): string;
5
- //#endregion
6
- //#region src/beacon-types/index.d.ts
7
- export declare const POSTURE_TTL_SECONDS = 120;
8
- //#endregion
9
- //#region src/browser-posture-report.d.ts
10
- export declare const BrowserPostureReportSchema: ZodObject<{
11
- projectId: ZodString;
12
- sessionId: ZodGUID;
13
- verdict: ZodEnum<{
14
- "agent-driven": "agent-driven";
15
- human: "human";
16
- insufficient: "insufficient";
17
- }>;
18
- score: ZodNullable<ZodNumber>;
19
- scorerVersion: ZodNumber;
20
- reasons: ZodArray<ZodString>;
21
- issuedAt: ZodNumber;
22
- expiresAt: ZodNumber;
23
- source: ZodLiteral<"verified-posture">;
24
- }, $strip>;
25
- export declare function browserPostureReport(posture: BrowserPosture): {
26
- projectId: string;
27
- sessionId: string;
28
- verdict: "agent-driven" | "human" | "insufficient";
29
- score: number | null;
30
- scorerVersion: number;
31
- reasons: string[];
32
- issuedAt: number;
33
- expiresAt: number;
34
- source: "verified-posture";
35
- };
36
- //#endregion
37
- //#region src/browser-posture.d.ts
38
- export declare const UNSIGNED_BROWSER_AGENT: {
39
- readonly agentType: "Browser agent (unsigned)";
40
- readonly detectionClass: "ai_agent";
41
- readonly verificationMethod: "behavioral";
42
- };
43
- export declare const behavioralConfidence: (score: number | null) => number;
44
- export declare const POSTURE_ISSUER = "checkpoint:browser-posture:v1";
45
- export declare const POSTURE_TYPE = "checkpoint-posture+jwt";
46
- export declare const BrowserPostureSchema: ZodObject<{
47
- v: ZodLiteral<1>;
48
- project_id: ZodString;
49
- origin: ZodString;
50
- session_id: ZodGUID;
51
- binding: ZodString;
52
- verdict: ZodEnum<{
53
- "agent-driven": "agent-driven";
54
- human: "human";
55
- insufficient: "insufficient";
56
- }>;
57
- score: ZodNullable<ZodNumber>;
58
- scorer_version: ZodNumber;
59
- reasons: ZodArray<ZodString>;
60
- automation_disclosed: ZodDefault<ZodBoolean>;
61
- automation_corroborated: ZodDefault<ZodBoolean>;
62
- iat: ZodNumber;
63
- exp: ZodNumber;
64
- }, $strip>;
65
- export type BrowserPosture = output<typeof BrowserPostureSchema>;
66
- export interface BrowserPostureConfig {
67
- publicKey: JWK$1;
68
- keyId: string;
69
- origin: string;
70
- sessionCookieName?: string;
71
- protectedRoutes?: Array<{
72
- path: string;
73
- scopes: string[];
74
- }>;
75
- }
76
- export declare function readPostureCookie(header: string | null | undefined, name: string): string | undefined;
77
- export declare function postureSessionBinding(sessionId: string): Promise<string>;
78
- export declare function signBrowserPosture(posture: BrowserPosture, privateKey: JWK$1, keyId: string): Promise<string>;
79
- export declare function verifyBrowserPosture(token: string | undefined, config: BrowserPostureConfig, projectId: string, browserSessionId: string | undefined, now?: number): Promise<BrowserPosture | undefined>;
80
- export declare function postureFromCookies(header: string | null | undefined, config: BrowserPostureConfig, projectId: string): Promise<BrowserPosture | undefined>;
81
- export declare function postureRequiredScopes(config: BrowserPostureConfig, path: string): string[] | undefined;
82
- export declare function validateBrowserPostureConfig(config: BrowserPostureConfig, projectId: string | undefined): void;
83
- //#endregion
84
- export type { JWK };
85
- //# sourceMappingURL=browser-posture.d.ts.map
1
+ import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-D4j2a5gi.js";
2
+ export { BROWSER_POSTURE_REJECTION_REASONS, type BrowserPosture, BrowserPostureConfig, type BrowserPostureOutcome, BrowserPostureOutcomeSchema, type BrowserPostureRejectionReason, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, type JWK, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, PostureRequest, PostureVerification, type PostureVerificationStatus, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_schemas = require('./schemas-BmjNLAE7.js');
3
- const require_patterns = require('./patterns-CkRVOdtV.js');
3
+ const require_posture_origins = require('./posture-origins-CEm83u4D.js');
4
4
  const require_project_verification_key = require('./project-verification-key-C3L5rd8a.js');
5
5
  let jose = require("jose");
6
6
 
@@ -17,7 +17,7 @@ let jose = require("jose");
17
17
  * reader will look for.
18
18
  */
19
19
  function postureCookieName(projectId) {
20
- if (!require_patterns.UUID_PATTERN.test(projectId) || projectId !== projectId.toLowerCase()) throw new Error("Invalid posture project id");
20
+ if (!require_posture_origins.UUID_PATTERN.test(projectId) || projectId !== projectId.toLowerCase()) throw new Error("Invalid posture project id");
21
21
  return `__Host-checkpoint_posture_${projectId}`;
22
22
  }
23
23
 
@@ -30,8 +30,41 @@ function postureCookieName(projectId) {
30
30
  */
31
31
  const POSTURE_TTL_SECONDS = 120;
32
32
 
33
+ //#endregion
34
+ //#region src/browser-posture-schema.ts
35
+ const BrowserPostureSchema = require_schemas.object({
36
+ v: require_schemas.literal(1),
37
+ project_id: require_schemas.string().min(1).max(128),
38
+ origin: require_schemas.string().url(),
39
+ session_id: require_schemas.guid(),
40
+ binding: require_schemas.string().regex(/^[a-f0-9]{64}$/),
41
+ verdict: require_schemas._enum([
42
+ "agent-driven",
43
+ "human",
44
+ "insufficient"
45
+ ]),
46
+ score: require_schemas.number().min(0).max(1).nullable(),
47
+ scorer_version: require_schemas.number().int().positive().max(2147483647),
48
+ reasons: require_schemas.array(require_schemas.string().max(160)).max(8),
49
+ automation_disclosed: require_schemas.boolean().default(false),
50
+ automation_corroborated: require_schemas.boolean().default(false),
51
+ detection: require_schemas.object({
52
+ class: require_schemas._enum(["ai_agent", "bot"]),
53
+ name: require_schemas.string().min(1).max(64).regex(/^[^\p{Cc}]+$/u),
54
+ confidence: require_schemas.number().int().min(0).max(100)
55
+ }).optional(),
56
+ cnf: require_schemas.object({ jkt: require_schemas.string().min(1).max(255) }).optional(),
57
+ iat: require_schemas.number().int().nonnegative(),
58
+ exp: require_schemas.number().int().positive()
59
+ });
60
+
33
61
  //#endregion
34
62
  //#region src/browser-posture-report.ts
63
+ const POSTURE_VERIFICATION_STATUSES = [
64
+ "verified",
65
+ "absent",
66
+ "rejected"
67
+ ];
35
68
  /** Audit projection: no token, cookie binding, raw counters, or credential fields. */
36
69
  const BrowserPostureReportSchema = require_schemas.object({
37
70
  projectId: require_schemas.string().min(1).max(128),
@@ -48,6 +81,31 @@ const BrowserPostureReportSchema = require_schemas.object({
48
81
  expiresAt: require_schemas.number().int().positive(),
49
82
  source: require_schemas.literal("verified-posture")
50
83
  });
84
+ const BROWSER_POSTURE_REJECTION_REASONS = [
85
+ "malformed",
86
+ "unknown-key",
87
+ "bad-signature",
88
+ "invalid-claims",
89
+ "project-mismatch",
90
+ "origin-mismatch",
91
+ "audience-mismatch",
92
+ "expired",
93
+ "not-yet-valid",
94
+ "binding-mismatch",
95
+ "session-missing"
96
+ ];
97
+ const BrowserPostureOutcomeSchema = require_schemas.object({
98
+ status: require_schemas._enum(POSTURE_VERIFICATION_STATUSES),
99
+ reason: require_schemas._enum(BROWSER_POSTURE_REJECTION_REASONS).optional()
100
+ }).refine((outcome) => outcome.status === "rejected" === (outcome.reason !== void 0), {
101
+ message: "reason is required if and only if status is rejected",
102
+ path: ["reason"]
103
+ });
104
+ const BROWSER_POSTURE_REASON_PATTERN = /^[a-z][a-z-]{0,31}$/;
105
+ const BROWSER_POSTURE_REJECTIONS_MAX_ENTRIES = 50;
106
+ const BROWSER_POSTURE_REJECTION_COUNT_MAX = 1e6;
107
+ const BrowserPostureRejectionsSchema = require_schemas.record(require_schemas.string(), require_schemas.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)])));
108
+ const BrowserPostureReportIngestSchema = BrowserPostureReportSchema.extend({ score: BrowserPostureReportSchema.shape.score.default(null) });
51
109
  function browserPostureReport(posture) {
52
110
  return {
53
111
  projectId: posture.project_id,
@@ -70,27 +128,43 @@ const UNSIGNED_BROWSER_AGENT = {
70
128
  verificationMethod: "behavioral"
71
129
  };
72
130
  const behavioralConfidence = (score) => Math.min(85, Math.max(50, Math.round((score ?? .5) * 100)));
131
+ function postureUpgrade(posture) {
132
+ const { detection, reasons } = posture;
133
+ const verificationMethod = "behavioral";
134
+ if (detection) return {
135
+ detectionClass: detection.class,
136
+ isAgent: true,
137
+ agentName: detection.name,
138
+ confidence: detection.confidence,
139
+ verificationMethod,
140
+ reasons
141
+ };
142
+ if (posture.automation_disclosed) return {
143
+ detectionClass: "bot",
144
+ isAgent: true,
145
+ agentName: "Automation Tools",
146
+ confidence: 80,
147
+ verificationMethod,
148
+ reasons
149
+ };
150
+ if (posture.verdict === "agent-driven") return {
151
+ detectionClass: UNSIGNED_BROWSER_AGENT.detectionClass,
152
+ isAgent: true,
153
+ agentName: UNSIGNED_BROWSER_AGENT.agentType,
154
+ confidence: behavioralConfidence(posture.score),
155
+ verificationMethod,
156
+ reasons
157
+ };
158
+ if (posture.automation_corroborated) return {
159
+ detectionClass: "incomplete_data",
160
+ isAgent: false,
161
+ confidence: 40,
162
+ verificationMethod,
163
+ reasons
164
+ };
165
+ }
73
166
  const POSTURE_ISSUER = "checkpoint:browser-posture:v1";
74
167
  const POSTURE_TYPE = "checkpoint-posture+jwt";
75
- const BrowserPostureSchema = require_schemas.object({
76
- v: require_schemas.literal(1),
77
- project_id: require_schemas.string().min(1).max(128),
78
- origin: require_schemas.string().url(),
79
- session_id: require_schemas.guid(),
80
- binding: require_schemas.string().regex(/^[a-f0-9]{64}$/),
81
- verdict: require_schemas._enum([
82
- "agent-driven",
83
- "human",
84
- "insufficient"
85
- ]),
86
- score: require_schemas.number().min(0).max(1).nullable(),
87
- scorer_version: require_schemas.number().int().positive().max(2147483647),
88
- reasons: require_schemas.array(require_schemas.string().max(160)).max(8),
89
- automation_disclosed: require_schemas.boolean().default(false),
90
- automation_corroborated: require_schemas.boolean().default(false),
91
- iat: require_schemas.number().int().nonnegative(),
92
- exp: require_schemas.number().int().positive()
93
- });
94
168
  /** Duplicate cookies are ambiguous, so none is trusted. */
95
169
  function readPostureCookie(header, name) {
96
170
  const matches = (header ?? "").split(";").map((s) => s.trim()).filter((s) => s.startsWith(`${name}=`));
@@ -108,7 +182,7 @@ async function postureSessionBinding(sessionId) {
108
182
  function validOrigin(origin) {
109
183
  try {
110
184
  const url = new URL(origin);
111
- return url.protocol === "https:" && url.origin === origin;
185
+ return url.protocol === "https:" && url.origin === origin && /^[^.*][^*]*$/.test(url.hostname);
112
186
  } catch {
113
187
  return false;
114
188
  }
@@ -123,31 +197,101 @@ async function signBrowserPosture(posture, privateKey, keyId) {
123
197
  kid: keyId
124
198
  }).setIssuer(POSTURE_ISSUER).setAudience(claims.origin).sign(key);
125
199
  }
126
- async function verifyBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
127
- 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;
200
+ const BASE64URL = /^[A-Za-z0-9_-]+$/;
201
+ const rejected = (reason) => ({
202
+ status: "rejected",
203
+ reason
204
+ });
205
+ const postureOutcomeReport = (outcome) => outcome.status === "verified" ? { status: "verified" } : outcome;
206
+ const verifiedPosture = (outcome) => outcome.status === "verified" ? outcome.posture : void 0;
207
+ async function inspectBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
208
+ if (!token) return { status: "absent" };
209
+ if (!browserSessionId || browserSessionId.length > 255) return rejected("session-missing");
210
+ const parts = token.split(".");
211
+ if (token.length > 3800 || parts.length !== 3 || !parts.every((part) => BASE64URL.test(part)) || parts[0].length % 4 === 1) return rejected("malformed");
212
+ let header;
128
213
  try {
129
- const publicKey = require_project_verification_key.projectVerificationKey(token, config, now);
130
- if (!publicKey) return void 0;
131
- const key = await (0, jose.importJWK)(publicKey, "ES256");
132
- const { payload, protectedHeader } = await (0, jose.jwtVerify)(token, key, {
133
- algorithms: ["ES256"],
134
- issuer: POSTURE_ISSUER,
135
- audience: config.origin,
136
- typ: POSTURE_TYPE,
137
- currentDate: /* @__PURE__ */ new Date(now * 1e3)
138
- });
139
- if ("crit" in protectedHeader || "b64" in protectedHeader || Array.isArray(payload.aud) && payload.aud.some((audience) => typeof audience !== "string")) return void 0;
140
- const parsed = BrowserPostureSchema.safeParse(payload);
141
- if (!parsed.success) return void 0;
142
- const claims = parsed.data;
143
- 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;
144
- return claims;
214
+ header = (0, jose.decodeProtectedHeader)(token);
145
215
  } catch {
146
- return;
216
+ return rejected("malformed");
147
217
  }
218
+ if (header.alg !== "ES256" || header.typ !== "checkpoint-posture+jwt" || typeof header.kid !== "string" || "crit" in header || "b64" in header) return rejected("malformed");
219
+ const publicKey = validOrigin(config.origin) && !config.publicKey.d && config.publicKey.kty === "EC" && config.publicKey.crv === "P-256" ? require_project_verification_key.projectVerificationKey(token, config, now) : void 0;
220
+ const key = publicKey && await (0, jose.importJWK)(publicKey, "ES256").catch(() => void 0);
221
+ if (!key) return rejected("unknown-key");
222
+ let signed;
223
+ try {
224
+ signed = await (0, jose.compactVerify)(token, key, { algorithms: ["ES256"] });
225
+ } catch {
226
+ return rejected("bad-signature");
227
+ }
228
+ let json;
229
+ try {
230
+ json = JSON.parse(new TextDecoder().decode(signed.payload));
231
+ } catch {
232
+ return rejected("malformed");
233
+ }
234
+ const record$1 = require_schemas.record(require_schemas.string(), require_schemas.unknown()).safeParse(json);
235
+ if (!record$1.success) return rejected("invalid-claims");
236
+ const audiences = [record$1.data.aud].flat();
237
+ if (audiences.some((audience) => typeof audience !== "string")) return rejected("malformed");
238
+ const notBefore = record$1.data.nbf;
239
+ const parsed = BrowserPostureSchema.safeParse(record$1.data);
240
+ 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");
241
+ const claims = parsed.data;
242
+ if (claims.project_id !== projectId) return rejected("project-mismatch");
243
+ if (claims.origin !== config.origin && !require_posture_origins.matchAllowedOrigin(claims.origin, config.origins ?? [])) return rejected("origin-mismatch");
244
+ if (!audiences.includes(claims.origin)) return rejected("audience-mismatch");
245
+ if (claims.exp <= now) return rejected("expired");
246
+ if (claims.iat > now + 5 || notBefore !== void 0 && notBefore > now) return rejected("not-yet-valid");
247
+ if (claims.exp <= claims.iat || claims.exp - claims.iat > 120) return rejected("invalid-claims");
248
+ if (claims.binding !== await postureSessionBinding(browserSessionId)) return rejected("binding-mismatch");
249
+ return {
250
+ status: "verified",
251
+ posture: claims
252
+ };
253
+ }
254
+ async function verifyBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
255
+ return verifiedPosture(await inspectBrowserPosture(token, config, projectId, browserSessionId, now));
256
+ }
257
+ /**
258
+ * Request headers a page sends when its posture cookies cannot reach the
259
+ * server: a request to another host (the cookies are host-only) or a browser
260
+ * that blocks cookies. The page reads both values from the beacon's
261
+ * `onReceipt`.
262
+ */
263
+ const POSTURE_HEADER = "kya-posture";
264
+ const POSTURE_SESSION_HEADER = "kya-posture-session";
265
+ /** The `PostureRequest` of any header store, read through its own lowercase-name getter. */
266
+ function postureRequestFromHeaders(get) {
267
+ const cookie = get("cookie");
268
+ return {
269
+ cookie: Array.isArray(cookie) ? cookie.join("; ") : cookie,
270
+ posture: get(POSTURE_HEADER),
271
+ session: get(POSTURE_SESSION_HEADER)
272
+ };
273
+ }
274
+ /**
275
+ * A header, when the request carries a non-empty one, wins over its cookie.
276
+ * A header sent twice, or joined into one comma-separated value, is ambiguous,
277
+ * so neither copy is trusted and the cookie is not consulted either: the page
278
+ * chose the header. Every runtime applies the same rule
279
+ * (`tests/browser-posture/vectors.json` `requests`).
280
+ */
281
+ function postureRequestValue(header, cookieHeader, cookieName) {
282
+ const values = (Array.isArray(header) ? header : [header]).map((value) => value?.trim()).filter((value) => Boolean(value));
283
+ if (values.length === 0) return readPostureCookie(cookieHeader, cookieName);
284
+ return values.length === 1 && !values[0].includes(",") ? values[0] : void 0;
285
+ }
286
+ /** Read and verify posture from the `KYA-Posture` headers, falling back to the cookies. */
287
+ async function postureOutcomeFromRequest(request, config, projectId, now) {
288
+ return inspectBrowserPosture(postureRequestValue(request.posture, request.cookie, postureCookieName(projectId)), config, projectId, postureRequestValue(request.session, request.cookie, config.sessionCookieName ?? "_as_beacon_session"), now);
289
+ }
290
+ async function postureFromRequest(request, config, projectId, now) {
291
+ return verifiedPosture(await postureOutcomeFromRequest(request, config, projectId, now));
148
292
  }
149
293
  async function postureFromCookies(header, config, projectId) {
150
- return verifyBrowserPosture(readPostureCookie(header, postureCookieName(projectId)), config, projectId, readPostureCookie(header, config.sessionCookieName ?? "_as_beacon_session"));
294
+ return postureFromRequest({ cookie: header }, config, projectId);
151
295
  }
152
296
  /** Exact paths or an explicit subtree ending in /*. Longest designation wins. */
153
297
  function postureRequiredScopes(config, path) {
@@ -158,8 +302,14 @@ function postureRequiredScopes(config, path) {
158
302
  }
159
303
  /** Validate operator configuration at startup, before any request can depend on it. */
160
304
  function validateBrowserPostureConfig(config, projectId) {
161
- if (!projectId || !require_patterns.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)");
305
+ if (!projectId || !require_posture_origins.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)");
162
306
  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");
307
+ const origins = config.origins ?? [];
308
+ if (origins.length > 20) throw new Error(`Browser posture accepts at most ${20} additional origins`);
309
+ for (const entry of origins) {
310
+ const parsed = require_posture_origins.parseOriginPattern(entry);
311
+ if (!parsed.ok) throw new Error(`Invalid browser posture origin "${entry}": ${parsed.error}`);
312
+ }
163
313
  const paths = /* @__PURE__ */ new Set();
164
314
  for (const route of config.protectedRoutes ?? []) {
165
315
  if (!/^\/(?:[^?#*\\]*)(?:\/\*)?$/.test(route.path) && route.path !== "/*") throw new Error("Invalid integrity-protected path");
@@ -173,18 +323,30 @@ function validateBrowserPostureConfig(config, projectId) {
173
323
  }
174
324
 
175
325
  //#endregion
326
+ exports.BROWSER_POSTURE_REJECTION_REASONS = BROWSER_POSTURE_REJECTION_REASONS;
327
+ exports.BrowserPostureOutcomeSchema = BrowserPostureOutcomeSchema;
328
+ exports.BrowserPostureReportIngestSchema = BrowserPostureReportIngestSchema;
176
329
  exports.BrowserPostureReportSchema = BrowserPostureReportSchema;
177
330
  exports.BrowserPostureSchema = BrowserPostureSchema;
331
+ exports.POSTURE_HEADER = POSTURE_HEADER;
178
332
  exports.POSTURE_ISSUER = POSTURE_ISSUER;
333
+ exports.POSTURE_SESSION_HEADER = POSTURE_SESSION_HEADER;
179
334
  exports.POSTURE_TTL_SECONDS = POSTURE_TTL_SECONDS;
180
335
  exports.POSTURE_TYPE = POSTURE_TYPE;
336
+ exports.POSTURE_VERIFICATION_STATUSES = POSTURE_VERIFICATION_STATUSES;
181
337
  exports.UNSIGNED_BROWSER_AGENT = UNSIGNED_BROWSER_AGENT;
182
338
  exports.behavioralConfidence = behavioralConfidence;
183
339
  exports.browserPostureReport = browserPostureReport;
340
+ exports.inspectBrowserPosture = inspectBrowserPosture;
184
341
  exports.postureCookieName = postureCookieName;
185
342
  exports.postureFromCookies = postureFromCookies;
343
+ exports.postureFromRequest = postureFromRequest;
344
+ exports.postureOutcomeFromRequest = postureOutcomeFromRequest;
345
+ exports.postureOutcomeReport = postureOutcomeReport;
346
+ exports.postureRequestFromHeaders = postureRequestFromHeaders;
186
347
  exports.postureRequiredScopes = postureRequiredScopes;
187
348
  exports.postureSessionBinding = postureSessionBinding;
349
+ exports.postureUpgrade = postureUpgrade;
188
350
  exports.readPostureCookie = readPostureCookie;
189
351
  exports.signBrowserPosture = signBrowserPosture;
190
352
  exports.validateBrowserPostureConfig = validateBrowserPostureConfig;