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