@kya-os/checkpoint-shared 1.5.0 → 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 +129 -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 +50 -14
  10. package/dist/beacon-types/index.d.mts.map +1 -1
  11. package/dist/beacon-types/index.d.ts +50 -14
  12. package/dist/beacon-types/index.d.ts.map +1 -1
  13. package/dist/beacon-types/index.js +127 -8
  14. package/dist/beacon-types/index.mjs +122 -9
  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 -83
  40. package/dist/browser-posture.d.ts +2 -83
  41. package/dist/browser-posture.js +214 -44
  42. package/dist/browser-posture.mjs +203 -45
  43. package/dist/browser-posture.mjs.map +1 -1
  44. package/dist/browser.d.mts +3 -11
  45. package/dist/browser.d.mts.map +1 -1
  46. package/dist/browser.d.ts +3 -11
  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 +5227 -1063
  79. package/dist/index.d.mts.map +1 -1
  80. package/dist/index.d.ts +5227 -1063
  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
@@ -0,0 +1,441 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region src/posture-origins/index.ts
3
+ /**
4
+ * Posture origins: which page origins a project's browser posture token may
5
+ * be issued for (and, at the edge gateway, accepted on).
6
+ *
7
+ * The primary origin is derived from `project.domain`. A project can add up
8
+ * to {@link MAX_POSTURE_ORIGINS} more in `settings.postureOrigins`, for the
9
+ * installs a single varchar cannot describe: a Shopify store whose shoppers
10
+ * browse a custom domain while `project.domain` is the myshopify host, `www`
11
+ * next to the apex, a staging host, several storefront domains.
12
+ *
13
+ * One resolver, used by every caller (the beacon issuer, the settings APIs,
14
+ * the dashboard editor, the gateway verifier, the beacon-ingest Worker), so
15
+ * what the dashboard accepts, what the issuer signs and what the gateway
16
+ * verifies can never drift apart.
17
+ *
18
+ * Pure, dependency-free, Web-standard `URL` only: safe in Node, the browser
19
+ * and Cloudflare Workers. `URL` also gives consistent IDN handling: a
20
+ * Unicode host is converted to its punycode (`xn--`) form everywhere, which
21
+ * is exactly how a browser serializes the `Origin` header.
22
+ *
23
+ * Pattern rules (the stored form is always normalized):
24
+ * - `https://host[:port]`: an exact origin. HTTPS only, with no localhost
25
+ * exception, because the posture signer (`signBrowserPosture`) refuses any
26
+ * non-HTTPS audience anyway.
27
+ * - A bare `host` is read as `https://host`. Paths, a trailing slash, query
28
+ * and fragment are stripped; userinfo (`user@host`) is rejected.
29
+ * - `https://*.example.com`: matches any origin ONE OR MORE labels below
30
+ * `example.com` (`a.example.com`, `a.b.example.com`), same scheme and port.
31
+ * It never matches the apex `example.com`; list that separately. The
32
+ * wildcard is allowed only as the whole leftmost label.
33
+ * - A wildcard over a public or multi-tenant suffix is rejected
34
+ * (`*.com`, `*.co.uk`, `*.myshopify.com`, `*.vercel.app`, ...): it would
35
+ * let any tenant of that platform mint posture for this project.
36
+ *
37
+ * @example
38
+ * const allowed = resolveProjectAllowedOrigins({
39
+ * domain: 'checkpoint-rebrand.myshopify.com',
40
+ * settings: { postureOrigins: ['https://www.brand.com', 'https://*.brand.com'] },
41
+ * });
42
+ * matchAllowedOrigin('https://shop.brand.com', allowed); // 'https://shop.brand.com'
43
+ * matchAllowedOrigin('https://brand.com', allowed); // undefined (apex not listed)
44
+ */
45
+ const MAX_POSTURE_ORIGINS = 20;
46
+ /** Longest accepted entry: `https://` + a 253-char host + `:65535`, with headroom. */
47
+ const MAX_POSTURE_ORIGIN_LENGTH = 300;
48
+ /**
49
+ * Multi-tenant hosting suffixes a customer does not control the siblings of.
50
+ * A wildcard AT or anywhere BELOW one of these is refused, because platforms
51
+ * nest tenant namespaces (`*.s3.us-east-1.amazonaws.com`, `*.a.run.app`,
52
+ * `*.blob.core.windows.net`). An exact tenant host (`https://brand.myshopify.com`)
53
+ * is still accepted.
54
+ *
55
+ * The public-suffix list is not a dependency of this package (it would ship
56
+ * to the dashboard bundle and both Workers), so this is a curated list plus
57
+ * the structural checks in {@link isPublicSuffixLike}. It is not complete:
58
+ * adopting the PSL private section (e.g. `tldts`) is the full fix.
59
+ */
60
+ const MULTI_TENANT_SUFFIXES = /* @__PURE__ */ new Set([
61
+ "myshopify.com",
62
+ "shopifypreview.com",
63
+ "myshopline.com",
64
+ "mybigcommerce.com",
65
+ "bigcartel.com",
66
+ "company.site",
67
+ "square.site",
68
+ "wixsite.com",
69
+ "wixstudio.io",
70
+ "squarespace.com",
71
+ "webflow.io",
72
+ "framer.app",
73
+ "framer.website",
74
+ "carrd.co",
75
+ "weebly.com",
76
+ "godaddysites.com",
77
+ "mystrikingly.com",
78
+ "hs-sites.com",
79
+ "hubspotpagebuilder.com",
80
+ "myportfolio.com",
81
+ "notion.site",
82
+ "ghost.io",
83
+ "substack.com",
84
+ "tumblr.com",
85
+ "blogspot.com",
86
+ "wordpress.com",
87
+ "wpengine.com",
88
+ "wpenginepowered.com",
89
+ "pantheonsite.io",
90
+ "kinsta.cloud",
91
+ "gitbook.io",
92
+ "bubbleapps.io",
93
+ "neocities.org",
94
+ "lovable.app",
95
+ "lovable.dev",
96
+ "replit.app",
97
+ "replit.dev",
98
+ "repl.co",
99
+ "glitch.me",
100
+ "vusercontent.net",
101
+ "csb.app",
102
+ "codesandbox.io",
103
+ "stackblitz.io",
104
+ "webcontainer.io",
105
+ "streamlit.app",
106
+ "hf.space",
107
+ "gradio.live",
108
+ "pythonanywhere.com",
109
+ "vercel.app",
110
+ "now.sh",
111
+ "netlify.app",
112
+ "netlify.com",
113
+ "pages.dev",
114
+ "workers.dev",
115
+ "r2.dev",
116
+ "github.io",
117
+ "github.dev",
118
+ "gitlab.io",
119
+ "herokuapp.com",
120
+ "onrender.com",
121
+ "fly.dev",
122
+ "railway.app",
123
+ "koyeb.app",
124
+ "deno.dev",
125
+ "surge.sh",
126
+ "ondigitalocean.app",
127
+ "digitaloceanspaces.com",
128
+ "gitpod.io",
129
+ "amazonaws.com",
130
+ "amplifyapp.com",
131
+ "awsapprunner.com",
132
+ "elasticbeanstalk.com",
133
+ "cloudfront.net",
134
+ "azurewebsites.net",
135
+ "azurestaticapps.net",
136
+ "azurecontainerapps.io",
137
+ "azureedge.net",
138
+ "azurefd.net",
139
+ "azure-api.net",
140
+ "cloudapp.net",
141
+ "cloudapp.azure.com",
142
+ "windows.net",
143
+ "run.app",
144
+ "web.app",
145
+ "firebaseapp.com",
146
+ "firebasestorage.app",
147
+ "appspot.com",
148
+ "googleapis.com",
149
+ "googleusercontent.com",
150
+ "translate.goog",
151
+ "fastly.net",
152
+ "akamaized.net",
153
+ "akamaihd.net",
154
+ "edgekey.net",
155
+ "edgesuite.net",
156
+ "b-cdn.net",
157
+ "cloudflarestorage.com",
158
+ "supabase.co",
159
+ "ngrok.io",
160
+ "ngrok.app",
161
+ "ngrok.dev",
162
+ "ngrok-free.app",
163
+ "ngrok-free.dev",
164
+ "trycloudflare.com",
165
+ "loca.lt"
166
+ ]);
167
+ /** Common second-level labels under a two-letter country TLD (`co.uk`, `com.au`, `ne.jp`). */
168
+ const CCTLD_SECOND_LEVEL_LABELS = /* @__PURE__ */ new Set([
169
+ "ac",
170
+ "biz",
171
+ "co",
172
+ "com",
173
+ "edu",
174
+ "gen",
175
+ "go",
176
+ "gob",
177
+ "gov",
178
+ "info",
179
+ "ltd",
180
+ "me",
181
+ "mil",
182
+ "ne",
183
+ "net",
184
+ "nic",
185
+ "or",
186
+ "org",
187
+ "plc",
188
+ "sch"
189
+ ]);
190
+ const WILDCARD_PROBE_LABEL = "posture-origin-wildcard-probe";
191
+ /**
192
+ * True when a wildcard directly over `host` would cover sites the customer
193
+ * does not control: a single label (`com`), a common ccTLD second level
194
+ * (`co.uk`, `com.au`), or a known multi-tenant platform suffix or any host
195
+ * below one (`myshopify.com`, `s3.us-east-1.amazonaws.com`). A heuristic,
196
+ * not the full PSL.
197
+ */
198
+ function isPublicSuffixLike(host) {
199
+ const labels = host.split(".");
200
+ if (labels.length < 2) return true;
201
+ for (let index = 0; index < labels.length - 1; index++) if (MULTI_TENANT_SUFFIXES.has(labels.slice(index).join("."))) return true;
202
+ if (labels.length === 2) {
203
+ const [second, top] = labels;
204
+ if (top.length === 2 && CCTLD_SECOND_LEVEL_LABELS.has(second)) return true;
205
+ }
206
+ return false;
207
+ }
208
+ function isIpLiteral(host) {
209
+ return host.startsWith("[") || /^\d+(\.\d+){3}$/.test(host);
210
+ }
211
+ /**
212
+ * Validates and normalizes one allowlist entry. Returns a human-readable
213
+ * error for the settings API's 400 and the dashboard editor.
214
+ */
215
+ function parseOriginPattern(input) {
216
+ const trimmed = typeof input === "string" ? input.trim() : "";
217
+ if (!trimmed) return {
218
+ ok: false,
219
+ error: "Enter an origin such as https://www.example.com"
220
+ };
221
+ if (trimmed.length > 300) return {
222
+ ok: false,
223
+ error: `Must be at most ${300} characters`
224
+ };
225
+ const schemeMatch = /^([a-z][a-z0-9+.-]*):\/\//i.exec(trimmed);
226
+ if (schemeMatch && schemeMatch[1].toLowerCase() !== "https") return {
227
+ ok: false,
228
+ error: "Only https:// origins are supported"
229
+ };
230
+ const rest = schemeMatch ? trimmed.slice(schemeMatch[0].length) : trimmed;
231
+ const wildcard = rest.startsWith("*.");
232
+ const withoutWildcard = wildcard ? rest.slice(2) : rest;
233
+ if (withoutWildcard.includes("*")) return {
234
+ ok: false,
235
+ error: "A wildcard is only allowed as the whole first label, e.g. https://*.example.com"
236
+ };
237
+ let url;
238
+ try {
239
+ url = new URL(`https://${wildcard ? `${WILDCARD_PROBE_LABEL}.` : ""}${withoutWildcard}`);
240
+ } catch {
241
+ return {
242
+ ok: false,
243
+ error: "Not a valid origin"
244
+ };
245
+ }
246
+ if (url.username || url.password) return {
247
+ ok: false,
248
+ error: "Origins cannot contain a username or password"
249
+ };
250
+ let host = url.hostname;
251
+ if (wildcard) host = host.slice(30);
252
+ if (!host || host.endsWith(".") || host.startsWith(".")) return {
253
+ ok: false,
254
+ error: "Not a valid host name"
255
+ };
256
+ if (isIpLiteral(host)) return {
257
+ ok: false,
258
+ error: "Use a domain name, not an IP address"
259
+ };
260
+ if (wildcard && isPublicSuffixLike(host)) return {
261
+ ok: false,
262
+ error: `*.${host} would include sites you do not control; list your own hosts instead`
263
+ };
264
+ if (!host.includes(".")) return {
265
+ ok: false,
266
+ error: "Use a fully qualified domain, e.g. www.example.com"
267
+ };
268
+ const port = url.port;
269
+ if (port === "0") return {
270
+ ok: false,
271
+ error: "Not a valid port"
272
+ };
273
+ return {
274
+ ok: true,
275
+ value: {
276
+ pattern: `https://${wildcard ? "*." : ""}${host}${port ? `:${port}` : ""}`,
277
+ wildcard,
278
+ host,
279
+ port
280
+ }
281
+ };
282
+ }
283
+ /**
284
+ * Validates a full allowlist from an API body or the editor: every entry
285
+ * must parse, the list is capped, and duplicates (after normalization) are
286
+ * removed while keeping first-seen order.
287
+ */
288
+ function validatePostureOrigins(input) {
289
+ if (!Array.isArray(input)) return {
290
+ ok: false,
291
+ errors: [{
292
+ index: -1,
293
+ message: "Expected a list of origins"
294
+ }]
295
+ };
296
+ if (input.length > 20) return {
297
+ ok: false,
298
+ errors: [{
299
+ index: -1,
300
+ message: `At most ${20} additional origins`
301
+ }]
302
+ };
303
+ const errors = [];
304
+ const origins = [];
305
+ input.forEach((entry, index) => {
306
+ if (typeof entry !== "string") {
307
+ errors.push({
308
+ index,
309
+ message: "Each origin must be a string"
310
+ });
311
+ return;
312
+ }
313
+ const parsed = parseOriginPattern(entry);
314
+ if (!parsed.ok) {
315
+ errors.push({
316
+ index,
317
+ message: parsed.error
318
+ });
319
+ return;
320
+ }
321
+ if (!origins.includes(parsed.value.pattern)) origins.push(parsed.value.pattern);
322
+ });
323
+ return errors.length > 0 ? {
324
+ ok: false,
325
+ errors
326
+ } : {
327
+ ok: true,
328
+ origins
329
+ };
330
+ }
331
+ /**
332
+ * The primary origin from `project.domain`: an exact HTTPS origin, or
333
+ * undefined when the domain is unset or carries a path, query, fragment or
334
+ * userinfo. A bare host is read as `https://host`.
335
+ */
336
+ function primaryPostureOrigin(domain) {
337
+ if (!domain) return void 0;
338
+ try {
339
+ const url = new URL(domain.includes("://") ? domain : `https://${domain}`);
340
+ if (url.protocol !== "https:" || url.username || url.password || url.pathname !== "/" || url.search || url.hash) return void 0;
341
+ return url.origin;
342
+ } catch {
343
+ return;
344
+ }
345
+ }
346
+ /**
347
+ * Reads `settings.postureOrigins` defensively: settings is a jsonb column,
348
+ * so anything written before validation existed (or by hand) is re-parsed
349
+ * and invalid entries are dropped rather than trusted.
350
+ */
351
+ function postureKeysUrl(base, projectId) {
352
+ return `${base}/api/v1/beacon/keys?projectId=${projectId}`;
353
+ }
354
+ function readPostureOriginsSetting(settings) {
355
+ if (!settings || typeof settings !== "object") return [];
356
+ const raw = settings.postureOrigins;
357
+ if (!Array.isArray(raw)) return [];
358
+ const origins = [];
359
+ for (const entry of raw.slice(0, 20)) {
360
+ if (typeof entry !== "string") continue;
361
+ const parsed = parseOriginPattern(entry);
362
+ if (parsed.ok && !origins.includes(parsed.value.pattern)) origins.push(parsed.value.pattern);
363
+ }
364
+ return origins;
365
+ }
366
+ /**
367
+ * Every origin pattern a project's posture may be issued for: the primary
368
+ * (from `project.domain`) first, then the additional allowlist. Empty when
369
+ * neither exists, which the issuer reports as `domain-unset`.
370
+ */
371
+ function resolveProjectAllowedOrigins(project) {
372
+ const allowed = [];
373
+ const primary = primaryPostureOrigin(project.domain);
374
+ if (primary) allowed.push(primary);
375
+ for (const pattern of readPostureOriginsSetting(project.settings)) if (!allowed.includes(pattern)) allowed.push(pattern);
376
+ return allowed;
377
+ }
378
+ /**
379
+ * Returns the page origin when it matches one of `allowed`, else undefined.
380
+ * The page origin must already be in the browser's serialized form
381
+ * (`https://host[:port]`, lowercase, no path); anything else, including the
382
+ * opaque `null` origin, never matches. The value returned is the page origin
383
+ * itself, never a pattern, so a signed audience is always a concrete origin.
384
+ */
385
+ function matchAllowedOrigin(pageOrigin, allowed) {
386
+ if (!pageOrigin || allowed.length === 0) return void 0;
387
+ let url;
388
+ try {
389
+ url = new URL(pageOrigin);
390
+ } catch {
391
+ return;
392
+ }
393
+ if (url.protocol !== "https:" || url.origin !== pageOrigin) return void 0;
394
+ const host = url.hostname;
395
+ if (host.includes("*")) return void 0;
396
+ for (const entry of allowed) {
397
+ const parsed = parseOriginPattern(entry);
398
+ if (!parsed.ok || parsed.value.port !== url.port) continue;
399
+ const { wildcard, host: patternHost } = parsed.value;
400
+ if (!wildcard) {
401
+ if (host === patternHost) return pageOrigin;
402
+ continue;
403
+ }
404
+ if (host.length > patternHost.length + 1 && host.endsWith(`.${patternHost}`)) return pageOrigin;
405
+ }
406
+ }
407
+ /**
408
+ * The page origin for an ingest request: the browser-set `Origin` header,
409
+ * or, ONLY when that header is absent, the origin of `Referer`. Both are
410
+ * set by the browser and equally forgeable by a non-browser client, so the
411
+ * fallback adds no trust; it recovers installs whose proxy or request mode
412
+ * drops `Origin`. A present-but-opaque `Origin: null` is kept as is (and
413
+ * never matches), so a sandboxed frame cannot fall back to its Referer.
414
+ * Never read `X-Forwarded-Host`, `X-Forwarded-Origin` or any custom header
415
+ * here: those are caller-controlled.
416
+ */
417
+ function pageOriginFromHeaders(origin, referer) {
418
+ if (origin !== null && origin !== void 0) return origin;
419
+ if (!referer) return null;
420
+ try {
421
+ const url = new URL(referer);
422
+ if (url.protocol !== "https:" || url.username || url.password) return null;
423
+ return url.origin;
424
+ } catch {
425
+ return null;
426
+ }
427
+ }
428
+
429
+ //#endregion
430
+ exports.MAX_POSTURE_ORIGINS = MAX_POSTURE_ORIGINS;
431
+ exports.MAX_POSTURE_ORIGIN_LENGTH = MAX_POSTURE_ORIGIN_LENGTH;
432
+ exports.MULTI_TENANT_SUFFIXES = MULTI_TENANT_SUFFIXES;
433
+ exports.isPublicSuffixLike = isPublicSuffixLike;
434
+ exports.matchAllowedOrigin = matchAllowedOrigin;
435
+ exports.pageOriginFromHeaders = pageOriginFromHeaders;
436
+ exports.parseOriginPattern = parseOriginPattern;
437
+ exports.postureKeysUrl = postureKeysUrl;
438
+ exports.primaryPostureOrigin = primaryPostureOrigin;
439
+ exports.readPostureOriginsSetting = readPostureOriginsSetting;
440
+ exports.resolveProjectAllowedOrigins = resolveProjectAllowedOrigins;
441
+ exports.validatePostureOrigins = validatePostureOrigins;