@vm0/cli 9.222.2 → 9.222.3

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 (82) hide show
  1. package/{agent-MAPPQJ6T.js → agent-LPPBYNS2.js} +4 -4
  2. package/{automation-Z4A56FZU.js → automation-BB4N3JL7.js} +5 -5
  3. package/{banking-EI7CVZ5K.js → banking-WAVEYEQR.js} +2 -2
  4. package/{chat-2C6KFXSA.js → chat-WLUTTBQU.js} +2 -2
  5. package/{chunk-E2O7MDL7.js → chunk-3QZMZ46V.js} +126 -1
  6. package/{chunk-E2O7MDL7.js.map → chunk-3QZMZ46V.js.map} +1 -1
  7. package/{chunk-EYFVTA5E.js → chunk-4IPZWDAI.js} +3 -3
  8. package/{chunk-EEKLQFJU.js → chunk-5FY5RVWK.js} +3 -3
  9. package/chunk-72DXWQL4.js +1178 -0
  10. package/chunk-72DXWQL4.js.map +1 -0
  11. package/{chunk-IH5XFOOD.js → chunk-A5RF3VZM.js} +2 -2
  12. package/{chunk-KA6H24H6.js → chunk-K7F6VF2Z.js} +2 -2
  13. package/{chunk-TTPLNGWS.js → chunk-OFENJD2Q.js} +7 -5
  14. package/{chunk-TTPLNGWS.js.map → chunk-OFENJD2Q.js.map} +1 -1
  15. package/{chunk-UX5MX23W.js → chunk-V2NS7MND.js} +2 -2
  16. package/{chunk-X6DLTGXJ.js → chunk-XX44OKQX.js} +2 -2
  17. package/{computer-use-UUJJLFRO.js → computer-use-V7RXYM5A.js} +2 -2
  18. package/{connector-IT2BLPVI.js → connector-ZFFOQO63.js} +2 -2
  19. package/{credit-ZT4YJEEV.js → credit-O3ELRY7X.js} +2 -2
  20. package/{developer-support-GUZAND2T.js → developer-support-2VYEJ4UE.js} +2 -2
  21. package/{doctor-GRCIJPEA.js → doctor-F5ETPBLW.js} +261 -65
  22. package/doctor-F5ETPBLW.js.map +1 -0
  23. package/{generate-CNZ6H26I.js → generate-MESJMO2O.js} +2 -2
  24. package/{github-B4RSWWQK.js → github-3QYZVKIQ.js} +2 -2
  25. package/{goal-BVS7HE23.js → goal-A5RMK7GY.js} +2 -2
  26. package/{host-7MWUCOLE.js → host-3R44HEX5.js} +2 -2
  27. package/index.js +13 -13
  28. package/{logs-EU6MWKYR.js → logs-TCWPJYIU.js} +6 -6
  29. package/{maps-KJNJ7JL4.js → maps-OADWY7SG.js} +2 -2
  30. package/{model-WQF5A6U4.js → model-VEADPWRX.js} +3 -3
  31. package/{model-provider-ELNWOZW4.js → model-provider-SHA27BOM.js} +3 -3
  32. package/{org-PCKII2IU.js → org-MI6FIM3U.js} +2 -2
  33. package/package.json +1 -1
  34. package/{phone-OJVOUMKG.js → phone-IIC43L5Z.js} +2 -2
  35. package/{preference-54AUYVYH.js → preference-JE7EYXOC.js} +2 -2
  36. package/{resource-OJ3ISHQ5.js → resource-Q646DK57.js} +2 -2
  37. package/{search-25UMJA56.js → search-5A5HM5EN.js} +6 -6
  38. package/{secret-UJZX3EGP.js → secret-JGEU4F2W.js} +3 -3
  39. package/{slack-ZFFQCZAW.js → slack-QLEY2HSE.js} +2 -2
  40. package/{telegram-2UPWXOIH.js → telegram-UCBPY4FU.js} +2 -2
  41. package/{variable-OPU6O75U.js → variable-XB45XMPQ.js} +2 -2
  42. package/{web-DEL3WDWU.js → web-DWIOAOMH.js} +2 -2
  43. package/{whoami-PSGS3D2Q.js → whoami-P7LQBBTB.js} +4 -4
  44. package/{workflow-K63JX3OF.js → workflow-ETGLSZ5Y.js} +2 -2
  45. package/zero.js +31 -31
  46. package/chunk-ODQBZESC.js +0 -612
  47. package/chunk-ODQBZESC.js.map +0 -1
  48. package/doctor-GRCIJPEA.js.map +0 -1
  49. /package/{agent-MAPPQJ6T.js.map → agent-LPPBYNS2.js.map} +0 -0
  50. /package/{automation-Z4A56FZU.js.map → automation-BB4N3JL7.js.map} +0 -0
  51. /package/{banking-EI7CVZ5K.js.map → banking-WAVEYEQR.js.map} +0 -0
  52. /package/{chat-2C6KFXSA.js.map → chat-WLUTTBQU.js.map} +0 -0
  53. /package/{chunk-EYFVTA5E.js.map → chunk-4IPZWDAI.js.map} +0 -0
  54. /package/{chunk-EEKLQFJU.js.map → chunk-5FY5RVWK.js.map} +0 -0
  55. /package/{chunk-IH5XFOOD.js.map → chunk-A5RF3VZM.js.map} +0 -0
  56. /package/{chunk-KA6H24H6.js.map → chunk-K7F6VF2Z.js.map} +0 -0
  57. /package/{chunk-UX5MX23W.js.map → chunk-V2NS7MND.js.map} +0 -0
  58. /package/{chunk-X6DLTGXJ.js.map → chunk-XX44OKQX.js.map} +0 -0
  59. /package/{computer-use-UUJJLFRO.js.map → computer-use-V7RXYM5A.js.map} +0 -0
  60. /package/{connector-IT2BLPVI.js.map → connector-ZFFOQO63.js.map} +0 -0
  61. /package/{credit-ZT4YJEEV.js.map → credit-O3ELRY7X.js.map} +0 -0
  62. /package/{developer-support-GUZAND2T.js.map → developer-support-2VYEJ4UE.js.map} +0 -0
  63. /package/{generate-CNZ6H26I.js.map → generate-MESJMO2O.js.map} +0 -0
  64. /package/{github-B4RSWWQK.js.map → github-3QYZVKIQ.js.map} +0 -0
  65. /package/{goal-BVS7HE23.js.map → goal-A5RMK7GY.js.map} +0 -0
  66. /package/{host-7MWUCOLE.js.map → host-3R44HEX5.js.map} +0 -0
  67. /package/{logs-EU6MWKYR.js.map → logs-TCWPJYIU.js.map} +0 -0
  68. /package/{maps-KJNJ7JL4.js.map → maps-OADWY7SG.js.map} +0 -0
  69. /package/{model-WQF5A6U4.js.map → model-VEADPWRX.js.map} +0 -0
  70. /package/{model-provider-ELNWOZW4.js.map → model-provider-SHA27BOM.js.map} +0 -0
  71. /package/{org-PCKII2IU.js.map → org-MI6FIM3U.js.map} +0 -0
  72. /package/{phone-OJVOUMKG.js.map → phone-IIC43L5Z.js.map} +0 -0
  73. /package/{preference-54AUYVYH.js.map → preference-JE7EYXOC.js.map} +0 -0
  74. /package/{resource-OJ3ISHQ5.js.map → resource-Q646DK57.js.map} +0 -0
  75. /package/{search-25UMJA56.js.map → search-5A5HM5EN.js.map} +0 -0
  76. /package/{secret-UJZX3EGP.js.map → secret-JGEU4F2W.js.map} +0 -0
  77. /package/{slack-ZFFQCZAW.js.map → slack-QLEY2HSE.js.map} +0 -0
  78. /package/{telegram-2UPWXOIH.js.map → telegram-UCBPY4FU.js.map} +0 -0
  79. /package/{variable-OPU6O75U.js.map → variable-XB45XMPQ.js.map} +0 -0
  80. /package/{web-DEL3WDWU.js.map → web-DWIOAOMH.js.map} +0 -0
  81. /package/{whoami-PSGS3D2Q.js.map → whoami-P7LQBBTB.js.map} +0 -0
  82. /package/{workflow-K63JX3OF.js.map → workflow-ETGLSZ5Y.js.map} +0 -0
@@ -0,0 +1,1178 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __createRequire } from "node:module";
3
+ const require = __createRequire(import.meta.url);
4
+ import {
5
+ hasBaseUrlParams,
6
+ hasRawWhitespace,
7
+ hasUnsafeFirewallPath,
8
+ hasUnsafeUrlCodepoint,
9
+ parseSegment,
10
+ splitPathSegments,
11
+ validateAuthBaseUrl,
12
+ validateBaseUrl
13
+ } from "./chunk-3QZMZ46V.js";
14
+ import {
15
+ init_esm_shims
16
+ } from "./chunk-DIRAZ3YX.js";
17
+
18
+ // ../../packages/connectors/src/firewall-rule-matcher.ts
19
+ init_esm_shims();
20
+ var VALID_RULE_METHODS = /* @__PURE__ */ new Set([
21
+ "GET",
22
+ "POST",
23
+ "PUT",
24
+ "PATCH",
25
+ "DELETE",
26
+ "HEAD",
27
+ "OPTIONS",
28
+ "ANY"
29
+ ]);
30
+ var FORBIDDEN_RUNTIME_HOST_CHARS = new Set("#%*,/<>?@\\^|{}".split(""));
31
+ var FORBIDDEN_BASE_PATTERN_HOST_CHARS = new Set("#%,/<>?@\\^|".split(""));
32
+ var PERCENT_ESCAPE_LENGTH = 3;
33
+ var HEX_DIGITS = new Set("0123456789abcdefABCDEF".split(""));
34
+ var PATH_SCORE_MULTIPLIER = 1e6;
35
+ var AUTHORITY_SCORE_MULTIPLIER = 100;
36
+ var LITERAL_SEGMENT_SCORE = 1e3;
37
+ var MIXED_PARAM_SEGMENT_SCORE = 100;
38
+ var PLAIN_PARAM_SEGMENT_SCORE = 10;
39
+ var PLUS_GREEDY_SEGMENT_SCORE = 1;
40
+ var ROOT_PATH_SCORE = 1;
41
+ var STATIC_BASE_SCORE_BONUS = 1;
42
+ var PERCENT_DECODED_AUTHORITY_SYNTAX_CHARS = /* @__PURE__ */ new Set([
43
+ "{",
44
+ "}",
45
+ "*",
46
+ ".",
47
+ "\u3002",
48
+ "\uFF0E",
49
+ "\uFF61",
50
+ ":"
51
+ ]);
52
+ function matchMixedSegment(runtime, prefix, suffix) {
53
+ if (!runtime.startsWith(prefix)) return null;
54
+ if (!runtime.endsWith(suffix)) return null;
55
+ if (runtime.length <= prefix.length + suffix.length) return null;
56
+ return runtime.slice(prefix.length, runtime.length - suffix.length);
57
+ }
58
+ function hasNonEmptySegment(segments, start) {
59
+ for (let i = start; i < segments.length; i++) {
60
+ if (segments[i] !== "") return true;
61
+ }
62
+ return false;
63
+ }
64
+ function codePointLength(value) {
65
+ return [...value].length;
66
+ }
67
+ function hasUnsafeRuntimeUrlSyntax(value) {
68
+ return hasUnsafeUrlCodepoint(value) || hasRawWhitespace(value) || value.includes("\\") || !value.includes("://");
69
+ }
70
+ function stripTrailingSlash(value) {
71
+ return value.endsWith("/") ? value.slice(0, -1) : value;
72
+ }
73
+ function isInvalidGreedyParam(patternIndex, lastPatternIndex, prefix, suffix) {
74
+ return patternIndex !== lastPatternIndex || prefix !== "" || suffix !== "";
75
+ }
76
+ function parseStrictMatchSegment(segment, patternIndex, lastPatternIndex) {
77
+ const parsed = parseSegment(segment);
78
+ if (parsed.kind === "error") return null;
79
+ if (parsed.kind === "param" && parsed.greedy !== "" && isInvalidGreedyParam(
80
+ patternIndex,
81
+ lastPatternIndex,
82
+ parsed.prefix,
83
+ parsed.suffix
84
+ )) {
85
+ return null;
86
+ }
87
+ return parsed;
88
+ }
89
+ function pathSpecificity(pattern) {
90
+ if (!pattern.startsWith("/") || pattern.includes("?") || pattern.includes("#") || pattern.includes("\\") || hasRawWhitespace(pattern) || hasUnsafeUrlCodepoint(pattern)) {
91
+ return null;
92
+ }
93
+ let literalSegments = 0;
94
+ let mixedParamSegments = 0;
95
+ let plainParamSegments = 0;
96
+ let plusGreedySegments = 0;
97
+ let starGreedySegments = 0;
98
+ let literalChars = 0;
99
+ const segments = splitPathSegments(pattern);
100
+ const paramNames = /* @__PURE__ */ new Set();
101
+ const lastSegmentIndex = segments.length - 1;
102
+ for (let index = 0; index < segments.length; index += 1) {
103
+ const seg = segments[index];
104
+ const parsed = parseSegment(seg);
105
+ if (parsed.kind === "error") return null;
106
+ if (parsed.kind === "literal") {
107
+ literalSegments += 1;
108
+ literalChars += codePointLength(parsed.value);
109
+ continue;
110
+ }
111
+ if (paramNames.has(parsed.name)) return null;
112
+ paramNames.add(parsed.name);
113
+ if (parsed.greedy !== "" && isInvalidGreedyParam(
114
+ index,
115
+ lastSegmentIndex,
116
+ parsed.prefix,
117
+ parsed.suffix
118
+ )) {
119
+ return null;
120
+ }
121
+ literalChars += codePointLength(parsed.prefix) + codePointLength(parsed.suffix);
122
+ if (parsed.prefix !== "" || parsed.suffix !== "") {
123
+ mixedParamSegments += 1;
124
+ } else if (parsed.greedy === "+") {
125
+ plusGreedySegments += 1;
126
+ } else if (parsed.greedy === "*") {
127
+ starGreedySegments += 1;
128
+ } else {
129
+ plainParamSegments += 1;
130
+ }
131
+ }
132
+ return [
133
+ literalSegments,
134
+ mixedParamSegments,
135
+ plainParamSegments,
136
+ plusGreedySegments,
137
+ -starGreedySegments,
138
+ literalChars,
139
+ segments.length
140
+ ];
141
+ }
142
+ function comparePathSpecificity(left, right) {
143
+ for (let i = 0; i < left.length; i++) {
144
+ const difference = left[i] - right[i];
145
+ if (difference !== 0) return difference;
146
+ }
147
+ return 0;
148
+ }
149
+ function compileDecisionRule(permission, rule) {
150
+ const spaceIdx = rule.indexOf(" ");
151
+ if (spaceIdx === -1) return null;
152
+ const method = rule.slice(0, spaceIdx);
153
+ if (!VALID_RULE_METHODS.has(method)) return null;
154
+ const path = rule.slice(spaceIdx + 1);
155
+ const specificity = pathSpecificity(path);
156
+ if (specificity === null) return null;
157
+ return { permission, raw: rule, method, path, specificity };
158
+ }
159
+ function isValidPermissionName(permissionName) {
160
+ return permissionName !== "" && permissionName !== "all";
161
+ }
162
+ function isObjectRecord(value) {
163
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
164
+ return false;
165
+ }
166
+ const prototype = Object.getPrototypeOf(value);
167
+ return prototype === Object.prototype || prototype === null;
168
+ }
169
+ function isStringRecord(value) {
170
+ if (!isObjectRecord(value)) return false;
171
+ return Object.values(value).every((entry) => {
172
+ return typeof entry === "string";
173
+ });
174
+ }
175
+ function hasEntries(value) {
176
+ return value !== void 0 && Object.keys(value).length > 0;
177
+ }
178
+ function isValidAwsSigv4AuthConfig(value) {
179
+ if (!isObjectRecord(value)) return false;
180
+ const allowedKeys = /* @__PURE__ */ new Set([
181
+ "accessKeyId",
182
+ "secretAccessKey",
183
+ "sessionToken"
184
+ ]);
185
+ if (Object.keys(value).some((key) => {
186
+ return !allowedKeys.has(key);
187
+ })) {
188
+ return false;
189
+ }
190
+ if (typeof value.accessKeyId !== "string" || value.accessKeyId === "") {
191
+ return false;
192
+ }
193
+ if (typeof value.secretAccessKey !== "string" || value.secretAccessKey === "") {
194
+ return false;
195
+ }
196
+ const optionalValue = value.sessionToken;
197
+ if (optionalValue !== void 0 && (typeof optionalValue !== "string" || optionalValue === "")) {
198
+ return false;
199
+ }
200
+ return true;
201
+ }
202
+ function isValidAuthConfig(auth, serviceName) {
203
+ if (!isObjectRecord(auth)) return false;
204
+ if (auth.headers !== void 0 && !isStringRecord(auth.headers)) return false;
205
+ if (auth.query !== void 0 && !isStringRecord(auth.query)) return false;
206
+ if (auth.awsSigv4 !== void 0 && !isValidAwsSigv4AuthConfig(auth.awsSigv4)) {
207
+ return false;
208
+ }
209
+ if (auth.awsSigv4 !== void 0) {
210
+ if (hasEntries(auth.headers)) {
211
+ return false;
212
+ }
213
+ if (hasEntries(auth.query)) {
214
+ return false;
215
+ }
216
+ }
217
+ if (auth.base !== void 0) {
218
+ if (typeof auth.base !== "string") return false;
219
+ validateAuthBaseUrl(auth.base, serviceName);
220
+ }
221
+ return true;
222
+ }
223
+ function rawObjectHasOwn(value, key) {
224
+ return Object.prototype.hasOwnProperty.call(value, key);
225
+ }
226
+ function isValidAuthConfigForDecision(auth, serviceName) {
227
+ try {
228
+ return isValidAuthConfig(auth, serviceName);
229
+ } catch {
230
+ return false;
231
+ }
232
+ }
233
+ function compileDecisionApi(api, serviceName, nameMalformed) {
234
+ if (typeof api.base !== "string") return null;
235
+ let baseMalformed = false;
236
+ try {
237
+ validateBaseUrl(api.base, serviceName);
238
+ } catch {
239
+ baseMalformed = true;
240
+ }
241
+ const authMalformed = !isValidAuthConfigForDecision(api.auth, serviceName);
242
+ const rules = [];
243
+ const seenPermissionNames = /* @__PURE__ */ new Set();
244
+ let hasMalformedRules = nameMalformed;
245
+ const rawPermissions = api.permissions;
246
+ if (Array.isArray(rawPermissions)) {
247
+ for (const rawPermission of rawPermissions) {
248
+ if (!isObjectRecord(rawPermission)) {
249
+ hasMalformedRules = true;
250
+ continue;
251
+ }
252
+ const permissionName = rawPermission.name;
253
+ if (typeof permissionName !== "string" || !isValidPermissionName(permissionName)) {
254
+ hasMalformedRules = true;
255
+ continue;
256
+ }
257
+ if (seenPermissionNames.has(permissionName)) {
258
+ hasMalformedRules = true;
259
+ continue;
260
+ }
261
+ seenPermissionNames.add(permissionName);
262
+ const rawRules = rawPermission.rules;
263
+ if (!Array.isArray(rawRules)) {
264
+ hasMalformedRules = true;
265
+ continue;
266
+ }
267
+ if (rawRules.length === 0) {
268
+ hasMalformedRules = true;
269
+ }
270
+ for (const rawRule of rawRules) {
271
+ if (typeof rawRule !== "string") {
272
+ hasMalformedRules = true;
273
+ continue;
274
+ }
275
+ const compiledRule = compileDecisionRule(permissionName, rawRule);
276
+ if (compiledRule === null) {
277
+ hasMalformedRules = true;
278
+ continue;
279
+ }
280
+ rules.push(compiledRule);
281
+ }
282
+ }
283
+ } else if (rawObjectHasOwn(api, "permissions")) {
284
+ hasMalformedRules = true;
285
+ }
286
+ return {
287
+ rawBase: api.base,
288
+ baseMalformed,
289
+ authMalformed,
290
+ hasMalformedRules,
291
+ rules
292
+ };
293
+ }
294
+ function compileDecisionFirewall(rawFirewall) {
295
+ if (!isObjectRecord(rawFirewall)) return null;
296
+ const rawName = rawFirewall.name;
297
+ const nameMalformed = typeof rawName !== "string" || rawName === "";
298
+ const name = typeof rawName === "string" ? rawName : "";
299
+ const rawApis = rawFirewall.apis;
300
+ if (!Array.isArray(rawApis)) return null;
301
+ const apis = [];
302
+ for (const rawApi of rawApis) {
303
+ if (!isObjectRecord(rawApi)) continue;
304
+ const api = compileDecisionApi(rawApi, name, nameMalformed);
305
+ if (api !== null) {
306
+ apis.push(api);
307
+ }
308
+ }
309
+ if (apis.length === 0) return null;
310
+ return { name, nameMalformed, apis };
311
+ }
312
+ function compileDecisionFirewalls(rawFirewalls) {
313
+ if (!Array.isArray(rawFirewalls) || rawFirewalls.length === 0) return [];
314
+ const firewalls = [];
315
+ for (const rawFirewall of rawFirewalls) {
316
+ const firewall = compileDecisionFirewall(rawFirewall);
317
+ if (firewall !== null) {
318
+ firewalls.push(firewall);
319
+ }
320
+ }
321
+ return firewalls;
322
+ }
323
+ function compilePermissionSet(rawValue) {
324
+ if (rawValue === void 0 || rawValue === null) {
325
+ return { values: /* @__PURE__ */ new Set(), malformed: false };
326
+ }
327
+ if (!Array.isArray(rawValue) || rawValue.some((item) => {
328
+ return typeof item !== "string";
329
+ })) {
330
+ return { values: /* @__PURE__ */ new Set(), malformed: true };
331
+ }
332
+ return { values: new Set(rawValue), malformed: false };
333
+ }
334
+ function compileNetworkPolicies(rawNetworkPolicies) {
335
+ if (rawNetworkPolicies === void 0 || rawNetworkPolicies === null) {
336
+ return { policies: /* @__PURE__ */ new Map(), topLevelMalformed: false };
337
+ }
338
+ if (!isObjectRecord(rawNetworkPolicies)) {
339
+ return { policies: /* @__PURE__ */ new Map(), topLevelMalformed: true };
340
+ }
341
+ const policies = /* @__PURE__ */ new Map();
342
+ for (const [firewallName, grant] of Object.entries(rawNetworkPolicies)) {
343
+ if (!isObjectRecord(grant)) {
344
+ policies.set(firewallName, {
345
+ blockedPermissions: /* @__PURE__ */ new Set(),
346
+ unknownPolicy: "allow",
347
+ permissionMalformed: true,
348
+ unknownPolicyMalformed: false
349
+ });
350
+ continue;
351
+ }
352
+ const allow = compilePermissionSet(grant.allow);
353
+ const deny = compilePermissionSet(grant.deny);
354
+ const ask = compilePermissionSet(grant.ask);
355
+ const blockedPermissions = /* @__PURE__ */ new Set([...deny.values, ...ask.values]);
356
+ let unknownPolicy = "allow";
357
+ let unknownPolicyMalformed = false;
358
+ const rawUnknownPolicy = grant.unknownPolicy;
359
+ if (rawUnknownPolicy === "allow" || rawUnknownPolicy === "deny" || rawUnknownPolicy === "ask") {
360
+ unknownPolicy = rawUnknownPolicy;
361
+ } else if (rawUnknownPolicy !== void 0 && rawUnknownPolicy !== null) {
362
+ unknownPolicyMalformed = true;
363
+ }
364
+ policies.set(firewallName, {
365
+ blockedPermissions,
366
+ unknownPolicy,
367
+ permissionMalformed: allow.malformed || deny.malformed || ask.malformed,
368
+ unknownPolicyMalformed
369
+ });
370
+ }
371
+ return { policies, topLevelMalformed: false };
372
+ }
373
+ function relativePathFromSegments(segments, consumed) {
374
+ const rest = segments.slice(consumed).join("/");
375
+ return rest === "" ? "/" : `/${rest}`;
376
+ }
377
+ function stripUrlQueryAndFragment(url) {
378
+ const queryIndex = url.indexOf("?");
379
+ const fragmentIndex = url.indexOf("#");
380
+ let end = url.length;
381
+ if (queryIndex !== -1) end = Math.min(end, queryIndex);
382
+ if (fragmentIndex !== -1) end = Math.min(end, fragmentIndex);
383
+ return url.slice(0, end);
384
+ }
385
+ function rawUrlAuthorityBounds(url) {
386
+ const schemeEnd = url.indexOf("://");
387
+ if (schemeEnd === -1) return null;
388
+ const authorityStart = schemeEnd + 3;
389
+ let authorityEnd = url.length;
390
+ for (const delimiter of ["/", "?", "#"]) {
391
+ const delimiterIndex = url.indexOf(delimiter, authorityStart);
392
+ if (delimiterIndex !== -1)
393
+ authorityEnd = Math.min(authorityEnd, delimiterIndex);
394
+ }
395
+ return { authorityStart, authorityEnd };
396
+ }
397
+ function replaceRawUrlAuthority(url, bounds, authority) {
398
+ return `${url.slice(0, bounds.authorityStart)}${authority}${url.slice(bounds.authorityEnd)}`;
399
+ }
400
+ function stripRawUrlUserinfo(url) {
401
+ const bounds = rawUrlAuthorityBounds(url);
402
+ if (bounds === null) return url;
403
+ const authority = url.slice(bounds.authorityStart, bounds.authorityEnd);
404
+ const userinfoEnd = authority.lastIndexOf("@");
405
+ if (userinfoEnd === -1) return url;
406
+ return replaceRawUrlAuthority(url, bounds, authority.slice(userinfoEnd + 1));
407
+ }
408
+ function rawAuthorityPortIsMalformed(port) {
409
+ if (port === "") return true;
410
+ if (![...port].every((char) => {
411
+ return char >= "0" && char <= "9";
412
+ })) {
413
+ return true;
414
+ }
415
+ return Number(port) > 65535;
416
+ }
417
+ function stripRawUrlMalformedPort(url) {
418
+ const bounds = rawUrlAuthorityBounds(url);
419
+ if (bounds === null) return url;
420
+ const authority = url.slice(bounds.authorityStart, bounds.authorityEnd);
421
+ if (authority.startsWith("[")) {
422
+ const closeBracketIndex = authority.indexOf("]");
423
+ if (closeBracketIndex === -1) return url;
424
+ const portPrefix = authority.slice(closeBracketIndex + 1);
425
+ if (!portPrefix.startsWith(":")) return url;
426
+ if (!rawAuthorityPortIsMalformed(portPrefix.slice(1))) return url;
427
+ return replaceRawUrlAuthority(
428
+ url,
429
+ bounds,
430
+ authority.slice(0, closeBracketIndex + 1)
431
+ );
432
+ }
433
+ const portSeparator = authority.lastIndexOf(":");
434
+ if (portSeparator === -1) return url;
435
+ if (authority.indexOf(":") !== portSeparator) return url;
436
+ if (!rawAuthorityPortIsMalformed(authority.slice(portSeparator + 1))) {
437
+ return url;
438
+ }
439
+ return replaceRawUrlAuthority(url, bounds, authority.slice(0, portSeparator));
440
+ }
441
+ function rawBaseForDecisionMatch(rawBase) {
442
+ if (stripUrlQueryAndFragment(rawBase).includes("\\")) return null;
443
+ return stripRawUrlMalformedPort(stripRawUrlUserinfo(rawBase));
444
+ }
445
+ function rawPathFromUrl(url) {
446
+ const urlWithoutQuery = stripUrlQueryAndFragment(url);
447
+ const schemeEnd = urlWithoutQuery.indexOf("://");
448
+ const authorityStart = schemeEnd === -1 ? 0 : schemeEnd + 3;
449
+ const pathStart = urlWithoutQuery.indexOf("/", authorityStart);
450
+ return pathStart === -1 ? "/" : urlWithoutQuery.slice(pathStart);
451
+ }
452
+ function rawBasePathFromUrl(url) {
453
+ const urlWithoutQuery = stripUrlQueryAndFragment(url);
454
+ const schemeEnd = urlWithoutQuery.indexOf("://");
455
+ const authorityStart = schemeEnd === -1 ? 0 : schemeEnd + 3;
456
+ const pathStart = urlWithoutQuery.indexOf("/", authorityStart);
457
+ return pathStart === -1 ? "" : urlWithoutQuery.slice(pathStart);
458
+ }
459
+ function rawAuthorityFromUrl(url) {
460
+ const urlWithoutQuery = stripUrlQueryAndFragment(url);
461
+ const schemeEnd = urlWithoutQuery.indexOf("://");
462
+ if (schemeEnd === -1) return null;
463
+ const authorityStart = schemeEnd + 3;
464
+ const pathStart = urlWithoutQuery.indexOf("/", authorityStart);
465
+ const authority = pathStart === -1 ? urlWithoutQuery.slice(authorityStart) : urlWithoutQuery.slice(authorityStart, pathStart);
466
+ return authority === "" ? null : authority;
467
+ }
468
+ function hasNonAscii(value) {
469
+ for (let index = 0; index < value.length; index += 1) {
470
+ if (value.charCodeAt(index) > 127) return true;
471
+ }
472
+ return false;
473
+ }
474
+ function rawHostFromAuthority(authority) {
475
+ const withoutUserinfo = authority.slice(authority.lastIndexOf("@") + 1);
476
+ if (withoutUserinfo.startsWith("[")) {
477
+ const closeBracket = withoutUserinfo.indexOf("]");
478
+ return closeBracket === -1 ? withoutUserinfo : withoutUserinfo.slice(0, closeBracket + 1);
479
+ }
480
+ const portSeparator = withoutUserinfo.lastIndexOf(":");
481
+ return portSeparator === -1 ? withoutUserinfo : withoutUserinfo.slice(0, portSeparator);
482
+ }
483
+ function authorityHasEmptyPort(authority) {
484
+ const withoutUserinfo = authority.slice(authority.lastIndexOf("@") + 1);
485
+ if (withoutUserinfo.startsWith("[")) {
486
+ const closeBracket = withoutUserinfo.indexOf("]");
487
+ if (closeBracket === -1) return false;
488
+ return withoutUserinfo.slice(closeBracket + 1) === ":";
489
+ }
490
+ const portSeparator = withoutUserinfo.lastIndexOf(":");
491
+ if (portSeparator === -1) return false;
492
+ return withoutUserinfo.indexOf(":") === portSeparator && portSeparator === withoutUserinfo.length - 1;
493
+ }
494
+ function rawAuthorityHostStartsWithDigit(authority) {
495
+ const firstChar = rawHostFromAuthority(authority)[0];
496
+ return firstChar !== void 0 && firstChar >= "0" && firstChar <= "9";
497
+ }
498
+ function runtimeAuthorityOriginForHostValidation(url) {
499
+ const authority = rawAuthorityFromUrl(url);
500
+ if (authority === null) return null;
501
+ if (!authority.includes("%") && !hasNonAscii(authority) && !rawAuthorityHostStartsWithDigit(authority)) {
502
+ return null;
503
+ }
504
+ const schemeEnd = url.indexOf("://");
505
+ if (schemeEnd === -1) return null;
506
+ return `${url.slice(0, schemeEnd)}://${authority}`;
507
+ }
508
+ function hasPercentEncodedAuthoritySyntax(value) {
509
+ let index = value.indexOf("%");
510
+ while (index !== -1) {
511
+ let runEnd = index;
512
+ while (runEnd < value.length && value[runEnd] === "%") {
513
+ const firstHexDigit = value[runEnd + 1];
514
+ const secondHexDigit = value[runEnd + 2];
515
+ if (!firstHexDigit || !secondHexDigit || !HEX_DIGITS.has(firstHexDigit) || !HEX_DIGITS.has(secondHexDigit)) {
516
+ return true;
517
+ }
518
+ runEnd += PERCENT_ESCAPE_LENGTH;
519
+ }
520
+ let decodedRun;
521
+ try {
522
+ decodedRun = decodeURIComponent(value.slice(index, runEnd));
523
+ } catch {
524
+ return true;
525
+ }
526
+ for (const char of decodedRun) {
527
+ if (PERCENT_DECODED_AUTHORITY_SYNTAX_CHARS.has(char)) {
528
+ return true;
529
+ }
530
+ }
531
+ index = value.indexOf("%", runEnd);
532
+ }
533
+ return false;
534
+ }
535
+ function hasMalformedRuntimeAuthoritySyntax(url) {
536
+ const authority = rawAuthorityFromUrl(url);
537
+ if (authority === null) return false;
538
+ return authority.includes("\\") || authorityHasEmptyPort(authority) || hasPercentEncodedAuthoritySyntax(authority);
539
+ }
540
+ function scoreLiteralSegment(segment) {
541
+ return LITERAL_SEGMENT_SCORE + codePointLength(segment);
542
+ }
543
+ function scoreParsedPatternSegment(parsed) {
544
+ if (parsed.kind === "literal") {
545
+ return scoreLiteralSegment(parsed.value);
546
+ }
547
+ const literalChars = codePointLength(parsed.prefix) + codePointLength(parsed.suffix);
548
+ if (parsed.prefix !== "" || parsed.suffix !== "") {
549
+ return MIXED_PARAM_SEGMENT_SCORE + literalChars;
550
+ }
551
+ if (parsed.greedy === "+") return PLUS_GREEDY_SEGMENT_SCORE;
552
+ if (parsed.greedy === "*") return 0;
553
+ return PLAIN_PARAM_SEGMENT_SCORE;
554
+ }
555
+ function scoreStaticSegments(segments) {
556
+ return segments.reduce((score, segment) => {
557
+ return score + scoreLiteralSegment(segment);
558
+ }, 0);
559
+ }
560
+ function scorePatternSegmentsWithParser(segments, parsePatternSegment) {
561
+ const lastPatternIndex = segments.length - 1;
562
+ let score = 0;
563
+ for (let index = 0; index < segments.length; index += 1) {
564
+ const segment = segments[index];
565
+ const parsed = parsePatternSegment(segment, index, lastPatternIndex);
566
+ if (parsed !== null) {
567
+ score += scoreParsedPatternSegment(parsed);
568
+ }
569
+ }
570
+ return score;
571
+ }
572
+ function scorePathPattern(path, parsePatternSegment) {
573
+ if (path === "") return 0;
574
+ if (path === "/") return ROOT_PATH_SCORE;
575
+ const segments = splitPathSegments(path);
576
+ return parsePatternSegment === null ? scoreStaticSegments(segments) : scorePatternSegmentsWithParser(segments, parsePatternSegment);
577
+ }
578
+ function splitAuthoritySegments(authority) {
579
+ if (authority.startsWith("[")) return [authority];
580
+ const normalized = authority.endsWith(".") ? authority.slice(0, -1) : authority;
581
+ return normalized === "" ? [] : normalized.split(".");
582
+ }
583
+ function baseUrlSpecificityScore({
584
+ authority,
585
+ path,
586
+ hasParams,
587
+ tolerateMalformedBaseParams = false
588
+ }) {
589
+ const patternParser = hasParams ? tolerateMalformedBaseParams ? parseMalformedTolerantBaseSegment : parseStrictMatchSegment : null;
590
+ const authoritySegments = splitAuthoritySegments(authority);
591
+ const authorityScore = patternParser === null ? scoreStaticSegments(authoritySegments) : scorePatternSegmentsWithParser(
592
+ [...authoritySegments].reverse(),
593
+ patternParser
594
+ );
595
+ const pathScore = scorePathPattern(path, patternParser);
596
+ return pathScore * PATH_SCORE_MULTIPLIER + authorityScore * AUTHORITY_SCORE_MULTIPLIER + (hasParams ? 0 : STATIC_BASE_SCORE_BONUS);
597
+ }
598
+ function matchStaticBasePathPrefix(path, pattern) {
599
+ if (pattern === "") {
600
+ return path === "" ? "/" : path;
601
+ }
602
+ if (pattern === "/") {
603
+ if (!path.startsWith(pattern)) return null;
604
+ const relativePath2 = path.slice(pattern.length);
605
+ if (relativePath2 !== "" && !relativePath2.startsWith("/")) return null;
606
+ return relativePath2 === "" ? "/" : relativePath2;
607
+ }
608
+ if (!path.startsWith(pattern)) return null;
609
+ const relativePath = path.slice(pattern.length);
610
+ if (relativePath !== "" && !relativePath.startsWith("/")) return null;
611
+ return relativePath === "" ? "/" : relativePath;
612
+ }
613
+ function normalizeUrlHostname(hostname, options = {}) {
614
+ let normalized = hostname.toLowerCase();
615
+ if (normalized.endsWith(".")) {
616
+ normalized = normalized.slice(0, -1);
617
+ if (normalized === "" || normalized.endsWith(".")) {
618
+ return null;
619
+ }
620
+ }
621
+ if (normalized.split(".").some((label) => {
622
+ return label === "";
623
+ })) {
624
+ return null;
625
+ }
626
+ const forbiddenChars = options.allowHostParams === true ? FORBIDDEN_BASE_PATTERN_HOST_CHARS : FORBIDDEN_RUNTIME_HOST_CHARS;
627
+ if (!normalized.startsWith("[") && [...normalized].some((char) => {
628
+ return forbiddenChars.has(char);
629
+ })) {
630
+ return null;
631
+ }
632
+ return normalized;
633
+ }
634
+ function normalizedUrlAuthority(parsed, options = {}) {
635
+ if (parsed.username !== "" || parsed.password !== "") {
636
+ return null;
637
+ }
638
+ const hostname = normalizeUrlHostname(parsed.hostname, options);
639
+ if (hostname === null || hostname === "") {
640
+ return null;
641
+ }
642
+ return parsed.port === "" ? hostname : `${hostname}:${parsed.port}`;
643
+ }
644
+ function matchStaticFirewallBaseUrl(url, rawBase, options = {}) {
645
+ const parsedUrl = new URL(url);
646
+ const parsedBase = new URL(rawBase);
647
+ if (parsedUrl.protocol.toLowerCase() !== parsedBase.protocol.toLowerCase()) {
648
+ return null;
649
+ }
650
+ const baseHasParams = hasBaseUrlParams(rawBase);
651
+ const baseForMatch = stripTrailingSlash(rawBase);
652
+ const urlAuthority = normalizedUrlAuthority(parsedUrl);
653
+ const baseAuthority = normalizedUrlAuthority(parsedBase, {
654
+ allowHostParams: baseHasParams
655
+ });
656
+ if (urlAuthority === null || baseAuthority === null) return null;
657
+ if (baseHasParams) {
658
+ const hostParams = options.tolerateMalformedBaseParams === true ? matchFirewallHostForMalformedBaseDecision(urlAuthority, baseAuthority) : matchFirewallHost(urlAuthority, baseAuthority);
659
+ if (hostParams === null) return null;
660
+ } else if (urlAuthority !== baseAuthority) {
661
+ return null;
662
+ }
663
+ const basePath = rawBasePathFromUrl(baseForMatch);
664
+ const relativePath = baseHasParams ? options.tolerateMalformedBaseParams === true ? matchFirewallPathPrefixForMalformedBaseDecision(
665
+ rawPathFromUrl(url),
666
+ basePath
667
+ ) : matchFirewallPathPrefix(rawPathFromUrl(url), basePath) : matchStaticBasePathPrefix(rawPathFromUrl(url), basePath);
668
+ if (relativePath === null) return null;
669
+ const displayBase = stripTrailingSlash(rawBase);
670
+ return {
671
+ displayBase,
672
+ relativePath,
673
+ score: baseUrlSpecificityScore({
674
+ authority: baseAuthority,
675
+ path: basePath,
676
+ hasParams: baseHasParams,
677
+ tolerateMalformedBaseParams: options.tolerateMalformedBaseParams === true
678
+ })
679
+ };
680
+ }
681
+ function runtimeUrlCanMatchFirewallBase(url) {
682
+ if (hasUnsafeUrlCodepoint(url) || hasRawWhitespace(url) || !url.includes("://") || hasMalformedRuntimeAuthoritySyntax(url)) {
683
+ return false;
684
+ }
685
+ const runtimeAuthorityOrigin = runtimeAuthorityOriginForHostValidation(url);
686
+ if (runtimeAuthorityOrigin === null) return true;
687
+ try {
688
+ validateBaseUrl(runtimeAuthorityOrigin, "runtime");
689
+ return true;
690
+ } catch {
691
+ return false;
692
+ }
693
+ }
694
+ function matchFirewallBaseUrlForDecision(url, rawBase) {
695
+ if (!runtimeUrlCanMatchFirewallBase(url)) return null;
696
+ const baseForMatch = rawBaseForDecisionMatch(rawBase);
697
+ if (baseForMatch === null) return null;
698
+ try {
699
+ const match = matchStaticFirewallBaseUrl(url, baseForMatch, {
700
+ tolerateMalformedBaseParams: true
701
+ });
702
+ if (match === null) return null;
703
+ return { ...match, displayBase: stripTrailingSlash(rawBase) };
704
+ } catch {
705
+ return null;
706
+ }
707
+ }
708
+ function createDecisionState() {
709
+ return {
710
+ bestBaseScore: null,
711
+ bestRuleSpecificity: null,
712
+ baseMatch: null,
713
+ allowedMatch: null,
714
+ deniedMatch: null,
715
+ deniedPermissionNames: [],
716
+ malformedConfigMatch: null,
717
+ malformedPolicyMatch: null
718
+ };
719
+ }
720
+ function acceptDecisionBaseMatch(state, match, score) {
721
+ if (state.bestBaseScore === null || score > state.bestBaseScore) {
722
+ state.bestBaseScore = score;
723
+ state.bestRuleSpecificity = null;
724
+ state.baseMatch = null;
725
+ state.allowedMatch = null;
726
+ state.deniedMatch = null;
727
+ state.deniedPermissionNames = [];
728
+ state.malformedConfigMatch = null;
729
+ state.malformedPolicyMatch = null;
730
+ } else if (score < state.bestBaseScore) {
731
+ return false;
732
+ }
733
+ state.baseMatch ??= match;
734
+ return true;
735
+ }
736
+ function canRuleSpecificityAffectDecision(state, specificity) {
737
+ if (state.bestRuleSpecificity === null) return true;
738
+ const comparison = comparePathSpecificity(
739
+ specificity,
740
+ state.bestRuleSpecificity
741
+ );
742
+ if (comparison > 0) return true;
743
+ if (comparison < 0) return false;
744
+ return state.allowedMatch === null;
745
+ }
746
+ function acceptRuleSpecificity(state, specificity) {
747
+ if (state.bestRuleSpecificity === null) {
748
+ state.bestRuleSpecificity = specificity;
749
+ return true;
750
+ }
751
+ const comparison = comparePathSpecificity(
752
+ specificity,
753
+ state.bestRuleSpecificity
754
+ );
755
+ if (comparison > 0) {
756
+ state.bestRuleSpecificity = specificity;
757
+ state.allowedMatch = null;
758
+ state.deniedMatch = null;
759
+ state.deniedPermissionNames = [];
760
+ return true;
761
+ }
762
+ return comparison === 0;
763
+ }
764
+ function recordDeniedRule(state, match, permission) {
765
+ if (!state.deniedPermissionNames.includes(permission)) {
766
+ state.deniedPermissionNames.push(permission);
767
+ }
768
+ state.deniedMatch ??= match;
769
+ }
770
+ function resolveFirewallDecision(state, networkPolicies) {
771
+ const baseMatch = state.baseMatch;
772
+ if (baseMatch === null) {
773
+ return { kind: "no_match" };
774
+ }
775
+ if (state.allowedMatch !== null) {
776
+ return {
777
+ kind: "allow",
778
+ firewallName: state.allowedMatch.firewallName,
779
+ base: state.allowedMatch.base,
780
+ relativePath: state.allowedMatch.relativePath,
781
+ permission: state.allowedMatch.permission,
782
+ rule: state.allowedMatch.rule
783
+ };
784
+ }
785
+ if (state.deniedMatch !== null) {
786
+ return {
787
+ kind: "block",
788
+ firewallName: state.deniedMatch.firewallName,
789
+ base: state.deniedMatch.base,
790
+ relativePath: state.deniedMatch.relativePath,
791
+ reason: "permission_denied",
792
+ permissions: state.deniedPermissionNames
793
+ };
794
+ }
795
+ if (state.malformedPolicyMatch !== null) {
796
+ return {
797
+ kind: "block",
798
+ firewallName: state.malformedPolicyMatch.firewallName,
799
+ base: state.malformedPolicyMatch.base,
800
+ relativePath: state.malformedPolicyMatch.relativePath,
801
+ reason: "malformed_network_policy",
802
+ permissions: []
803
+ };
804
+ }
805
+ if (state.malformedConfigMatch !== null) {
806
+ return {
807
+ kind: "block",
808
+ firewallName: state.malformedConfigMatch.firewallName,
809
+ base: state.malformedConfigMatch.base,
810
+ relativePath: state.malformedConfigMatch.relativePath,
811
+ reason: "malformed_firewall_config",
812
+ permissions: []
813
+ };
814
+ }
815
+ const policy = networkPolicies.policies.get(baseMatch.firewallName);
816
+ if (policy === void 0) {
817
+ return {
818
+ kind: "allow",
819
+ firewallName: baseMatch.firewallName,
820
+ base: baseMatch.allowBase,
821
+ relativePath: baseMatch.relativePath
822
+ };
823
+ }
824
+ if (policy.unknownPolicyMalformed) {
825
+ return {
826
+ kind: "block",
827
+ firewallName: baseMatch.firewallName,
828
+ base: baseMatch.base,
829
+ relativePath: baseMatch.relativePath,
830
+ reason: "malformed_network_policy",
831
+ permissions: []
832
+ };
833
+ }
834
+ if (policy.unknownPolicy === "allow") {
835
+ return {
836
+ kind: "allow",
837
+ firewallName: baseMatch.firewallName,
838
+ base: baseMatch.allowBase,
839
+ relativePath: baseMatch.relativePath
840
+ };
841
+ }
842
+ return {
843
+ kind: "block",
844
+ firewallName: baseMatch.firewallName,
845
+ base: baseMatch.base,
846
+ relativePath: baseMatch.relativePath,
847
+ reason: "unknown_endpoint",
848
+ permissions: []
849
+ };
850
+ }
851
+ function unsafePathBlockDecision(firewall, baseMatch) {
852
+ return {
853
+ kind: "block",
854
+ firewallName: firewall.name,
855
+ base: baseMatch.displayBase,
856
+ relativePath: baseMatch.relativePath,
857
+ reason: "unsafe_path",
858
+ permissions: []
859
+ };
860
+ }
861
+ function recordMalformedDecisionState(state, api, blockMatch) {
862
+ if (api.baseMalformed || api.authMalformed || api.hasMalformedRules) {
863
+ state.malformedConfigMatch ??= blockMatch;
864
+ }
865
+ }
866
+ function apiCannotEvaluateRules(firewall, api) {
867
+ return firewall.nameMalformed || api.baseMalformed || api.authMalformed;
868
+ }
869
+ function policyCannotEvaluateRules(networkPolicies, policy) {
870
+ return networkPolicies.topLevelMalformed || policy !== void 0 && policy.permissionMalformed;
871
+ }
872
+ function evaluateDecisionRule({
873
+ state,
874
+ rule,
875
+ policy,
876
+ blockMatch,
877
+ baseMatch,
878
+ upperMethod
879
+ }) {
880
+ if (rule.method !== "ANY" && rule.method !== upperMethod) return;
881
+ if (!canRuleSpecificityAffectDecision(state, rule.specificity)) return;
882
+ const permissionBlocked = policy !== void 0 && policy.blockedPermissions.has(rule.permission);
883
+ if (matchFirewallPath(baseMatch.relativePath, rule.path) === null) return;
884
+ if (!acceptRuleSpecificity(state, rule.specificity)) return;
885
+ if (permissionBlocked) {
886
+ recordDeniedRule(state, blockMatch, rule.permission);
887
+ return;
888
+ }
889
+ state.allowedMatch ??= {
890
+ firewallName: baseMatch.firewallName,
891
+ base: baseMatch.allowBase,
892
+ relativePath: baseMatch.relativePath,
893
+ permission: rule.permission,
894
+ rule: rule.raw
895
+ };
896
+ }
897
+ function evaluateDecisionRules({
898
+ state,
899
+ api,
900
+ policy,
901
+ blockMatch,
902
+ baseMatch,
903
+ upperMethod
904
+ }) {
905
+ for (const rule of api.rules) {
906
+ evaluateDecisionRule({
907
+ state,
908
+ rule,
909
+ policy,
910
+ blockMatch,
911
+ baseMatch,
912
+ upperMethod
913
+ });
914
+ }
915
+ }
916
+ function evaluateDecisionApi({
917
+ state,
918
+ firewall,
919
+ api,
920
+ url,
921
+ unsafePath,
922
+ networkPolicies,
923
+ upperMethod
924
+ }) {
925
+ const policy = networkPolicies.policies.get(firewall.name);
926
+ const baseMatch = matchFirewallBaseUrlForDecision(url, api.rawBase);
927
+ if (baseMatch === null) return null;
928
+ if (unsafePath) return unsafePathBlockDecision(firewall, baseMatch);
929
+ const decisionBaseMatch = {
930
+ firewallName: firewall.name,
931
+ base: baseMatch.displayBase,
932
+ allowBase: api.rawBase,
933
+ relativePath: baseMatch.relativePath
934
+ };
935
+ const blockMatch = {
936
+ firewallName: decisionBaseMatch.firewallName,
937
+ base: decisionBaseMatch.base,
938
+ relativePath: decisionBaseMatch.relativePath
939
+ };
940
+ if (!acceptDecisionBaseMatch(state, decisionBaseMatch, baseMatch.score)) {
941
+ return null;
942
+ }
943
+ recordMalformedDecisionState(state, api, blockMatch);
944
+ if (apiCannotEvaluateRules(firewall, api)) return null;
945
+ if (policyCannotEvaluateRules(networkPolicies, policy)) {
946
+ state.malformedPolicyMatch ??= blockMatch;
947
+ return null;
948
+ }
949
+ evaluateDecisionRules({
950
+ state,
951
+ api,
952
+ policy,
953
+ blockMatch,
954
+ baseMatch: decisionBaseMatch,
955
+ upperMethod
956
+ });
957
+ return null;
958
+ }
959
+ function matchFirewallBaseUrl(url, rawBase) {
960
+ if (hasUnsafeRuntimeUrlSyntax(url) || hasMalformedRuntimeAuthoritySyntax(url)) {
961
+ return null;
962
+ }
963
+ const runtimeAuthorityOrigin = runtimeAuthorityOriginForHostValidation(url);
964
+ try {
965
+ if (runtimeAuthorityOrigin !== null) {
966
+ validateBaseUrl(runtimeAuthorityOrigin, "runtime");
967
+ }
968
+ validateBaseUrl(rawBase, "firewall");
969
+ return matchStaticFirewallBaseUrl(url, rawBase);
970
+ } catch {
971
+ return null;
972
+ }
973
+ }
974
+ function matchFirewallRequestDecision(firewalls, method, url, networkPolicies = void 0) {
975
+ const decisionFirewalls = compileDecisionFirewalls(firewalls);
976
+ if (decisionFirewalls.length === 0) return { kind: "no_match" };
977
+ const compiledNetworkPolicies = compileNetworkPolicies(networkPolicies);
978
+ const upperMethod = method.toUpperCase();
979
+ const state = createDecisionState();
980
+ const unsafePath = url.includes("\\") || hasUnsafeFirewallPath(rawPathFromUrl(url));
981
+ for (const firewall of decisionFirewalls) {
982
+ for (const api of firewall.apis) {
983
+ const immediateDecision = evaluateDecisionApi({
984
+ state,
985
+ firewall,
986
+ api,
987
+ url,
988
+ unsafePath,
989
+ networkPolicies: compiledNetworkPolicies,
990
+ upperMethod
991
+ });
992
+ if (immediateDecision !== null) {
993
+ return immediateDecision;
994
+ }
995
+ }
996
+ }
997
+ return resolveFirewallDecision(state, compiledNetworkPolicies);
998
+ }
999
+ function matchFirewallHostWithParser(host, pattern, parsePatternSegment) {
1000
+ const hostSegsOrig = host.split(".");
1001
+ const hostSegsLower = hostSegsOrig.map((segment) => {
1002
+ return segment.toLowerCase();
1003
+ });
1004
+ const patternSegs = pattern.split(".").reverse();
1005
+ hostSegsOrig.reverse();
1006
+ hostSegsLower.reverse();
1007
+ const params = {};
1008
+ let hi = 0;
1009
+ const lastPatternIndex = patternSegs.length - 1;
1010
+ for (let patternIndex = 0; patternIndex < patternSegs.length; patternIndex++) {
1011
+ const seg = patternSegs[patternIndex];
1012
+ const parsed = parsePatternSegment(seg, patternIndex, lastPatternIndex);
1013
+ if (parsed === null) return null;
1014
+ if (parsed.kind === "literal") {
1015
+ if (hi >= hostSegsLower.length || hostSegsLower[hi] !== parsed.value.toLowerCase()) {
1016
+ return null;
1017
+ }
1018
+ hi += 1;
1019
+ continue;
1020
+ }
1021
+ const { name, prefix, suffix, greedy } = parsed;
1022
+ if (greedy === "+") {
1023
+ if (hi >= hostSegsOrig.length) return null;
1024
+ params[name] = hostSegsOrig.slice(hi).reverse().join(".");
1025
+ return params;
1026
+ }
1027
+ if (greedy === "*") {
1028
+ params[name] = hostSegsOrig.slice(hi).reverse().join(".");
1029
+ return params;
1030
+ }
1031
+ if (hi >= hostSegsOrig.length) return null;
1032
+ if (prefix === "" && suffix === "") {
1033
+ params[name] = hostSegsLower[hi];
1034
+ } else {
1035
+ const captured = matchMixedSegment(
1036
+ hostSegsLower[hi],
1037
+ prefix.toLowerCase(),
1038
+ suffix.toLowerCase()
1039
+ );
1040
+ if (captured === null) return null;
1041
+ params[name] = captured;
1042
+ }
1043
+ hi += 1;
1044
+ }
1045
+ return hi === hostSegsOrig.length ? params : null;
1046
+ }
1047
+ function matchFirewallHost(host, pattern) {
1048
+ return matchFirewallHostWithParser(host, pattern, parseStrictMatchSegment);
1049
+ }
1050
+ function parseMalformedTolerantBaseSegment(segment, patternIndex, lastPatternIndex) {
1051
+ const parsed = parseSegment(segment);
1052
+ if (parsed.kind === "error") {
1053
+ return {
1054
+ kind: "param",
1055
+ prefix: "",
1056
+ name: `__malformed_base_segment_${patternIndex}`,
1057
+ suffix: "",
1058
+ greedy: ""
1059
+ };
1060
+ }
1061
+ if (parsed.kind === "param" && parsed.greedy !== "" && isInvalidGreedyParam(
1062
+ patternIndex,
1063
+ lastPatternIndex,
1064
+ parsed.prefix,
1065
+ parsed.suffix
1066
+ )) {
1067
+ return { ...parsed, greedy: "" };
1068
+ }
1069
+ return parsed;
1070
+ }
1071
+ function matchFirewallHostForMalformedBaseDecision(host, pattern) {
1072
+ return matchFirewallHostWithParser(
1073
+ host,
1074
+ pattern,
1075
+ parseMalformedTolerantBaseSegment
1076
+ );
1077
+ }
1078
+ function matchFirewallPathPrefixWithParser(path, pattern, parsePatternSegment) {
1079
+ const pathSegs = splitPathSegments(path);
1080
+ const patternSegs = splitPathSegments(pattern);
1081
+ let pi = 0;
1082
+ const lastPatternIndex = patternSegs.length - 1;
1083
+ for (let patternIndex = 0; patternIndex < patternSegs.length; patternIndex++) {
1084
+ const seg = patternSegs[patternIndex];
1085
+ const parsed = parsePatternSegment(seg, patternIndex, lastPatternIndex);
1086
+ if (parsed === null) return null;
1087
+ if (parsed.kind === "literal") {
1088
+ if (pi >= pathSegs.length || pathSegs[pi] !== parsed.value) return null;
1089
+ pi += 1;
1090
+ continue;
1091
+ }
1092
+ const { prefix, suffix, greedy } = parsed;
1093
+ if (greedy === "+") {
1094
+ if (pi >= pathSegs.length || !hasNonEmptySegment(pathSegs, pi)) {
1095
+ return null;
1096
+ }
1097
+ return "/";
1098
+ }
1099
+ if (greedy === "*") {
1100
+ return "/";
1101
+ }
1102
+ if (pi >= pathSegs.length) return null;
1103
+ const runtime = pathSegs[pi];
1104
+ if (prefix === "" && suffix === "") {
1105
+ if (runtime === "") return null;
1106
+ } else if (matchMixedSegment(runtime, prefix, suffix) === null) {
1107
+ return null;
1108
+ }
1109
+ pi += 1;
1110
+ }
1111
+ return relativePathFromSegments(pathSegs, pi);
1112
+ }
1113
+ function matchFirewallPathPrefix(path, pattern) {
1114
+ return matchFirewallPathPrefixWithParser(
1115
+ path,
1116
+ pattern,
1117
+ parseStrictMatchSegment
1118
+ );
1119
+ }
1120
+ function matchFirewallPathPrefixForMalformedBaseDecision(path, pattern) {
1121
+ return matchFirewallPathPrefixWithParser(
1122
+ path,
1123
+ pattern,
1124
+ parseMalformedTolerantBaseSegment
1125
+ );
1126
+ }
1127
+ function matchFirewallPath(path, pattern) {
1128
+ const pathSegs = splitPathSegments(path);
1129
+ const patternSegs = splitPathSegments(pattern);
1130
+ const params = {};
1131
+ let pi = 0;
1132
+ const lastPatternIndex = patternSegs.length - 1;
1133
+ for (let patternIndex = 0; patternIndex < patternSegs.length; patternIndex++) {
1134
+ const seg = patternSegs[patternIndex];
1135
+ const parsed = parseSegment(seg);
1136
+ if (parsed.kind === "error") return null;
1137
+ if (parsed.kind === "literal") {
1138
+ if (pi >= pathSegs.length || pathSegs[pi] !== parsed.value) return null;
1139
+ pi++;
1140
+ continue;
1141
+ }
1142
+ const { name, prefix, suffix, greedy } = parsed;
1143
+ if (greedy === "+") {
1144
+ if (isInvalidGreedyParam(patternIndex, lastPatternIndex, prefix, suffix))
1145
+ return null;
1146
+ if (pi >= pathSegs.length || !hasNonEmptySegment(pathSegs, pi)) {
1147
+ return null;
1148
+ }
1149
+ params[name] = pathSegs.slice(pi).join("/");
1150
+ return params;
1151
+ }
1152
+ if (greedy === "*") {
1153
+ if (isInvalidGreedyParam(patternIndex, lastPatternIndex, prefix, suffix))
1154
+ return null;
1155
+ params[name] = pathSegs.slice(pi).join("/");
1156
+ return params;
1157
+ }
1158
+ if (pi >= pathSegs.length) return null;
1159
+ const runtime = pathSegs[pi];
1160
+ if (prefix === "" && suffix === "") {
1161
+ if (runtime === "") return null;
1162
+ params[name] = runtime;
1163
+ } else {
1164
+ const captured = matchMixedSegment(runtime, prefix, suffix);
1165
+ if (captured === null) return null;
1166
+ params[name] = captured;
1167
+ }
1168
+ pi++;
1169
+ }
1170
+ if (pi !== pathSegs.length) return null;
1171
+ return params;
1172
+ }
1173
+
1174
+ export {
1175
+ matchFirewallBaseUrl,
1176
+ matchFirewallRequestDecision
1177
+ };
1178
+ //# sourceMappingURL=chunk-72DXWQL4.js.map