@kya-os/checkpoint-shared 1.8.0 → 1.10.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.
Files changed (155) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +1 -1
  3. package/dist/agent-catalog.d.mts +12 -0
  4. package/dist/agent-catalog.d.mts.map +1 -0
  5. package/dist/agent-catalog.d.ts +12 -0
  6. package/dist/agent-catalog.d.ts.map +1 -0
  7. package/dist/agent-catalog.js +105 -0
  8. package/dist/agent-catalog.mjs +105 -0
  9. package/dist/agent-catalog.mjs.map +1 -0
  10. package/dist/beacon-types/index.d.mts +18 -0
  11. package/dist/beacon-types/index.d.mts.map +1 -1
  12. package/dist/beacon-types/index.d.ts +18 -0
  13. package/dist/beacon-types/index.d.ts.map +1 -1
  14. package/dist/beacon-types/index.js +116 -12
  15. package/dist/beacon-types/index.mjs +105 -13
  16. package/dist/beacon-types/index.mjs.map +1 -1
  17. package/dist/browser-posture-5fPrsxx7.d.mts.map +1 -1
  18. package/dist/browser-posture-CCR1kh5e.d.ts.map +1 -1
  19. package/dist/browser-posture-cookie.js +1 -1
  20. package/dist/browser-posture-cookie.mjs +1 -1
  21. package/dist/browser-posture-cookie.mjs.map +1 -1
  22. package/dist/browser-posture-proof-verifier-DvsOmFrM.js +202 -0
  23. package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs +180 -0
  24. package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs.map +1 -0
  25. package/dist/browser-posture-proof-verifier.d.mts +25 -0
  26. package/dist/browser-posture-proof-verifier.d.mts.map +1 -0
  27. package/dist/browser-posture-proof-verifier.d.ts +25 -0
  28. package/dist/browser-posture-proof-verifier.d.ts.map +1 -0
  29. package/dist/browser-posture-proof-verifier.js +7 -0
  30. package/dist/browser-posture-proof-verifier.mjs +3 -0
  31. package/dist/browser-posture-proof.d.mts +3 -18
  32. package/dist/browser-posture-proof.d.mts.map +1 -1
  33. package/dist/browser-posture-proof.d.ts +3 -18
  34. package/dist/browser-posture-proof.d.ts.map +1 -1
  35. package/dist/browser-posture-proof.js +6 -131
  36. package/dist/browser-posture-proof.mjs +1 -126
  37. package/dist/browser-posture-proof.mjs.map +1 -1
  38. package/dist/browser-posture.js +36 -5
  39. package/dist/browser-posture.mjs +36 -5
  40. package/dist/browser-posture.mjs.map +1 -1
  41. package/dist/browser.d.mts +0 -282
  42. package/dist/browser.d.mts.map +1 -1
  43. package/dist/browser.d.ts +0 -282
  44. package/dist/browser.d.ts.map +1 -1
  45. package/dist/browser.js +1 -1
  46. package/dist/browser.mjs +1 -1
  47. package/dist/browser.mjs.map +1 -1
  48. package/dist/canonical-signer/index.mjs.map +1 -1
  49. package/dist/consent-handoff.d.mts +0 -3
  50. package/dist/consent-handoff.d.mts.map +1 -1
  51. package/dist/consent-handoff.d.ts +0 -3
  52. package/dist/consent-handoff.d.ts.map +1 -1
  53. package/dist/consent-handoff.mjs.map +1 -1
  54. package/dist/default-sign-in-host.d.mts +10 -0
  55. package/dist/default-sign-in-host.d.mts.map +1 -0
  56. package/dist/default-sign-in-host.d.ts +10 -0
  57. package/dist/default-sign-in-host.d.ts.map +1 -0
  58. package/dist/default-sign-in-host.js +72 -0
  59. package/dist/default-sign-in-host.mjs +66 -0
  60. package/dist/default-sign-in-host.mjs.map +1 -0
  61. package/dist/deploy/index.d.mts +1 -0
  62. package/dist/deploy/index.d.mts.map +1 -1
  63. package/dist/deploy/index.d.ts +1 -0
  64. package/dist/deploy/index.d.ts.map +1 -1
  65. package/dist/deploy/index.js +9 -1
  66. package/dist/deploy/index.mjs +9 -1
  67. package/dist/deploy/index.mjs.map +1 -1
  68. package/dist/errors/index.d.mts +1 -0
  69. package/dist/errors/index.d.mts.map +1 -1
  70. package/dist/errors/index.d.ts +1 -0
  71. package/dist/errors/index.d.ts.map +1 -1
  72. package/dist/errors/index.js +5 -2
  73. package/dist/errors/index.mjs +5 -2
  74. package/dist/errors/index.mjs.map +1 -1
  75. package/dist/{fetcher-CivUCbhL.d.ts → fetcher-CCw4Q95g.d.ts} +2 -2
  76. package/dist/{fetcher-CivUCbhL.d.ts.map → fetcher-CCw4Q95g.d.ts.map} +1 -1
  77. package/dist/{fetcher-cXQsbm6s.d.mts → fetcher-CZfLcbRZ.d.mts} +2 -2
  78. package/dist/{fetcher-cXQsbm6s.d.mts.map → fetcher-CZfLcbRZ.d.mts.map} +1 -1
  79. package/dist/gateway-client-ip.d.mts +0 -2
  80. package/dist/gateway-client-ip.d.mts.map +1 -1
  81. package/dist/gateway-client-ip.d.ts +0 -2
  82. package/dist/gateway-client-ip.d.ts.map +1 -1
  83. package/dist/gateway-client-ip.mjs.map +1 -1
  84. package/dist/host-adapter/index.d.mts +1 -1
  85. package/dist/host-adapter/index.d.ts +1 -1
  86. package/dist/host-adapter/index.js +1 -1
  87. package/dist/host-adapter/index.mjs +1 -1
  88. package/dist/{host-adapter-DHyISsIf.mjs → host-adapter-BKdQHwbi.mjs} +2 -2
  89. package/dist/{host-adapter-DHyISsIf.mjs.map → host-adapter-BKdQHwbi.mjs.map} +1 -1
  90. package/dist/{host-adapter-0F8EpbD6.js → host-adapter-bWftXA9T.js} +1 -1
  91. package/dist/{index-CXbOY7gB.d.ts → index-Cdv_FH0H.d.ts} +3 -3
  92. package/dist/{index-CXbOY7gB.d.ts.map → index-Cdv_FH0H.d.ts.map} +1 -1
  93. package/dist/{index-B3cHxr3O.d.mts → index-DL_dmQBY.d.mts} +3 -3
  94. package/dist/{index-B3cHxr3O.d.mts.map → index-DL_dmQBY.d.mts.map} +1 -1
  95. package/dist/index.d.mts +124 -463
  96. package/dist/index.d.mts.map +1 -1
  97. package/dist/index.d.ts +124 -463
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +52 -468
  100. package/dist/index.mjs +40 -435
  101. package/dist/index.mjs.map +1 -1
  102. package/dist/{kya-http-error-codes-UYb1zpGM.js → kya-http-error-codes-B4rUmUEI.js} +2 -0
  103. package/dist/{kya-http-error-codes-7ewV5RuK.d.ts → kya-http-error-codes-C14E4gi3.d.mts} +2 -1
  104. package/dist/kya-http-error-codes-C14E4gi3.d.mts.map +1 -0
  105. package/dist/{kya-http-error-codes-7ewV5RuK.d.mts → kya-http-error-codes-C14E4gi3.d.ts} +2 -1
  106. package/dist/kya-http-error-codes-C14E4gi3.d.ts.map +1 -0
  107. package/dist/{kya-http-error-codes-C2JiWPsi.mjs → kya-http-error-codes-DSBrxNry.mjs} +3 -1
  108. package/dist/kya-http-error-codes-DSBrxNry.mjs.map +1 -0
  109. package/dist/kya-http.d.mts +3 -3
  110. package/dist/kya-http.d.ts +3 -3
  111. package/dist/kya-http.js +7 -3
  112. package/dist/kya-http.mjs +3 -3
  113. package/dist/mcpi/dashboard-config/index.d.mts.map +1 -1
  114. package/dist/mcpi/dashboard-config/index.d.ts.map +1 -1
  115. package/dist/mcpi/dashboard-config/index.mjs.map +1 -1
  116. package/dist/{patterns-B2r7M9wR.js → patterns-CiMpbdAF.js} +1 -1
  117. package/dist/{patterns-B7dQoeE3.mjs → patterns-D4OAsNQY.mjs} +2 -2
  118. package/dist/{patterns-B7dQoeE3.mjs.map → patterns-D4OAsNQY.mjs.map} +1 -1
  119. package/dist/patterns.js +1 -1
  120. package/dist/patterns.mjs +1 -1
  121. package/dist/policy/fetcher.d.mts +1 -1
  122. package/dist/policy/fetcher.d.ts +1 -1
  123. package/dist/policy/schemas.d.mts +1 -1
  124. package/dist/policy/schemas.d.ts +1 -1
  125. package/dist/{registered-sid-DVGTSH0L.js → registered-sid-BZfDOfXy.js} +107 -4
  126. package/dist/{registered-sid-26hNxp6t.mjs → registered-sid-CS9V8nPr.mjs} +85 -6
  127. package/dist/registered-sid-CS9V8nPr.mjs.map +1 -0
  128. package/dist/{registered-sid-D6KCaT1E.d.ts → registered-sid-CnWIU_l1.d.mts} +13 -2
  129. package/dist/registered-sid-CnWIU_l1.d.mts.map +1 -0
  130. package/dist/{registered-sid-D6KCaT1E.d.mts → registered-sid-CnWIU_l1.d.ts} +13 -2
  131. package/dist/registered-sid-CnWIU_l1.d.ts.map +1 -0
  132. package/dist/{schemas-02CI7jgm.d.mts → schemas-BhC88D1-.d.mts} +17 -17
  133. package/dist/{schemas-02CI7jgm.d.mts.map → schemas-BhC88D1-.d.mts.map} +1 -1
  134. package/dist/{schemas-C_3C72SR.d.ts → schemas-DZa1ouGs.d.ts} +17 -17
  135. package/dist/{schemas-C_3C72SR.d.ts.map → schemas-DZa1ouGs.d.ts.map} +1 -1
  136. package/dist/signals/index.d.mts.map +1 -1
  137. package/dist/signals/index.d.ts.map +1 -1
  138. package/dist/signals/index.js +4 -0
  139. package/dist/signals/index.mjs +4 -0
  140. package/dist/signals/index.mjs.map +1 -1
  141. package/dist/tool-protection/index.d.mts +12 -0
  142. package/dist/tool-protection/index.d.mts.map +1 -1
  143. package/dist/tool-protection/index.d.ts +12 -0
  144. package/dist/tool-protection/index.d.ts.map +1 -1
  145. package/dist/tool-protection/index.js +46 -0
  146. package/dist/tool-protection/index.mjs +44 -1
  147. package/dist/tool-protection/index.mjs.map +1 -1
  148. package/fixtures/kya-http/error-codes.json +2 -1
  149. package/package.json +19 -3
  150. package/dist/kya-http-error-codes-7ewV5RuK.d.mts.map +0 -1
  151. package/dist/kya-http-error-codes-7ewV5RuK.d.ts.map +0 -1
  152. package/dist/kya-http-error-codes-C2JiWPsi.mjs.map +0 -1
  153. package/dist/registered-sid-26hNxp6t.mjs.map +0 -1
  154. package/dist/registered-sid-D6KCaT1E.d.mts.map +0 -1
  155. package/dist/registered-sid-D6KCaT1E.d.ts.map +0 -1
@@ -1,124 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_schemas = require('./schemas-BlScS1it.js');
3
- let jose = require("jose");
3
+ const require_browser_posture_proof_verifier = require('./browser-posture-proof-verifier-DvsOmFrM.js');
4
4
 
5
- //#region src/utils/base64url.ts
6
- /**
7
- * Base64url (RFC 4648 § 5) built on `atob` and `btoa` rather than Node's
8
- * buffer API, so it runs on every runtime the SDKs support, Cloudflare Workers
9
- * without `nodejs_compat` included.
10
- */
11
- const BASE64URL_UNPADDED = /^[A-Za-z0-9_-]*$/;
12
- const PADDING = 61;
13
- /**
14
- * `text` without its trailing `=` padding. A backward scan, not
15
- * `replace(/=+$/, '')`: that regex retries from every `=` in a long run that
16
- * does not reach the end, which is quadratic on hostile input.
17
- */
18
- function withoutPadding(text) {
19
- let end = text.length;
20
- while (end > 0 && text.charCodeAt(end - 1) === PADDING) end -= 1;
21
- return text.slice(0, end);
22
- }
23
- /**
24
- * Decode base64url, with or without `=` padding.
25
- *
26
- * Strict where Node's buffer decoder is lenient: a character outside the
27
- * alphabet, or a length no encoder produces (one character past a multiple of
28
- * four), throws a `TypeError` instead of being skipped or truncated. This
29
- * matches the engine's decoder.
30
- */
31
- function base64UrlToBytes(text) {
32
- const unpadded = withoutPadding(text);
33
- if (!BASE64URL_UNPADDED.test(unpadded) || unpadded.length % 4 === 1) throw new TypeError("not valid base64url (RFC 4648 § 5)");
34
- const base64 = unpadded.replace(/-/g, "+").replace(/_/g, "/");
35
- const binary = atob(base64 + "=".repeat((4 - base64.length % 4) % 4));
36
- const bytes = new Uint8Array(binary.length);
37
- for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
38
- return bytes;
39
- }
40
- /** Decode base64url to a string as UTF-8, replacing invalid sequences with U+FFFD. */
41
- function base64UrlToString(text) {
42
- return new TextDecoder().decode(base64UrlToBytes(text));
43
- }
44
-
45
- //#endregion
46
5
  //#region src/browser-posture-proof.ts
47
- /**
48
- * RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture
49
- * token to a non-extractable key the page holds, so the posture token's
50
- * TTL stops being the whole replay window. The literal RFC 9449 `typ`
51
- * value, not a project-specific string like the posture token's own
52
- * `checkpoint-posture+jwt` - adopting the registered value buys real
53
- * interoperability with any existing DPoP-aware tooling for no cost.
54
- */
55
- const POSTURE_PROOF_TYPE = "dpop+jwt";
56
- /** Half the posture TTL: a per-request, single-use artifact needs a much
57
- * tighter freshness window than a session-scoped token. A caller-supplied
58
- * parameter, not a private constant - this must never repeat
59
- * `POSTURE_TTL_SECONDS`'s own hardcoding mistake. */
60
- const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
61
6
  const BrowserPostureProofSchema = require_schemas.object({
62
7
  jti: require_schemas.string().min(1).max(255),
63
8
  htm: require_schemas.string().min(1).max(16),
64
9
  htu: require_schemas.string().url(),
65
10
  iat: require_schemas.number().int().nonnegative()
66
11
  });
67
- const MALFORMED = {
68
- verified: false,
69
- reason: "malformed"
70
- };
71
- async function verifyBrowserPostureProofKey(proofJws, request, expectedJkt, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
72
- if (!proofJws || proofJws.length > 2e3) return MALFORMED;
73
- let decoded;
74
- let jkt;
75
- let key;
76
- try {
77
- decoded = JSON.parse(base64UrlToString(proofJws.split(".")[0]));
78
- if (decoded.typ !== "dpop+jwt" || decoded.alg !== "ES256" || !decoded.jwk || decoded.jwk.kty !== "EC" || decoded.jwk.crv !== "P-256" || decoded.jwk.d) return MALFORMED;
79
- jkt = await (0, jose.calculateJwkThumbprint)(decoded.jwk, "sha256");
80
- if (expectedJkt !== void 0 && jkt !== expectedJkt) return {
81
- verified: false,
82
- reason: "jkt-mismatch"
83
- };
84
- key = await (0, jose.importJWK)(decoded.jwk, "ES256");
85
- } catch {
86
- return MALFORMED;
87
- }
88
- let payload;
89
- try {
90
- ({payload} = await (0, jose.jwtVerify)(proofJws, key, {
91
- algorithms: ["ES256"],
92
- typ: POSTURE_PROOF_TYPE,
93
- currentDate: /* @__PURE__ */ new Date(now * 1e3)
94
- }));
95
- } catch {
96
- return {
97
- verified: false,
98
- reason: "bad-signature"
99
- };
100
- }
101
- const parsed = BrowserPostureProofSchema.safeParse(payload);
102
- if (!parsed.success) return {
103
- verified: false,
104
- reason: "invalid-claims"
105
- };
106
- const claims = parsed.data;
107
- const acceptedUrls = typeof request.url === "string" ? [request.url] : request.url;
108
- if (claims.htm.toUpperCase() !== request.method.toUpperCase() || !acceptedUrls.includes(claims.htu)) return {
109
- verified: false,
110
- reason: "htu-mismatch"
111
- };
112
- if (Math.abs(now - claims.iat) > maxAgeSeconds) return {
113
- verified: false,
114
- reason: "stale-iat"
115
- };
116
- return {
117
- verified: true,
118
- claims,
119
- jkt
120
- };
121
- }
122
12
  /**
123
13
  * Verifies a DPoP-shaped proof (RFC 9449) against an ALREADY-VERIFIED
124
14
  * `BrowserPosture` (call `verifyBrowserPosture` first). Checks, in order:
@@ -135,29 +25,14 @@ async function verifyBrowserPostureProofKey(proofJws, request, expectedJkt, now
135
25
  */
136
26
  async function verifyBrowserPostureProof(proofJws, posture, request, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
137
27
  if (!posture.cnf) return void 0;
138
- const result = await verifyBrowserPostureProofKey(proofJws, request, posture.cnf.jkt, now, maxAgeSeconds);
28
+ const result = await require_browser_posture_proof_verifier.verifyBrowserPostureProofKey(proofJws, request, posture.cnf.jkt, now, maxAgeSeconds);
139
29
  return result.verified ? result.claims : void 0;
140
30
  }
141
- async function browserPostureKeyThumbprint(jwk) {
142
- if (typeof jwk !== "object" || jwk === null) return void 0;
143
- const { kty, crv, x, y, d } = jwk;
144
- if (kty !== "EC" || crv !== "P-256" || typeof x !== "string" || typeof y !== "string" || d) return;
145
- try {
146
- return await (0, jose.calculateJwkThumbprint)({
147
- kty,
148
- crv,
149
- x,
150
- y
151
- }, "sha256");
152
- } catch {
153
- return;
154
- }
155
- }
156
31
 
157
32
  //#endregion
158
33
  exports.BrowserPostureProofSchema = BrowserPostureProofSchema;
159
- exports.DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS;
160
- exports.POSTURE_PROOF_TYPE = POSTURE_PROOF_TYPE;
161
- exports.browserPostureKeyThumbprint = browserPostureKeyThumbprint;
34
+ exports.DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = require_browser_posture_proof_verifier.DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS;
35
+ exports.POSTURE_PROOF_TYPE = require_browser_posture_proof_verifier.POSTURE_PROOF_TYPE;
36
+ exports.browserPostureKeyThumbprint = require_browser_posture_proof_verifier.browserPostureKeyThumbprint;
162
37
  exports.verifyBrowserPostureProof = verifyBrowserPostureProof;
163
- exports.verifyBrowserPostureProofKey = verifyBrowserPostureProofKey;
38
+ exports.verifyBrowserPostureProofKey = require_browser_posture_proof_verifier.verifyBrowserPostureProofKey;
@@ -1,123 +1,13 @@
1
1
  import { S as string, _ as number, v as object } from "./schemas-IHAhH3gV.mjs";
2
- import { calculateJwkThumbprint, importJWK, jwtVerify } from "jose";
2
+ import { i as verifyBrowserPostureProofKey, n as POSTURE_PROOF_TYPE, r as browserPostureKeyThumbprint, t as DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS } from "./browser-posture-proof-verifier-I0HP2Ics.mjs";
3
3
 
4
- //#region src/utils/base64url.ts
5
- /**
6
- * Base64url (RFC 4648 § 5) built on `atob` and `btoa` rather than Node's
7
- * buffer API, so it runs on every runtime the SDKs support, Cloudflare Workers
8
- * without `nodejs_compat` included.
9
- */
10
- const BASE64URL_UNPADDED = /^[A-Za-z0-9_-]*$/;
11
- const PADDING = 61;
12
- /**
13
- * `text` without its trailing `=` padding. A backward scan, not
14
- * `replace(/=+$/, '')`: that regex retries from every `=` in a long run that
15
- * does not reach the end, which is quadratic on hostile input.
16
- */
17
- function withoutPadding(text) {
18
- let end = text.length;
19
- while (end > 0 && text.charCodeAt(end - 1) === PADDING) end -= 1;
20
- return text.slice(0, end);
21
- }
22
- /**
23
- * Decode base64url, with or without `=` padding.
24
- *
25
- * Strict where Node's buffer decoder is lenient: a character outside the
26
- * alphabet, or a length no encoder produces (one character past a multiple of
27
- * four), throws a `TypeError` instead of being skipped or truncated. This
28
- * matches the engine's decoder.
29
- */
30
- function base64UrlToBytes(text) {
31
- const unpadded = withoutPadding(text);
32
- if (!BASE64URL_UNPADDED.test(unpadded) || unpadded.length % 4 === 1) throw new TypeError("not valid base64url (RFC 4648 § 5)");
33
- const base64 = unpadded.replace(/-/g, "+").replace(/_/g, "/");
34
- const binary = atob(base64 + "=".repeat((4 - base64.length % 4) % 4));
35
- const bytes = new Uint8Array(binary.length);
36
- for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
37
- return bytes;
38
- }
39
- /** Decode base64url to a string as UTF-8, replacing invalid sequences with U+FFFD. */
40
- function base64UrlToString(text) {
41
- return new TextDecoder().decode(base64UrlToBytes(text));
42
- }
43
-
44
- //#endregion
45
4
  //#region src/browser-posture-proof.ts
46
- /**
47
- * RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture
48
- * token to a non-extractable key the page holds, so the posture token's
49
- * TTL stops being the whole replay window. The literal RFC 9449 `typ`
50
- * value, not a project-specific string like the posture token's own
51
- * `checkpoint-posture+jwt` - adopting the registered value buys real
52
- * interoperability with any existing DPoP-aware tooling for no cost.
53
- */
54
- const POSTURE_PROOF_TYPE = "dpop+jwt";
55
- /** Half the posture TTL: a per-request, single-use artifact needs a much
56
- * tighter freshness window than a session-scoped token. A caller-supplied
57
- * parameter, not a private constant - this must never repeat
58
- * `POSTURE_TTL_SECONDS`'s own hardcoding mistake. */
59
- const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
60
5
  const BrowserPostureProofSchema = object({
61
6
  jti: string().min(1).max(255),
62
7
  htm: string().min(1).max(16),
63
8
  htu: string().url(),
64
9
  iat: number().int().nonnegative()
65
10
  });
66
- const MALFORMED = {
67
- verified: false,
68
- reason: "malformed"
69
- };
70
- async function verifyBrowserPostureProofKey(proofJws, request, expectedJkt, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
71
- if (!proofJws || proofJws.length > 2e3) return MALFORMED;
72
- let decoded;
73
- let jkt;
74
- let key;
75
- try {
76
- decoded = JSON.parse(base64UrlToString(proofJws.split(".")[0]));
77
- if (decoded.typ !== "dpop+jwt" || decoded.alg !== "ES256" || !decoded.jwk || decoded.jwk.kty !== "EC" || decoded.jwk.crv !== "P-256" || decoded.jwk.d) return MALFORMED;
78
- jkt = await calculateJwkThumbprint(decoded.jwk, "sha256");
79
- if (expectedJkt !== void 0 && jkt !== expectedJkt) return {
80
- verified: false,
81
- reason: "jkt-mismatch"
82
- };
83
- key = await importJWK(decoded.jwk, "ES256");
84
- } catch {
85
- return MALFORMED;
86
- }
87
- let payload;
88
- try {
89
- ({payload} = await jwtVerify(proofJws, key, {
90
- algorithms: ["ES256"],
91
- typ: POSTURE_PROOF_TYPE,
92
- currentDate: /* @__PURE__ */ new Date(now * 1e3)
93
- }));
94
- } catch {
95
- return {
96
- verified: false,
97
- reason: "bad-signature"
98
- };
99
- }
100
- const parsed = BrowserPostureProofSchema.safeParse(payload);
101
- if (!parsed.success) return {
102
- verified: false,
103
- reason: "invalid-claims"
104
- };
105
- const claims = parsed.data;
106
- const acceptedUrls = typeof request.url === "string" ? [request.url] : request.url;
107
- if (claims.htm.toUpperCase() !== request.method.toUpperCase() || !acceptedUrls.includes(claims.htu)) return {
108
- verified: false,
109
- reason: "htu-mismatch"
110
- };
111
- if (Math.abs(now - claims.iat) > maxAgeSeconds) return {
112
- verified: false,
113
- reason: "stale-iat"
114
- };
115
- return {
116
- verified: true,
117
- claims,
118
- jkt
119
- };
120
- }
121
11
  /**
122
12
  * Verifies a DPoP-shaped proof (RFC 9449) against an ALREADY-VERIFIED
123
13
  * `BrowserPosture` (call `verifyBrowserPosture` first). Checks, in order:
@@ -137,21 +27,6 @@ async function verifyBrowserPostureProof(proofJws, posture, request, now = Math.
137
27
  const result = await verifyBrowserPostureProofKey(proofJws, request, posture.cnf.jkt, now, maxAgeSeconds);
138
28
  return result.verified ? result.claims : void 0;
139
29
  }
140
- async function browserPostureKeyThumbprint(jwk) {
141
- if (typeof jwk !== "object" || jwk === null) return void 0;
142
- const { kty, crv, x, y, d } = jwk;
143
- if (kty !== "EC" || crv !== "P-256" || typeof x !== "string" || typeof y !== "string" || d) return;
144
- try {
145
- return await calculateJwkThumbprint({
146
- kty,
147
- crv,
148
- x,
149
- y
150
- }, "sha256");
151
- } catch {
152
- return;
153
- }
154
- }
155
30
 
156
31
  //#endregion
157
32
  export { BrowserPostureProofSchema, DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS, POSTURE_PROOF_TYPE, browserPostureKeyThumbprint, verifyBrowserPostureProof, verifyBrowserPostureProofKey };
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-proof.mjs","names":["z.object","z.string","z.number"],"sources":["../src/utils/base64url.ts","../src/browser-posture-proof.ts"],"sourcesContent":["/**\n * Base64url (RFC 4648 § 5) built on `atob` and `btoa` rather than Node's\n * buffer API, so it runs on every runtime the SDKs support, Cloudflare Workers\n * without `nodejs_compat` included.\n */\n\nconst BASE64URL_UNPADDED = /^[A-Za-z0-9_-]*$/;\nconst PADDING = 61; // '='\n\n/**\n * `text` without its trailing `=` padding. A backward scan, not\n * `replace(/=+$/, '')`: that regex retries from every `=` in a long run that\n * does not reach the end, which is quadratic on hostile input.\n */\nfunction withoutPadding(text: string): string {\n let end = text.length;\n while (end > 0 && text.charCodeAt(end - 1) === PADDING) end -= 1;\n return text.slice(0, end);\n}\n\n/**\n * Decode base64url, with or without `=` padding.\n *\n * Strict where Node's buffer decoder is lenient: a character outside the\n * alphabet, or a length no encoder produces (one character past a multiple of\n * four), throws a `TypeError` instead of being skipped or truncated. This\n * matches the engine's decoder.\n */\nexport function base64UrlToBytes(text: string): Uint8Array {\n const unpadded = withoutPadding(text);\n if (!BASE64URL_UNPADDED.test(unpadded) || unpadded.length % 4 === 1) {\n throw new TypeError('not valid base64url (RFC 4648 § 5)');\n }\n const base64 = unpadded.replace(/-/g, '+').replace(/_/g, '/');\n const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4));\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) {\n bytes[index] = binary.charCodeAt(index);\n }\n return bytes;\n}\n\n/** Decode base64url to a string as UTF-8, replacing invalid sequences with U+FFFD. */\nexport function base64UrlToString(text: string): string {\n return new TextDecoder().decode(base64UrlToBytes(text));\n}\n\n/** Encode bytes as base64url without padding. */\nexport function bytesToBase64Url(bytes: Uint8Array): string {\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return withoutPadding(btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_'));\n}\n","import { calculateJwkThumbprint, importJWK, jwtVerify, type JWK } from 'jose';\nimport { z } from 'zod';\nimport type { BrowserPosture } from './browser-posture';\nimport { base64UrlToString } from './utils/base64url';\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\nexport type BrowserPostureProofFailure =\n | 'malformed'\n | 'jkt-mismatch'\n | 'bad-signature'\n | 'invalid-claims'\n | 'htu-mismatch'\n | 'stale-iat';\n\nexport type BrowserPostureProofResult =\n | { verified: true; claims: BrowserPostureProof; jkt: string }\n | { verified: false; reason: BrowserPostureProofFailure };\n\nconst MALFORMED: BrowserPostureProofResult = { verified: false, reason: 'malformed' };\n\nexport async function verifyBrowserPostureProofKey(\n proofJws: string | undefined,\n request: { method: string; url: string | readonly string[] },\n expectedJkt?: string,\n now = Math.floor(Date.now() / 1000),\n maxAgeSeconds = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS\n): Promise<BrowserPostureProofResult> {\n if (!proofJws || proofJws.length > 2000) return MALFORMED;\n let decoded: { typ?: string; alg?: string; jwk?: JWK };\n let jkt: string;\n let key: Awaited<ReturnType<typeof importJWK>>;\n try {\n decoded = JSON.parse(base64UrlToString(proofJws.split('.')[0]));\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 MALFORMED;\n jkt = await calculateJwkThumbprint(decoded.jwk, 'sha256');\n if (expectedJkt !== undefined && jkt !== expectedJkt) {\n return { verified: false, reason: 'jkt-mismatch' };\n }\n key = await importJWK(decoded.jwk, 'ES256');\n } catch {\n return MALFORMED;\n }\n let payload: Awaited<ReturnType<typeof jwtVerify>>['payload'];\n try {\n ({ payload } = await jwtVerify(proofJws, key, {\n algorithms: ['ES256'],\n typ: POSTURE_PROOF_TYPE,\n currentDate: new Date(now * 1000),\n }));\n } catch {\n return { verified: false, reason: 'bad-signature' };\n }\n const parsed = BrowserPostureProofSchema.safeParse(payload);\n if (!parsed.success) return { verified: false, reason: 'invalid-claims' };\n const claims = parsed.data;\n const acceptedUrls = typeof request.url === 'string' ? [request.url] : request.url;\n if (\n claims.htm.toUpperCase() !== request.method.toUpperCase() ||\n !acceptedUrls.includes(claims.htu)\n ) {\n return { verified: false, reason: 'htu-mismatch' };\n }\n if (Math.abs(now - claims.iat) > maxAgeSeconds) return { verified: false, reason: 'stale-iat' };\n return { verified: true, claims, jkt };\n}\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 (!posture.cnf) return undefined;\n const result = await verifyBrowserPostureProofKey(\n proofJws,\n request,\n posture.cnf.jkt,\n now,\n maxAgeSeconds\n );\n return result.verified ? result.claims : undefined;\n}\n\nexport async function browserPostureKeyThumbprint(jwk: unknown): Promise<string | undefined> {\n if (typeof jwk !== 'object' || jwk === null) return undefined;\n const { kty, crv, x, y, d } = jwk as Record<string, unknown>;\n if (kty !== 'EC' || crv !== 'P-256' || typeof x !== 'string' || typeof y !== 'string' || d) {\n return undefined;\n }\n try {\n return await calculateJwkThumbprint({ kty, crv, x, y }, 'sha256');\n } catch {\n return undefined;\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"browser-posture-proof.mjs","names":["z.object","z.string","z.number"],"sources":["../src/browser-posture-proof.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { BrowserPosture } from './browser-posture';\nimport {\n DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS,\n verifyBrowserPostureProofKey,\n type BrowserPostureProof,\n} from './browser-posture-proof-verifier';\n\nexport {\n browserPostureKeyThumbprint,\n DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS,\n POSTURE_PROOF_TYPE,\n verifyBrowserPostureProofKey,\n} from './browser-posture-proof-verifier';\nexport type {\n BrowserPostureProof,\n BrowserPostureProofFailure,\n BrowserPostureProofResult,\n} from './browser-posture-proof-verifier';\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}) satisfies z.ZodType<BrowserPostureProof>;\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 (!posture.cnf) return undefined;\n const result = await verifyBrowserPostureProofKey(\n proofJws,\n request,\n posture.cnf.jkt,\n now,\n maxAgeSeconds\n );\n return result.verified ? result.claims : undefined;\n}\n"],"mappings":";;;;AAoBA,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;;;;;;;;;;;;;;;AAgBD,eAAsB,0BACpB,UACA,SACA,SACA,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,GAClC,oBAC0C;CAC1C,IAAI,CAAC,QAAQ,KAAK,OAAO;CACzB,MAAM,SAAS,MAAM,6BACnB,UACA,SACA,QAAQ,IAAI,KACZ,KACA,aACF;CACA,OAAO,OAAO,WAAW,OAAO,SAAS;AAC3C"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_schemas = require('./schemas-BlScS1it.js');
3
- const require_patterns = require('./patterns-B2r7M9wR.js');
3
+ const require_patterns = require('./patterns-CiMpbdAF.js');
4
4
  const require_posture_origins = require('./posture-origins-Ci6k4Zh1.js');
5
5
  const require_project_verification_key = require('./project-verification-key-B-L3D2nC.js');
6
6
  let jose = require("jose");
@@ -294,9 +294,39 @@ async function postureFromRequest(request, config, projectId, now) {
294
294
  async function postureFromCookies(header, config, projectId) {
295
295
  return postureFromRequest({ cookie: header }, config, projectId);
296
296
  }
297
- /** Exact paths or an explicit subtree ending in /*. Longest designation wins. */
297
+ /**
298
+ * A path the way routers commonly match one: letter case and trailing
299
+ * slashes do not change which handler serves a request (Express routes are
300
+ * case-insensitive and non-strict by default), so they cannot change which
301
+ * designation covers it either. Folding them can only add a step-up.
302
+ */
303
+ function routeKey(path) {
304
+ let end = path.length;
305
+ while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
306
+ return end === 0 ? "/" : path.slice(0, end).toLowerCase();
307
+ }
308
+ /** The key a designation is matched and deduplicated by. */
309
+ function designationKey(path) {
310
+ return path.endsWith("/*") ? `${routeKey(path.slice(0, -2))}/*` : routeKey(path);
311
+ }
312
+ /** More specific first: the longer path, then an exact path before its own subtree. */
313
+ function bySpecificity(a, b) {
314
+ const length = (path) => routeKey(path.endsWith("/*") ? path.slice(0, -2) : path).length;
315
+ const subtree = (path) => path.endsWith("/*") ? 1 : 0;
316
+ return length(b.path) - length(a.path) || subtree(a.path) - subtree(b.path);
317
+ }
318
+ function designationCovers(designation, path) {
319
+ const key = routeKey(path);
320
+ if (!designation.endsWith("/*")) return key === routeKey(designation);
321
+ const root = routeKey(designation.slice(0, -2));
322
+ return root === "/" || key === root || key.startsWith(`${root}/`);
323
+ }
324
+ /**
325
+ * Exact paths or an explicit subtree ending in /*, matched without letter
326
+ * case or trailing slashes. The most specific designation wins.
327
+ */
298
328
  function postureRequiredScopes(config, path) {
299
- const route = [...config.protectedRoutes ?? []].sort((a, b) => b.path.length - a.path.length).find((r) => r.path.endsWith("/*") ? path.startsWith(r.path.slice(0, -1)) : path === r.path);
329
+ const route = [...config.protectedRoutes ?? []].sort(bySpecificity).find((r) => designationCovers(r.path, path));
300
330
  if (!route) return void 0;
301
331
  if (!route.scopes.length || route.scopes.length > 50 || route.scopes.some((s) => s.length > 200 || !/^[\x21\x23-\x5b\x5d-\x7e]+$/.test(s)) || new Set(route.scopes).size !== route.scopes.length) throw new Error("Integrity-protected routes require explicit, unique scopes");
302
332
  return route.scopes;
@@ -314,8 +344,9 @@ function validateBrowserPostureConfig(config, projectId) {
314
344
  const paths = /* @__PURE__ */ new Set();
315
345
  for (const route of config.protectedRoutes ?? []) {
316
346
  if (!/^\/(?:[^?#*\\]*)(?:\/\*)?$/.test(route.path) && route.path !== "/*") throw new Error("Invalid integrity-protected path");
317
- if (paths.has(route.path)) throw new Error("Duplicate integrity-protected path");
318
- paths.add(route.path);
347
+ const key = designationKey(route.path);
348
+ if (paths.has(key)) throw new Error("Duplicate integrity-protected path");
349
+ paths.add(key);
319
350
  postureRequiredScopes({
320
351
  ...config,
321
352
  protectedRoutes: [route]
@@ -1,5 +1,5 @@
1
1
  import { S as string, _ as number, b as record, c as array, f as guid, h as literal, i as _enum, l as boolean, v as object, w as unknown } from "./schemas-IHAhH3gV.mjs";
2
- import { c as VALIDATION_PATTERNS, s as UUID_PATTERN } from "./patterns-B7dQoeE3.mjs";
2
+ import { c as VALIDATION_PATTERNS, s as UUID_PATTERN } from "./patterns-D4OAsNQY.mjs";
3
3
  import { n as matchAllowedOrigin, r as parseOriginPattern } from "./posture-origins-DGyS4Vuk.mjs";
4
4
  import { t as projectVerificationKey } from "./project-verification-key-CWXdu3-n.mjs";
5
5
  import { SignJWT, compactVerify, decodeProtectedHeader, importJWK } from "jose";
@@ -293,9 +293,39 @@ async function postureFromRequest(request, config, projectId, now) {
293
293
  async function postureFromCookies(header, config, projectId) {
294
294
  return postureFromRequest({ cookie: header }, config, projectId);
295
295
  }
296
- /** Exact paths or an explicit subtree ending in /*. Longest designation wins. */
296
+ /**
297
+ * A path the way routers commonly match one: letter case and trailing
298
+ * slashes do not change which handler serves a request (Express routes are
299
+ * case-insensitive and non-strict by default), so they cannot change which
300
+ * designation covers it either. Folding them can only add a step-up.
301
+ */
302
+ function routeKey(path) {
303
+ let end = path.length;
304
+ while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
305
+ return end === 0 ? "/" : path.slice(0, end).toLowerCase();
306
+ }
307
+ /** The key a designation is matched and deduplicated by. */
308
+ function designationKey(path) {
309
+ return path.endsWith("/*") ? `${routeKey(path.slice(0, -2))}/*` : routeKey(path);
310
+ }
311
+ /** More specific first: the longer path, then an exact path before its own subtree. */
312
+ function bySpecificity(a, b) {
313
+ const length = (path) => routeKey(path.endsWith("/*") ? path.slice(0, -2) : path).length;
314
+ const subtree = (path) => path.endsWith("/*") ? 1 : 0;
315
+ return length(b.path) - length(a.path) || subtree(a.path) - subtree(b.path);
316
+ }
317
+ function designationCovers(designation, path) {
318
+ const key = routeKey(path);
319
+ if (!designation.endsWith("/*")) return key === routeKey(designation);
320
+ const root = routeKey(designation.slice(0, -2));
321
+ return root === "/" || key === root || key.startsWith(`${root}/`);
322
+ }
323
+ /**
324
+ * Exact paths or an explicit subtree ending in /*, matched without letter
325
+ * case or trailing slashes. The most specific designation wins.
326
+ */
297
327
  function postureRequiredScopes(config, path) {
298
- const route = [...config.protectedRoutes ?? []].sort((a, b) => b.path.length - a.path.length).find((r) => r.path.endsWith("/*") ? path.startsWith(r.path.slice(0, -1)) : path === r.path);
328
+ const route = [...config.protectedRoutes ?? []].sort(bySpecificity).find((r) => designationCovers(r.path, path));
299
329
  if (!route) return void 0;
300
330
  if (!route.scopes.length || route.scopes.length > 50 || route.scopes.some((s) => s.length > 200 || !/^[\x21\x23-\x5b\x5d-\x7e]+$/.test(s)) || new Set(route.scopes).size !== route.scopes.length) throw new Error("Integrity-protected routes require explicit, unique scopes");
301
331
  return route.scopes;
@@ -313,8 +343,9 @@ function validateBrowserPostureConfig(config, projectId) {
313
343
  const paths = /* @__PURE__ */ new Set();
314
344
  for (const route of config.protectedRoutes ?? []) {
315
345
  if (!/^\/(?:[^?#*\\]*)(?:\/\*)?$/.test(route.path) && route.path !== "/*") throw new Error("Invalid integrity-protected path");
316
- if (paths.has(route.path)) throw new Error("Duplicate integrity-protected path");
317
- paths.add(route.path);
346
+ const key = designationKey(route.path);
347
+ if (paths.has(key)) throw new Error("Duplicate integrity-protected path");
348
+ paths.add(key);
318
349
  postureRequiredScopes({
319
350
  ...config,
320
351
  protectedRoutes: [route]