@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,621 @@
1
+ //#region src/constants/patterns.ts
2
+ /**
3
+ * Regular Expression Patterns
4
+ *
5
+ * Common regex patterns used for validation and detection
6
+ */
7
+ /**
8
+ * Validation Patterns
9
+ */
10
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
11
+ const VALIDATION_PATTERNS = {
12
+ UUID: UUID_PATTERN,
13
+ ULID: /^[0-9A-HJKMNP-TV-Z]{26}$/,
14
+ SLUG: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
15
+ IPV4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
16
+ IPV6: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,
17
+ IP: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,
18
+ CIDR: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:[0-9]|[12][0-9]|3[0-2])$/,
19
+ DOMAIN: /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,
20
+ HOSTNAME: /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/,
21
+ URL: /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,
22
+ EMAIL: /^[a-zA-Z0-9](?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]|\.(?!\.))*[a-zA-Z0-9]?@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/,
23
+ PHONE: /^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/,
24
+ JWT: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/,
25
+ BASE64: /^[A-Za-z0-9+\/]*={0,2}$/,
26
+ HEX: /^[0-9a-fA-F]+$/,
27
+ MD5: /^[a-f0-9]{32}$/i,
28
+ SHA1: /^[a-f0-9]{40}$/i,
29
+ SHA256: /^[a-f0-9]{64}$/i,
30
+ SEMVER: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,
31
+ FILENAME: /^[a-zA-Z0-9](?:[a-zA-Z0-9 ._-]*[a-zA-Z0-9])?\.[a-zA-Z0-9_-]+$/,
32
+ PATH: /^(\/[^/ ]*)+\/?$/,
33
+ API_KEY: /^[A-Za-z0-9_-]{32,}$/,
34
+ SECRET_KEY: /^[A-Za-z0-9_-]{64,}$/,
35
+ PIXEL_ID: /^px_[A-Za-z0-9]{16}$/
36
+ };
37
+ /**
38
+ * User Agent Patterns for Agent Detection
39
+ */
40
+ const USER_AGENT_PATTERNS = {
41
+ OPENAI: /(?:GPTBot|ChatGPT-User|OpenAI)/i,
42
+ ANTHROPIC: /(?:Claude-Web|Claude-User|anthropic-ai|claude-web|claude-user|ClaudeBot)/i,
43
+ PERPLEXITY: /(?:PerplexityBot|Perplexica)/i,
44
+ GOOGLE_AI: /(?:Bard|Google-InspectionTool)/i,
45
+ MICROSOFT_AI: /(?:BingPreview\/.*ChatGPT|Copilot)/i,
46
+ GOOGLEBOT: /Googlebot/i,
47
+ BINGBOT: /(?:bingbot|BingPreview|msnbot)/i,
48
+ DUCKDUCKBOT: /DuckDuckBot/i,
49
+ BAIDUBOT: /Baiduspider/i,
50
+ YANDEXBOT: /YandexBot/i,
51
+ FACEBOOK: /(?:facebookexternalhit|facebookcatalog)/i,
52
+ TWITTER: /(?:Twitterbot|TwitterImageProxy)/i,
53
+ LINKEDIN: /LinkedInBot/i,
54
+ WHATSAPP: /WhatsApp/i,
55
+ TELEGRAM: /TelegramBot/i,
56
+ DISCORD: /Discordbot/i,
57
+ SLACK: /Slackbot/i,
58
+ GENERIC_BOT: /(?:bot|crawler|spider|scraper|agent)/i,
59
+ SCRAPY: /Scrapy/i,
60
+ PUPPETEER: /(?:HeadlessChrome|Puppeteer)/i,
61
+ PLAYWRIGHT: /Playwright/i,
62
+ SELENIUM: /(?:selenium|webdriver)/i,
63
+ POSTMAN: /PostmanRuntime/i,
64
+ INSOMNIA: /insomnia/i,
65
+ CURL: /curl/i,
66
+ WGET: /Wget/i,
67
+ HTTPIE: /HTTPie/i,
68
+ UPTIMEROBOT: /UptimeRobot/i,
69
+ PINGDOM: /Pingdom/i,
70
+ NEWRELIC: /NewRelicPinger/i,
71
+ DATADOG: /Datadog/i
72
+ };
73
+ /**
74
+ * Header Patterns for Agent Detection
75
+ */
76
+ const HEADER_PATTERNS = {
77
+ AI_HEADERS: /^(?:X-(?:OpenAI|Anthropic|AI|Bot|Agent|LLM))/i,
78
+ AUTOMATION_HEADERS: /^(?:X-(?:Automated|Robot|Crawler|Scraper))/i,
79
+ MISSING_ACCEPT: /^$/,
80
+ MISSING_ACCEPT_LANGUAGE: /^$/,
81
+ MISSING_ACCEPT_ENCODING: /^$/,
82
+ GENERIC_ACCEPT: /^\*\/\*$/,
83
+ NO_COOKIES: /^$/,
84
+ PROXY_HEADERS: /^(?:X-Forwarded-|X-Real-IP|X-Originating-IP|Via|Forwarded)/i,
85
+ CLOUD_HEADERS: /^(?:X-(?:AWS|Azure|GCP|Cloudflare))/i
86
+ };
87
+ /**
88
+ * Browser Patterns
89
+ */
90
+ const BROWSER_PATTERNS = {
91
+ CHROME: /Chrome\/([0-9.]+)/,
92
+ FIREFOX: /Firefox\/([0-9.]+)/,
93
+ SAFARI: /Version\/([0-9.]+).*Safari/,
94
+ EDGE: /Edg\/([0-9.]+)/,
95
+ OPERA: /OPR\/([0-9.]+)/,
96
+ IE: /MSIE ([0-9.]+)/
97
+ };
98
+ /**
99
+ * Operating System Patterns
100
+ */
101
+ const OS_PATTERNS = {
102
+ WINDOWS: /Windows NT ([0-9.]+)/,
103
+ MACOS: /Mac OS X ([0-9_]+)/,
104
+ LINUX: /Linux/,
105
+ ANDROID: /Android ([0-9.]+)/,
106
+ IOS: /OS ([0-9_]+) like Mac OS X/
107
+ };
108
+ /**
109
+ * Mobile Device Patterns
110
+ */
111
+ const MOBILE_PATTERNS = {
112
+ MOBILE: /(?:Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini)/i,
113
+ TABLET: /(?:iPad|Android.*Tablet|Tablet.*Android|Kindle|Silk)/i,
114
+ DESKTOP: /(?:Windows NT|Mac OS X|Linux|CrOS)/i
115
+ };
116
+ /**
117
+ * Suspicious Behavior Patterns
118
+ */
119
+ const SUSPICIOUS_PATTERNS = {
120
+ RAPID_REQUESTS: /^[0-9]{1,3}$/,
121
+ SEQUENTIAL_URLS: /\?(?:page|offset|id)=[0-9]+/,
122
+ API_ENDPOINTS: /\/api\/|\.json$|\.xml$/i,
123
+ DIRECT_POST: /^POST$/,
124
+ SQL_INJECTION: /(?:union|select|insert|update|delete|drop|create|alter|exec|script|javascript|onerror|onload|eval|src=)/i,
125
+ XSS_ATTEMPT: /(?:<script|javascript:|onerror=|onclick=|<iframe|<embed|<object)/i,
126
+ PATH_TRAVERSAL: /(?:\.\.\/|\.\.\\|%2e%2e%2f|%252e%252e%252f)/i,
127
+ URL_ENCODED: /%[0-9a-f]{2}/i,
128
+ BASE64_DATA: /data:[^;]+;base64,/i
129
+ };
130
+ /**
131
+ * Maximum input length for pattern matching. UAs, header values, and
132
+ * detection payloads are bounded in practice (<4KB even for the most
133
+ * verbose Chrome/Firefox UAs). Caps worst-case complexity for any
134
+ * polynomial-shaped pattern an external caller might supply to
135
+ * `testPattern` / `extractMatch`; CodeQL flagged the unbounded path
136
+ * (js/polynomial-redos) on PR #2576.
137
+ */
138
+ const MAX_PATTERN_INPUT_LENGTH = 4096;
139
+ /**
140
+ * Helper function to test a pattern. Returns `false` on inputs longer
141
+ * than {@link MAX_PATTERN_INPUT_LENGTH} — an abuse signal we'd rather
142
+ * reject than process.
143
+ */
144
+ function testPattern(pattern, value) {
145
+ if (value.length > MAX_PATTERN_INPUT_LENGTH) return false;
146
+ return pattern.test(value);
147
+ }
148
+ /**
149
+ * Helper function to extract match from pattern. Returns `null` on
150
+ * over-long inputs (same ReDoS defense as `testPattern`).
151
+ */
152
+ function extractMatch(pattern, value) {
153
+ if (value.length > MAX_PATTERN_INPUT_LENGTH) return null;
154
+ const match = value.match(pattern);
155
+ return match ? match[1] || match[0] : null;
156
+ }
157
+ /**
158
+ * Helper function to test multiple patterns
159
+ */
160
+ function testPatterns(patterns, value) {
161
+ return patterns.some((pattern) => testPattern(pattern, value));
162
+ }
163
+ /**
164
+ * Helper function to find matching pattern
165
+ */
166
+ function findMatchingPattern(patterns, value) {
167
+ for (const [name, pattern] of Object.entries(patterns)) if (testPattern(pattern, value)) return name;
168
+ return null;
169
+ }
170
+
171
+ //#endregion
172
+ //#region src/posture-origins/index.ts
173
+ /**
174
+ * Posture origins: which page origins a project's browser posture token may
175
+ * be issued for (and, at the edge gateway, accepted on).
176
+ *
177
+ * The primary origin is derived from `project.domain`. A project can add up
178
+ * to {@link MAX_POSTURE_ORIGINS} more in `settings.postureOrigins`, for the
179
+ * installs a single varchar cannot describe: a Shopify store whose shoppers
180
+ * browse a custom domain while `project.domain` is the myshopify host, `www`
181
+ * next to the apex, a staging host, several storefront domains.
182
+ *
183
+ * One resolver, used by every caller (the beacon issuer, the settings APIs,
184
+ * the dashboard editor, the gateway verifier, the beacon-ingest Worker), so
185
+ * what the dashboard accepts, what the issuer signs and what the gateway
186
+ * verifies can never drift apart.
187
+ *
188
+ * Pure, dependency-free, Web-standard `URL` only: safe in Node, the browser
189
+ * and Cloudflare Workers. `URL` also gives consistent IDN handling: a
190
+ * Unicode host is converted to its punycode (`xn--`) form everywhere, which
191
+ * is exactly how a browser serializes the `Origin` header.
192
+ *
193
+ * Pattern rules (the stored form is always normalized):
194
+ * - `https://host[:port]`: an exact origin. HTTPS only, with no localhost
195
+ * exception, because the posture signer (`signBrowserPosture`) refuses any
196
+ * non-HTTPS audience anyway.
197
+ * - A bare `host` is read as `https://host`. Paths, a trailing slash, query
198
+ * and fragment are stripped; userinfo (`user@host`) is rejected.
199
+ * - `https://*.example.com`: matches any origin ONE OR MORE labels below
200
+ * `example.com` (`a.example.com`, `a.b.example.com`), same scheme and port.
201
+ * It never matches the apex `example.com`; list that separately. The
202
+ * wildcard is allowed only as the whole leftmost label.
203
+ * - A wildcard over a public or multi-tenant suffix is rejected
204
+ * (`*.com`, `*.co.uk`, `*.myshopify.com`, `*.vercel.app`, ...): it would
205
+ * let any tenant of that platform mint posture for this project.
206
+ *
207
+ * @example
208
+ * const allowed = resolveProjectAllowedOrigins({
209
+ * domain: 'checkpoint-rebrand.myshopify.com',
210
+ * settings: { postureOrigins: ['https://www.brand.com', 'https://*.brand.com'] },
211
+ * });
212
+ * matchAllowedOrigin('https://shop.brand.com', allowed); // 'https://shop.brand.com'
213
+ * matchAllowedOrigin('https://brand.com', allowed); // undefined (apex not listed)
214
+ */
215
+ const MAX_POSTURE_ORIGINS = 20;
216
+ /** Longest accepted entry: `https://` + a 253-char host + `:65535`, with headroom. */
217
+ const MAX_POSTURE_ORIGIN_LENGTH = 300;
218
+ /**
219
+ * Multi-tenant hosting suffixes a customer does not control the siblings of.
220
+ * A wildcard AT or anywhere BELOW one of these is refused, because platforms
221
+ * nest tenant namespaces (`*.s3.us-east-1.amazonaws.com`, `*.a.run.app`,
222
+ * `*.blob.core.windows.net`). An exact tenant host (`https://brand.myshopify.com`)
223
+ * is still accepted.
224
+ *
225
+ * The public-suffix list is not a dependency of this package (it would ship
226
+ * to the dashboard bundle and both Workers), so this is a curated list plus
227
+ * the structural checks in {@link isPublicSuffixLike}. It is not complete:
228
+ * adopting the PSL private section (e.g. `tldts`) is the full fix.
229
+ */
230
+ const MULTI_TENANT_SUFFIXES = /* @__PURE__ */ new Set([
231
+ "myshopify.com",
232
+ "shopifypreview.com",
233
+ "myshopline.com",
234
+ "mybigcommerce.com",
235
+ "bigcartel.com",
236
+ "company.site",
237
+ "square.site",
238
+ "wixsite.com",
239
+ "wixstudio.io",
240
+ "squarespace.com",
241
+ "webflow.io",
242
+ "framer.app",
243
+ "framer.website",
244
+ "carrd.co",
245
+ "weebly.com",
246
+ "godaddysites.com",
247
+ "mystrikingly.com",
248
+ "hs-sites.com",
249
+ "hubspotpagebuilder.com",
250
+ "myportfolio.com",
251
+ "notion.site",
252
+ "ghost.io",
253
+ "substack.com",
254
+ "tumblr.com",
255
+ "blogspot.com",
256
+ "wordpress.com",
257
+ "wpengine.com",
258
+ "wpenginepowered.com",
259
+ "pantheonsite.io",
260
+ "kinsta.cloud",
261
+ "gitbook.io",
262
+ "bubbleapps.io",
263
+ "neocities.org",
264
+ "lovable.app",
265
+ "lovable.dev",
266
+ "replit.app",
267
+ "replit.dev",
268
+ "repl.co",
269
+ "glitch.me",
270
+ "vusercontent.net",
271
+ "csb.app",
272
+ "codesandbox.io",
273
+ "stackblitz.io",
274
+ "webcontainer.io",
275
+ "streamlit.app",
276
+ "hf.space",
277
+ "gradio.live",
278
+ "pythonanywhere.com",
279
+ "vercel.app",
280
+ "now.sh",
281
+ "netlify.app",
282
+ "netlify.com",
283
+ "pages.dev",
284
+ "workers.dev",
285
+ "r2.dev",
286
+ "github.io",
287
+ "github.dev",
288
+ "gitlab.io",
289
+ "herokuapp.com",
290
+ "onrender.com",
291
+ "fly.dev",
292
+ "railway.app",
293
+ "koyeb.app",
294
+ "deno.dev",
295
+ "surge.sh",
296
+ "ondigitalocean.app",
297
+ "digitaloceanspaces.com",
298
+ "gitpod.io",
299
+ "amazonaws.com",
300
+ "amplifyapp.com",
301
+ "awsapprunner.com",
302
+ "elasticbeanstalk.com",
303
+ "cloudfront.net",
304
+ "azurewebsites.net",
305
+ "azurestaticapps.net",
306
+ "azurecontainerapps.io",
307
+ "azureedge.net",
308
+ "azurefd.net",
309
+ "azure-api.net",
310
+ "cloudapp.net",
311
+ "cloudapp.azure.com",
312
+ "windows.net",
313
+ "run.app",
314
+ "web.app",
315
+ "firebaseapp.com",
316
+ "firebasestorage.app",
317
+ "appspot.com",
318
+ "googleapis.com",
319
+ "googleusercontent.com",
320
+ "translate.goog",
321
+ "fastly.net",
322
+ "akamaized.net",
323
+ "akamaihd.net",
324
+ "edgekey.net",
325
+ "edgesuite.net",
326
+ "b-cdn.net",
327
+ "cloudflarestorage.com",
328
+ "supabase.co",
329
+ "ngrok.io",
330
+ "ngrok.app",
331
+ "ngrok.dev",
332
+ "ngrok-free.app",
333
+ "ngrok-free.dev",
334
+ "trycloudflare.com",
335
+ "loca.lt"
336
+ ]);
337
+ /** Common second-level labels under a two-letter country TLD (`co.uk`, `com.au`, `ne.jp`). */
338
+ const CCTLD_SECOND_LEVEL_LABELS = /* @__PURE__ */ new Set([
339
+ "ac",
340
+ "biz",
341
+ "co",
342
+ "com",
343
+ "edu",
344
+ "gen",
345
+ "go",
346
+ "gob",
347
+ "gov",
348
+ "info",
349
+ "ltd",
350
+ "me",
351
+ "mil",
352
+ "ne",
353
+ "net",
354
+ "nic",
355
+ "or",
356
+ "org",
357
+ "plc",
358
+ "sch"
359
+ ]);
360
+ const WILDCARD_PROBE_LABEL = "posture-origin-wildcard-probe";
361
+ /**
362
+ * True when a wildcard directly over `host` would cover sites the customer
363
+ * does not control: a single label (`com`), a common ccTLD second level
364
+ * (`co.uk`, `com.au`), or a known multi-tenant platform suffix or any host
365
+ * below one (`myshopify.com`, `s3.us-east-1.amazonaws.com`). A heuristic,
366
+ * not the full PSL.
367
+ */
368
+ function isPublicSuffixLike(host) {
369
+ const labels = host.split(".");
370
+ if (labels.length < 2) return true;
371
+ for (let index = 0; index < labels.length - 1; index++) if (MULTI_TENANT_SUFFIXES.has(labels.slice(index).join("."))) return true;
372
+ if (labels.length === 2) {
373
+ const [second, top] = labels;
374
+ if (top.length === 2 && CCTLD_SECOND_LEVEL_LABELS.has(second)) return true;
375
+ }
376
+ return false;
377
+ }
378
+ function isIpLiteral(host) {
379
+ return host.startsWith("[") || /^\d+(\.\d+){3}$/.test(host);
380
+ }
381
+ /**
382
+ * Validates and normalizes one allowlist entry. Returns a human-readable
383
+ * error for the settings API's 400 and the dashboard editor.
384
+ */
385
+ function parseOriginPattern(input) {
386
+ const trimmed = typeof input === "string" ? input.trim() : "";
387
+ if (!trimmed) return {
388
+ ok: false,
389
+ error: "Enter an origin such as https://www.example.com"
390
+ };
391
+ if (trimmed.length > 300) return {
392
+ ok: false,
393
+ error: `Must be at most ${300} characters`
394
+ };
395
+ const schemeMatch = /^([a-z][a-z0-9+.-]*):\/\//i.exec(trimmed);
396
+ if (schemeMatch && schemeMatch[1].toLowerCase() !== "https") return {
397
+ ok: false,
398
+ error: "Only https:// origins are supported"
399
+ };
400
+ const rest = schemeMatch ? trimmed.slice(schemeMatch[0].length) : trimmed;
401
+ const wildcard = rest.startsWith("*.");
402
+ const withoutWildcard = wildcard ? rest.slice(2) : rest;
403
+ if (withoutWildcard.includes("*")) return {
404
+ ok: false,
405
+ error: "A wildcard is only allowed as the whole first label, e.g. https://*.example.com"
406
+ };
407
+ let url;
408
+ try {
409
+ url = new URL(`https://${wildcard ? `${WILDCARD_PROBE_LABEL}.` : ""}${withoutWildcard}`);
410
+ } catch {
411
+ return {
412
+ ok: false,
413
+ error: "Not a valid origin"
414
+ };
415
+ }
416
+ if (url.username || url.password) return {
417
+ ok: false,
418
+ error: "Origins cannot contain a username or password"
419
+ };
420
+ let host = url.hostname;
421
+ if (wildcard) host = host.slice(30);
422
+ if (!host || host.endsWith(".") || host.startsWith(".")) return {
423
+ ok: false,
424
+ error: "Not a valid host name"
425
+ };
426
+ if (isIpLiteral(host)) return {
427
+ ok: false,
428
+ error: "Use a domain name, not an IP address"
429
+ };
430
+ if (wildcard && isPublicSuffixLike(host)) return {
431
+ ok: false,
432
+ error: `*.${host} would include sites you do not control; list your own hosts instead`
433
+ };
434
+ if (!host.includes(".")) return {
435
+ ok: false,
436
+ error: "Use a fully qualified domain, e.g. www.example.com"
437
+ };
438
+ const port = url.port;
439
+ if (port === "0") return {
440
+ ok: false,
441
+ error: "Not a valid port"
442
+ };
443
+ return {
444
+ ok: true,
445
+ value: {
446
+ pattern: `https://${wildcard ? "*." : ""}${host}${port ? `:${port}` : ""}`,
447
+ wildcard,
448
+ host,
449
+ port
450
+ }
451
+ };
452
+ }
453
+ /**
454
+ * Validates a full allowlist from an API body or the editor: every entry
455
+ * must parse, the list is capped, and duplicates (after normalization) are
456
+ * removed while keeping first-seen order.
457
+ */
458
+ function validatePostureOrigins(input) {
459
+ if (!Array.isArray(input)) return {
460
+ ok: false,
461
+ errors: [{
462
+ index: -1,
463
+ message: "Expected a list of origins"
464
+ }]
465
+ };
466
+ if (input.length > 20) return {
467
+ ok: false,
468
+ errors: [{
469
+ index: -1,
470
+ message: `At most ${20} additional origins`
471
+ }]
472
+ };
473
+ const errors = [];
474
+ const origins = [];
475
+ input.forEach((entry, index) => {
476
+ if (typeof entry !== "string") {
477
+ errors.push({
478
+ index,
479
+ message: "Each origin must be a string"
480
+ });
481
+ return;
482
+ }
483
+ const parsed = parseOriginPattern(entry);
484
+ if (!parsed.ok) {
485
+ errors.push({
486
+ index,
487
+ message: parsed.error
488
+ });
489
+ return;
490
+ }
491
+ if (!origins.includes(parsed.value.pattern)) origins.push(parsed.value.pattern);
492
+ });
493
+ return errors.length > 0 ? {
494
+ ok: false,
495
+ errors
496
+ } : {
497
+ ok: true,
498
+ origins
499
+ };
500
+ }
501
+ /**
502
+ * Returns the page origin when it matches one of `allowed`, else undefined.
503
+ * The page origin must already be in the browser's serialized form
504
+ * (`https://host[:port]`, lowercase, no path); anything else, including the
505
+ * opaque `null` origin, never matches. The value returned is the page origin
506
+ * itself, never a pattern, so a signed audience is always a concrete origin.
507
+ */
508
+ function matchAllowedOrigin(pageOrigin, allowed) {
509
+ if (!pageOrigin || allowed.length === 0) return void 0;
510
+ let url;
511
+ try {
512
+ url = new URL(pageOrigin);
513
+ } catch {
514
+ return;
515
+ }
516
+ if (url.protocol !== "https:" || url.origin !== pageOrigin) return void 0;
517
+ const host = url.hostname;
518
+ if (host.includes("*")) return void 0;
519
+ for (const entry of allowed) {
520
+ const parsed = parseOriginPattern(entry);
521
+ if (!parsed.ok || parsed.value.port !== url.port) continue;
522
+ const { wildcard, host: patternHost } = parsed.value;
523
+ if (!wildcard) {
524
+ if (host === patternHost) return pageOrigin;
525
+ continue;
526
+ }
527
+ if (host.length > patternHost.length + 1 && host.endsWith(`.${patternHost}`)) return pageOrigin;
528
+ }
529
+ }
530
+
531
+ //#endregion
532
+ Object.defineProperty(exports, 'BROWSER_PATTERNS', {
533
+ enumerable: true,
534
+ get: function () {
535
+ return BROWSER_PATTERNS;
536
+ }
537
+ });
538
+ Object.defineProperty(exports, 'HEADER_PATTERNS', {
539
+ enumerable: true,
540
+ get: function () {
541
+ return HEADER_PATTERNS;
542
+ }
543
+ });
544
+ Object.defineProperty(exports, 'MOBILE_PATTERNS', {
545
+ enumerable: true,
546
+ get: function () {
547
+ return MOBILE_PATTERNS;
548
+ }
549
+ });
550
+ Object.defineProperty(exports, 'OS_PATTERNS', {
551
+ enumerable: true,
552
+ get: function () {
553
+ return OS_PATTERNS;
554
+ }
555
+ });
556
+ Object.defineProperty(exports, 'SUSPICIOUS_PATTERNS', {
557
+ enumerable: true,
558
+ get: function () {
559
+ return SUSPICIOUS_PATTERNS;
560
+ }
561
+ });
562
+ Object.defineProperty(exports, 'USER_AGENT_PATTERNS', {
563
+ enumerable: true,
564
+ get: function () {
565
+ return USER_AGENT_PATTERNS;
566
+ }
567
+ });
568
+ Object.defineProperty(exports, 'UUID_PATTERN', {
569
+ enumerable: true,
570
+ get: function () {
571
+ return UUID_PATTERN;
572
+ }
573
+ });
574
+ Object.defineProperty(exports, 'VALIDATION_PATTERNS', {
575
+ enumerable: true,
576
+ get: function () {
577
+ return VALIDATION_PATTERNS;
578
+ }
579
+ });
580
+ Object.defineProperty(exports, 'extractMatch', {
581
+ enumerable: true,
582
+ get: function () {
583
+ return extractMatch;
584
+ }
585
+ });
586
+ Object.defineProperty(exports, 'findMatchingPattern', {
587
+ enumerable: true,
588
+ get: function () {
589
+ return findMatchingPattern;
590
+ }
591
+ });
592
+ Object.defineProperty(exports, 'matchAllowedOrigin', {
593
+ enumerable: true,
594
+ get: function () {
595
+ return matchAllowedOrigin;
596
+ }
597
+ });
598
+ Object.defineProperty(exports, 'parseOriginPattern', {
599
+ enumerable: true,
600
+ get: function () {
601
+ return parseOriginPattern;
602
+ }
603
+ });
604
+ Object.defineProperty(exports, 'testPattern', {
605
+ enumerable: true,
606
+ get: function () {
607
+ return testPattern;
608
+ }
609
+ });
610
+ Object.defineProperty(exports, 'testPatterns', {
611
+ enumerable: true,
612
+ get: function () {
613
+ return testPatterns;
614
+ }
615
+ });
616
+ Object.defineProperty(exports, 'validatePostureOrigins', {
617
+ enumerable: true,
618
+ get: function () {
619
+ return validatePostureOrigins;
620
+ }
621
+ });