@libreflare/worker-runtime 0.10.4 → 0.10.6
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/README.md +101 -44
- package/dist/rule-evaluator/access-values.d.ts +42 -27
- package/dist/rule-evaluator/access-values.d.ts.map +1 -1
- package/dist/rule-evaluator/access-values.js +123 -52
- package/dist/rule-evaluator/access-values.js.map +1 -1
- package/dist/rule-evaluator/byte-strings.d.ts.map +1 -1
- package/dist/rule-evaluator/byte-strings.js +27 -11
- package/dist/rule-evaluator/byte-strings.js.map +1 -1
- package/dist/rule-evaluator/constants.d.ts +1 -1
- package/dist/rule-evaluator/constants.d.ts.map +1 -1
- package/dist/rule-evaluator/constants.js +8 -0
- package/dist/rule-evaluator/constants.js.map +1 -1
- package/dist/rule-evaluator/country-codes.generated.js +1 -1
- package/dist/rule-evaluator/diagnostics.d.ts +1 -1
- package/dist/rule-evaluator/diagnostics.d.ts.map +1 -1
- package/dist/rule-evaluator/diagnostics.js +10 -0
- package/dist/rule-evaluator/diagnostics.js.map +1 -1
- package/dist/rule-evaluator/edge-field-gaps.d.ts +6 -4
- package/dist/rule-evaluator/edge-field-gaps.d.ts.map +1 -1
- package/dist/rule-evaluator/edge-field-gaps.js +40 -42
- package/dist/rule-evaluator/edge-field-gaps.js.map +1 -1
- package/dist/rule-evaluator/edge-record.js +2 -0
- package/dist/rule-evaluator/edge-record.js.map +1 -1
- package/dist/rule-evaluator/engine-observations.d.ts +4 -4
- package/dist/rule-evaluator/engine-observations.d.ts.map +1 -1
- package/dist/rule-evaluator/engine-observations.generated.d.ts +533 -3
- package/dist/rule-evaluator/engine-observations.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/engine-observations.generated.js +406 -248
- package/dist/rule-evaluator/engine-observations.generated.js.map +1 -1
- package/dist/rule-evaluator/engine-observations.js +1 -0
- package/dist/rule-evaluator/engine-observations.js.map +1 -1
- package/dist/rule-evaluator/explain.js +12 -9
- package/dist/rule-evaluator/explain.js.map +1 -1
- package/dist/rule-evaluator/field-availability.d.ts +6 -1
- package/dist/rule-evaluator/field-availability.d.ts.map +1 -1
- package/dist/rule-evaluator/field-availability.js +16 -4
- package/dist/rule-evaluator/field-availability.js.map +1 -1
- package/dist/rule-evaluator/field-descriptions.generated.d.ts +147 -5
- package/dist/rule-evaluator/field-descriptions.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/field-descriptions.generated.js +345 -5
- package/dist/rule-evaluator/field-descriptions.generated.js.map +1 -1
- package/dist/rule-evaluator/fields.d.ts +0 -1
- package/dist/rule-evaluator/fields.d.ts.map +1 -1
- package/dist/rule-evaluator/fields.js +67 -8
- package/dist/rule-evaluator/fields.js.map +1 -1
- package/dist/rule-evaluator/function-availability.d.ts +7 -0
- package/dist/rule-evaluator/function-availability.d.ts.map +1 -1
- package/dist/rule-evaluator/function-availability.js +38 -0
- package/dist/rule-evaluator/function-availability.js.map +1 -1
- package/dist/rule-evaluator/function-descriptions.d.ts +12 -2
- package/dist/rule-evaluator/function-descriptions.d.ts.map +1 -1
- package/dist/rule-evaluator/function-descriptions.generated.d.ts +171 -4
- package/dist/rule-evaluator/function-descriptions.generated.d.ts.map +1 -1
- package/dist/rule-evaluator/function-descriptions.generated.js +1280 -98
- package/dist/rule-evaluator/function-descriptions.generated.js.map +1 -1
- package/dist/rule-evaluator/function-descriptions.js +3 -1
- package/dist/rule-evaluator/function-descriptions.js.map +1 -1
- package/dist/rule-evaluator/function-signature-validation.d.ts +13 -4
- package/dist/rule-evaluator/function-signature-validation.d.ts.map +1 -1
- package/dist/rule-evaluator/function-signature-validation.js +142 -28
- package/dist/rule-evaluator/function-signature-validation.js.map +1 -1
- package/dist/rule-evaluator/functions.d.ts +10 -6
- package/dist/rule-evaluator/functions.d.ts.map +1 -1
- package/dist/rule-evaluator/functions.js +550 -167
- package/dist/rule-evaluator/functions.js.map +1 -1
- package/dist/rule-evaluator/minifier.d.ts +9 -0
- package/dist/rule-evaluator/minifier.d.ts.map +1 -1
- package/dist/rule-evaluator/minifier.js +23 -0
- package/dist/rule-evaluator/minifier.js.map +1 -1
- package/dist/rule-evaluator/operators.d.ts.map +1 -1
- package/dist/rule-evaluator/operators.js +15 -6
- package/dist/rule-evaluator/operators.js.map +1 -1
- package/dist/rule-evaluator/parse-cache.d.ts +3 -1
- package/dist/rule-evaluator/parse-cache.d.ts.map +1 -1
- package/dist/rule-evaluator/parse-cache.js +4 -0
- package/dist/rule-evaluator/parse-cache.js.map +1 -1
- package/dist/rule-evaluator/parser.d.ts +7 -1
- package/dist/rule-evaluator/parser.d.ts.map +1 -1
- package/dist/rule-evaluator/parser.js +14 -0
- package/dist/rule-evaluator/parser.js.map +1 -1
- package/dist/rule-evaluator/quantifier.d.ts +19 -2
- package/dist/rule-evaluator/quantifier.d.ts.map +1 -1
- package/dist/rule-evaluator/quantifier.js +104 -12
- package/dist/rule-evaluator/quantifier.js.map +1 -1
- package/dist/rule-evaluator/replacement.d.ts +37 -0
- package/dist/rule-evaluator/replacement.d.ts.map +1 -0
- package/dist/rule-evaluator/replacement.js +54 -0
- package/dist/rule-evaluator/replacement.js.map +1 -0
- package/dist/rule-evaluator/rule-language-types.d.ts.map +1 -1
- package/dist/rule-evaluator/rule-language-types.js +5 -0
- package/dist/rule-evaluator/rule-language-types.js.map +1 -1
- package/dist/rule-evaluator/validation.d.ts +2 -1
- package/dist/rule-evaluator/validation.d.ts.map +1 -1
- package/dist/rule-evaluator/validation.js +250 -91
- package/dist/rule-evaluator/validation.js.map +1 -1
- package/dist/rule-evaluator/wildcard.d.ts +6 -3
- package/dist/rule-evaluator/wildcard.d.ts.map +1 -1
- package/dist/rule-evaluator/wildcard.js +10 -4
- package/dist/rule-evaluator/wildcard.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,14 +54,14 @@ Analysis:
|
|
|
54
54
|
|
|
55
55
|
Validation:
|
|
56
56
|
|
|
57
|
-
- `validateRuleExpressionSyntax`: syntax, length, and field availability validation for Cloudflare URL Rewrite Rule filter expressions by default. Pass an explicit config object for minification, length enforcement, preset, field availability, deprecated-field notices, and list-reference policy. With minification enabled it validates the minified expression against Cloudflare's 4096-character rule limit by default; when minification is disabled, the result omits `minifiedExpression` and `minifiedLength`.
|
|
57
|
+
- `validateRuleExpressionSyntax`: syntax, length, and field availability validation for Cloudflare URL Rewrite Rule filter expressions by default. Pass an explicit config object for minification, length enforcement, preset, field availability, deprecated-field notices, and list-reference policy. The presets are `url-rewrite-filter`, `url-rewrite-target`, which reads the expression as one value rather than a condition, `custom-rule` for the Custom Rules of a zone, and `logging-source-key`. With minification enabled it validates the minified expression against Cloudflare's 4096-character rule limit by default; when minification is disabled, the result omits `minifiedExpression` and `minifiedLength`.
|
|
58
58
|
- `validateLoggingSourceKeyRuleExpressionSyntax`: runtime-only source-key rule validation using the pre-origin field context, without Custom List references or deployment length enforcement.
|
|
59
59
|
- `trimRuleExpression`: the expression without the whitespace Cloudflare trims off its ends, which is every character Unicode counts as whitespace: unlike `String.prototype.trim()`, it keeps U+FEFF and trims U+0085. Validation reads the expression trimmed this way, so its diagnostic positions count from the first character that is not whitespace, `source.search(/\P{White_Space}/u)`.
|
|
60
60
|
|
|
61
61
|
Formatting:
|
|
62
62
|
|
|
63
63
|
- `normalizeRuleExpression`: syntax-aware readable formatter that preserves operator notation, grouping, and string literal spelling while canonicalizing grammar whitespace.
|
|
64
|
-
- `minifyRuleExpression`: syntax-aware minifier for Cloudflare Rules expressions before Rewrite Rule deployment. It uses C-like operators, removes precedence-redundant grouping, and preserves string literal spelling. Syntax-invalid source is returned unchanged with diagnostics.
|
|
64
|
+
- `minifyRuleExpression`: syntax-aware minifier for Cloudflare Rules expressions before Rewrite Rule deployment. It uses C-like operators, removes precedence-redundant grouping, and preserves string literal spelling. Syntax-invalid source is returned unchanged with diagnostics. It reads the expression as a condition; `validateRuleExpressionSyntax` with the `url-rewrite-target` preset gives a rewrite target's `minifiedExpression`.
|
|
65
65
|
|
|
66
66
|
String literals:
|
|
67
67
|
|
|
@@ -125,8 +125,11 @@ an expression, `lookup_json_*()` keys must be literals,
|
|
|
125
125
|
header map keys such as `http.request.headers["x-a"]` must be lowercase, and
|
|
126
126
|
integer literals must fit in 64 bits, with `0x` making one hex and a leading `0` making one octal. Field availability keeps each preset's
|
|
127
127
|
documented fields and the observed differences apart, and `fieldAvailability`
|
|
128
|
-
can still allow a field the engine was observed to reject.
|
|
129
|
-
|
|
128
|
+
can still allow a field the engine was observed to reject. Cloudflare documents
|
|
129
|
+
no field list for Custom Rules, so theirs is the observed one. The catalog also
|
|
130
|
+
has fields and functions that Cloudflare's references lack and dry runs accepted,
|
|
131
|
+
such as `cf.zone.plan` and `filter()`. Source-key rules run in
|
|
132
|
+
the Worker rather than in a Cloudflare phase, so the URL rewrite phase's
|
|
130
133
|
observed differences do not apply to them.
|
|
131
134
|
|
|
132
135
|
Cloudflare trims any whitespace off the ends of an expression, but reads only
|
|
@@ -175,12 +178,34 @@ results that large round, and so do the comparisons and `to_string()` output
|
|
|
175
178
|
that use them. An integer `hash_in_range()` seed that large gives an unknown
|
|
176
179
|
result instead, since a rounded seed hashes into an unrelated bucket.
|
|
177
180
|
|
|
181
|
+
A rewrite target is one field, with or without access, such as
|
|
182
|
+
`http.request.headers["x"][0]`, or one function call, and it must give a
|
|
183
|
+
String, as Cloudflare reads it. A literal gets
|
|
184
|
+
`syntax.literal_instead_of_field_or_call`. A target in parentheses, or a
|
|
185
|
+
condition, gets `syntax.condition_instead_of_value`, with no other checks of
|
|
186
|
+
what it holds. A field or call of another type, such as `ssl`, `len(...)` or
|
|
187
|
+
`http.request.headers.names[*]`, gets `rule_expression.result_type_mismatch`,
|
|
188
|
+
whose `expectedType` is `String`. A target gets no
|
|
189
|
+
`field.header_index_requires_guard`, since its `has_key()` guard can go only
|
|
190
|
+
in the rule's filter.
|
|
191
|
+
|
|
178
192
|
URL rewrite filters and rewrite targets also reject the functions the URL
|
|
179
193
|
rewrite phase does not accept, such as `split()` in either and `to_string()`
|
|
180
|
-
in filters, with `function.unavailable`. Rewrite targets
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
194
|
+
and `format_date()` in filters, with `function.unavailable`. Rewrite targets
|
|
195
|
+
reject operators and quantifiers, as in `to_string(http.host eq "x")` and
|
|
196
|
+
`any(...)`, and conditions used as function arguments, as in
|
|
197
|
+
`to_string((ssl))`, with `operator.unavailable`.
|
|
198
|
+
`concat()` can appear only once in filters, and three times in rewrite targets.
|
|
199
|
+
|
|
200
|
+
Custom Rules also reject some functions with `function.unavailable`, such as
|
|
201
|
+
`split()`, or `join()` and `wildcard_replace()`, which URL rewrite filters
|
|
202
|
+
accept. They accept some that URL rewrite filters reject, such as `cidr()` and
|
|
203
|
+
`to_string()`. In Custom Rules, `concat()` can also appear only once, and it
|
|
204
|
+
reads only some request fields, such as `http.request.uri.path` and the request
|
|
205
|
+
headers but not `http.host`, directly or through nested calls; another field
|
|
206
|
+
gets `function.parameter.requires_allowed_field`.
|
|
207
|
+
|
|
208
|
+
These phase rules depend on the preset alone:
|
|
184
209
|
`fieldAvailability` does not change them, and they do not apply to source-key
|
|
185
210
|
rules or when `evaluateExpression` decides whether an expression is valid.
|
|
186
211
|
`getRuleExpressionFunctionDescriptions()` lists only the functions a preset
|
|
@@ -188,16 +213,17 @@ accepts, `url-rewrite-filter` by default as in validation; the
|
|
|
188
213
|
`logging-source-key` preset lists every function.
|
|
189
214
|
|
|
190
215
|
The observed behavior is recorded in
|
|
191
|
-
`src/rule-evaluator/engine-observations.generated.ts` by
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
`test/fixtures/rules-engine-probes.json`, and `npm test`
|
|
195
|
-
where this package's validator disagrees with the recorded
|
|
196
|
-
`CLOUDFLARE_API_TOKEN` (Zone Read
|
|
197
|
-
`CLOUDFLARE_ZONE_ID`,
|
|
198
|
-
|
|
199
|
-
`--write-probes <file>` and
|
|
200
|
-
`--responses <file>`, as described in the
|
|
216
|
+
`src/rule-evaluator/engine-observations.generated.ts` by `npm run
|
|
217
|
+
probe:rules-engine`, which dry-runs probe expressions against a URL rewrite
|
|
218
|
+
ruleset and a Custom Rules ruleset. It also records every probe with the
|
|
219
|
+
engine's verdict in `test/fixtures/rules-engine-probes.json`, and `npm test`
|
|
220
|
+
fails on any probe where this package's validator disagrees with the recorded
|
|
221
|
+
verdict. It needs `CLOUDFLARE_API_TOKEN` (Zone Read, Transform Rules Edit and
|
|
222
|
+
Zone WAF Edit), `CLOUDFLARE_ZONE_ID`, `CLOUDFLARE_URL_REWRITE_RULESET_ID`, and
|
|
223
|
+
`CLOUDFLARE_CUSTOM_RULES_RULESET_ID`, and never changes the rulesets. To probe
|
|
224
|
+
through another client, write the probe list with `--write-probes <file>` and
|
|
225
|
+
pass the API responses back with `--responses <file>`, as described in the
|
|
226
|
+
script.
|
|
201
227
|
|
|
202
228
|
## Rule Expression Evaluation
|
|
203
229
|
|
|
@@ -248,9 +274,10 @@ values are converted to that type, so a numeric `request.cf` value that
|
|
|
248
274
|
arrives as decimal text still compares as a number. Strings are ordered by code
|
|
249
275
|
point, which matches Cloudflare's byte order, with bytes that are not UTF-8
|
|
250
276
|
ordered as bytes, and IP addresses are compared as addresses rather than as
|
|
251
|
-
text.
|
|
252
|
-
|
|
253
|
-
|
|
277
|
+
text. IP addresses are ordered within one IP version: an IPv4 and an IPv6
|
|
278
|
+
address are unordered, so `lt`, `le`, `gt` and `ge` never match them. A
|
|
279
|
+
field value that does not represent its declared type, such as other text for
|
|
280
|
+
a Number field or a number for a String field, is unknown, with a warning.
|
|
254
281
|
|
|
255
282
|
### Literals and Inline Lists
|
|
256
283
|
|
|
@@ -303,6 +330,12 @@ other character, or at the end of a pattern, is an error, as is `**`. A
|
|
|
303
330
|
`wildcard_replace()` pattern can have at most eight `*`s, one for each of
|
|
304
331
|
`${1}` to `${8}`.
|
|
305
332
|
|
|
333
|
+
In the replacement of `wildcard_replace()` and `regex_replace()`, `${1}` stands
|
|
334
|
+
for the first capture and `$$` for a `$`, and in `regex_replace()`, `${0}` stands
|
|
335
|
+
for the whole match. Any other `$` is an error, and so are more than eight
|
|
336
|
+
references, or one past the pattern's captures. Validation does not count a
|
|
337
|
+
regex's captures, so it rejects only references past `${8}` there.
|
|
338
|
+
|
|
306
339
|
### Maps
|
|
307
340
|
|
|
308
341
|
The request header, cookie, and query argument maps are values too: functions
|
|
@@ -379,7 +412,8 @@ lists, where one `any()` for each array is usually what the rule means. Arrays
|
|
|
379
412
|
line up when they read the same field and access, directly or through a call
|
|
380
413
|
that gives each element a result, such as `lower()`, or when they come from one
|
|
381
414
|
list: the request header names and values, the query argument names and values,
|
|
382
|
-
or the response header names and values.
|
|
415
|
+
or the response header names and values. `filter()` calls over arrays that line
|
|
416
|
+
up do too when their conditions are the same. Raw fields are read before rewrites
|
|
383
417
|
and transforms, so the raw names and values make lists of their own. The
|
|
384
418
|
content scan arrays line up too, as Cloudflare documents them in the order the
|
|
385
419
|
objects were detected. Its documentation says nothing of the order of others,
|
|
@@ -393,11 +427,11 @@ elements settle it. An array may also hold more elements than it lists: when
|
|
|
393
427
|
`request.cf.requestHeaderNames` is cut, the request header arrays hold the
|
|
394
428
|
listed headers, and others at positions Worker context cannot tell. Their known
|
|
395
429
|
elements still pair with arrays that line up with them, as the warning counts
|
|
396
|
-
them, when each
|
|
397
|
-
settle the result counts only where every array surely
|
|
398
|
-
explain output words the reason for a predicate over several
|
|
399
|
-
pairs, as in `none of 4 paired element(s) satisfy its predicate`,
|
|
400
|
-
over a single array, such as a call's, by its elements, as in
|
|
430
|
+
them, when each lists as many and may lack the same ones, but not with other
|
|
431
|
+
arrays. A pair that would settle the result counts only where every array surely
|
|
432
|
+
has an element. The explain output words the reason for a predicate over several
|
|
433
|
+
arrays by their pairs, as in `none of 4 paired element(s) satisfy its predicate`,
|
|
434
|
+
and for one over a single array, such as a call's, by its elements, as in
|
|
401
435
|
`none of 4 element(s) satisfy its predicate`. When a call read as a value gives
|
|
402
436
|
nil, the reason says so, as in
|
|
403
437
|
`function 'starts_with' returned nil, which all() does not hold for`. In the
|
|
@@ -413,8 +447,8 @@ array of Booleans, one for each pair of its arrays, up to the shorter one (see
|
|
|
413
447
|
Quantifier Predicates). A comparison over `[*]` is such an argument, in
|
|
414
448
|
parentheses or not, and so is a call in parentheses that gives an array of
|
|
415
449
|
Booleans, as in `len((starts_with(http.request.headers.names[*], "x-")))`.
|
|
416
|
-
`len()`, `concat()`, `coalesce()` and `has_value()`'s collection
|
|
417
|
-
array, so
|
|
450
|
+
`len()`, `concat()`, `coalesce()`, `filter()` and `has_value()`'s collection
|
|
451
|
+
take the array, so
|
|
418
452
|
`any(concat((http.request.headers.names[*] eq "x-a"), (http.request.uri.args.names[*] eq "a")))`
|
|
419
453
|
holds when the request has the header or the query argument, without pairing
|
|
420
454
|
the two lists. No call maps over the array, so `len()` gives one Integer. A
|
|
@@ -426,13 +460,28 @@ uses the arguments after one. An element Worker context cannot tell keeps its
|
|
|
426
460
|
place as unknown, also through `concat()`, and `len()`, `has_value()`, `any()`
|
|
427
461
|
and `all()` read it only where their result depends on it.
|
|
428
462
|
|
|
463
|
+
`filter()`, which Cloudflare's reference lacks, gives the elements of its first
|
|
464
|
+
argument, an array, whose results in its second are true, so
|
|
465
|
+
`any(filter(http.request.headers.values, http.request.headers.names[*] eq "x-a")[*] eq "b")`
|
|
466
|
+
holds when an `x-a` header has the value `b`. Live requests on 2026-11-25 showed
|
|
467
|
+
that it pairs the two by index, stops at the shorter one, and gives an empty
|
|
468
|
+
array, not nil, when it keeps nothing. Over `[*]`, as in
|
|
469
|
+
`filter(http.request.uri.args[*], ...)`, each of the arrays pairs with the same
|
|
470
|
+
results. Cloudflare's `filter()` panics on a nil array, which fails the dry run of
|
|
471
|
+
a rule with `filter(http.request.headers["x"], ...)`, so validation rejects an
|
|
472
|
+
argument of it that may be nil, such as a map key's values, an array's element,
|
|
473
|
+
or a call over one, with `function.parameter.may_be_nil`. An element whose result
|
|
474
|
+
is unknown may be missing from its place among the elements kept, which leaves
|
|
475
|
+
the positions from there on unknown.
|
|
476
|
+
|
|
429
477
|
Validation checks each comparison over each element as a comparison of single
|
|
430
478
|
elements, with the `operator.*` diagnostics, and the array as its parameter's
|
|
431
479
|
value, so `lower((http.request.headers.names[*] eq "a"))` gets
|
|
432
480
|
`function.parameter.requires_typed_value`. Conditions with a result for each
|
|
433
481
|
element combine only with each other (`logical.operand_type_mismatch`), and
|
|
434
482
|
those over arrays from different lists get `array_expansion.unaligned_arrays`,
|
|
435
|
-
naming the function they are an argument of
|
|
483
|
+
naming the function they are an argument of, with `filter()`'s array among them.
|
|
484
|
+
Where a condition needs a single
|
|
436
485
|
result, as a whole expression or combined with one, a comparison over `[*]`
|
|
437
486
|
gets `array_expansion.direct_comparison`, and a call that gives an array of
|
|
438
487
|
Booleans gets `function.result_type_mismatch`. Dry runs on 2026-10-20 and
|
|
@@ -556,8 +605,8 @@ the solve, and the request goes where its unrewritten URL leads, which may
|
|
|
556
605
|
not be the Worker. Validation gives the notice
|
|
557
606
|
`field.header_dropped_on_challenge_solve` where a rule looks either header up
|
|
558
607
|
by name: by its key in the request headers, with `has_key()`, or among the
|
|
559
|
-
header names, with `has_value()` or by comparing each with the name in `any()
|
|
560
|
-
or `
|
|
608
|
+
header names, with `has_value()` or by comparing each with the name in `any()`,
|
|
609
|
+
`all()` or a function argument, such as `filter()`'s.
|
|
561
610
|
|
|
562
611
|
The evaluator takes a GET for a solve when its names list `Content-Length`,
|
|
563
612
|
`Content-Type` and `Origin` and the Worker has none of them. It then lists
|
|
@@ -581,10 +630,12 @@ Worker's other headers count once, and over HTTP/1 their names are lowercase
|
|
|
581
630
|
rather than the client's spelling. Cloudflare's order followed no protocol's
|
|
582
631
|
layout in the probes, so positions in the names and values follow the order
|
|
583
632
|
above, and validation warns where a rule reads them by index or through
|
|
584
|
-
`join()`, also by way of `coalesce()`, `concat()` and functions that
|
|
585
|
-
them, or where `any()` or `
|
|
633
|
+
`join()`, also by way of `coalesce()`, `concat()`, `filter()` and functions that
|
|
634
|
+
map over them, or where `any()`, `all()` or `filter()` pairs them with an array
|
|
635
|
+
from another list.
|
|
586
636
|
The raw header fields are unknown on a solve, so reading them in order gets no
|
|
587
|
-
such warning
|
|
637
|
+
such warning, and neither does a Custom Rule, which is never evaluated in Worker
|
|
638
|
+
context.
|
|
588
639
|
|
|
589
640
|
Cloudflare replays a challenged POST with its body, so it keeps its
|
|
590
641
|
`Content-Type` and is not taken for a solve. Cloudflare's header fields read
|
|
@@ -599,7 +650,7 @@ Cloudflare adds. Live requests compared them with Cloudflare's values over
|
|
|
599
650
|
HTTP/1.1, HTTP/2 and HTTP/3, and the evaluator follows what they showed:
|
|
600
651
|
|
|
601
652
|
- `cf.ray_id` adds the data center to the Worker's `CF-Ray`, as in
|
|
602
|
-
`8f1c2a3b4d5e6f70-LAX`.
|
|
653
|
+
`8f1c2a3b4d5e6f70-LAX`, and `cf.colo.code` reads it from `request.cf.colo`.
|
|
603
654
|
- `cf.edge.client_tcp` is false over HTTP/3 and true over the other HTTP
|
|
604
655
|
versions, which run over TCP. Cloudflare's `cf.timings.client_tcp_rtt_msec`
|
|
605
656
|
was 1 ms more than `request.cf.clientTcpRtt` in every TCP request probed, and
|
|
@@ -640,12 +691,15 @@ Values the evaluator cannot resolve are unknown rather than nil. These include
|
|
|
640
691
|
`raw.*` URI fields in Worker context, request metadata missing from the
|
|
641
692
|
request, such as `request.cf` properties or the `cf-connecting-ip` header behind
|
|
642
693
|
`ip.src`, which the Remove visitor IP headers Managed Transform removes, and
|
|
643
|
-
results of functions it cannot reproduce, such as the
|
|
644
|
-
`
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
694
|
+
results of functions it cannot reproduce, such as the HMAC functions and
|
|
695
|
+
`sign_sigv4_hmac_sha256()`, the hash functions `md5()`, `sha1()`, `sha256()`
|
|
696
|
+
and `sha512()`, and `is_jwt_valid()`,
|
|
697
|
+
or whose result holds more than 524,288 characters, counting each array element
|
|
698
|
+
as at least 8, or just 8 in `concat()` of arrays; the elements of an array that
|
|
699
|
+
fit stay known. An unknown value makes the functions and comparisons that use it
|
|
700
|
+
unknown. It also makes `not`, `and`, `or` and `xor` unknown, unless another
|
|
701
|
+
operand settles the result. An unknown result does not match, and the evaluation
|
|
702
|
+
warnings name the values involved.
|
|
649
703
|
|
|
650
704
|
Unresolved Cloudflare list references are the exception: they count as
|
|
651
705
|
inferred matches whenever assuming the list results alone can make the
|
|
@@ -862,7 +916,7 @@ Probes on a playground zone compared edge records with the rules engine's
|
|
|
862
916
|
values for the same requests, which a response header transform rule echoed
|
|
863
917
|
into the records (live requests, 2026-11-16 and 2026-11-17,
|
|
864
918
|
`test/fixtures/edge-record-probes.json`). The evaluator reads only what they
|
|
865
|
-
showed equal:
|
|
919
|
+
or other live requests showed equal, or what follows from it:
|
|
866
920
|
|
|
867
921
|
- `ip.src` reads the client address, and the location fields, Cloudflare's
|
|
868
922
|
ASN, country, city, region code, latitude and longitude. Logpush gives the
|
|
@@ -877,7 +931,10 @@ showed equal:
|
|
|
877
931
|
Worker's: the engine's was the record's plus 1 on every TCP request probed,
|
|
878
932
|
and on 15 production requests the Worker's equaled the record's. An RTT of
|
|
879
933
|
0 over TCP is unknown.
|
|
880
|
-
- `cf.ray_id` joins the Ray ID and the data center.
|
|
934
|
+
- `cf.ray_id` joins the Ray ID and the data center. The probes did not echo
|
|
935
|
+
`cf.colo.code`, which reads the data center, as it is the suffix of the
|
|
936
|
+
engine's Ray ID. Nor did they echo `http.request.headers.truncated` and its raw
|
|
937
|
+
form, which live requests with 1,000 headers showed false.
|
|
881
938
|
- `http.host`, `http.request.full_uri` and `raw.http.request.full_uri` read
|
|
882
939
|
the record's host, which Logpush gives in lowercase with any port or
|
|
883
940
|
trailing dot the client sent. The engine reads it without them, on any
|
|
@@ -11,42 +11,57 @@ export type ElementValue = Known<CfValue> | UnknownElement;
|
|
|
11
11
|
/** A map key's values, which can be known in part, as a header sent once with unknown text. */
|
|
12
12
|
export type MapEntryValue = Known<CfValue | PartialArrayValue> | UnknownElement;
|
|
13
13
|
export declare function isUnknownElement(element: MapEntryValue): element is UnknownElement;
|
|
14
|
+
/** An element of an array that the array may lack, and why it may. */
|
|
15
|
+
export declare class OptionalElement {
|
|
16
|
+
readonly element: ElementValue;
|
|
17
|
+
readonly reason: UnknownElement;
|
|
18
|
+
constructor(element: ElementValue, reason: UnknownElement);
|
|
19
|
+
}
|
|
20
|
+
/** An element a partly known array lists. */
|
|
21
|
+
export type ArrayElement = ElementValue | OptionalElement;
|
|
22
|
+
/** The element listed, as it is where the array has it. */
|
|
23
|
+
export declare function listedElement(listed: ArrayElement): ElementValue;
|
|
24
|
+
/** An element in the place of one listed, which an array lacks where it lacks that one. */
|
|
25
|
+
export declare function inPlaceOf(listed: ArrayElement, element: ElementValue): ArrayElement;
|
|
14
26
|
/**
|
|
15
|
-
* An array some of
|
|
16
|
-
* request header
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
27
|
+
* An array known in part while evaluating: some of its elements are unknown,
|
|
28
|
+
* as a request header's value that Worker context lacks, or it may lack some,
|
|
29
|
+
* as filter() may keep an element or not, or hold some it does not list, as a
|
|
30
|
+
* request header list that may be cut. What it lists is surely in order only
|
|
31
|
+
* before any element it does not list. Its known elements can still settle
|
|
32
|
+
* any() and all(), has_value(), and an index whose position is certain, and
|
|
33
|
+
* mapped calls, concat() and filter() keep them; anything else that reads the
|
|
34
|
+
* whole array is unknown. Arrays from one list still line up; see
|
|
35
|
+
* pairArrays().
|
|
22
36
|
*/
|
|
23
37
|
export declare class PartialArrayValue {
|
|
24
|
-
readonly elements: readonly
|
|
38
|
+
readonly elements: readonly ArrayElement[];
|
|
39
|
+
/** Why the array may hold elements it does not list, when it may. */
|
|
25
40
|
readonly more: UnknownElement | undefined;
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
readonly
|
|
41
|
+
/** How many of the elements listed come before any that is not. */
|
|
42
|
+
readonly moreFrom: number;
|
|
43
|
+
/** How many elements the array surely has. */
|
|
44
|
+
readonly shortest: number;
|
|
45
|
+
/** How many elements at its start have certain positions. */
|
|
46
|
+
readonly leading: number;
|
|
47
|
+
/** Why the array's length is unknown, when it is, and so are its positions past the leading ones. */
|
|
48
|
+
readonly unknownLength: UnknownElement | undefined;
|
|
30
49
|
private constructor();
|
|
31
50
|
/**
|
|
32
|
-
* An array of elements,
|
|
33
|
-
*
|
|
34
|
-
* conditions over a collection that may end early, `optional` lists them.
|
|
35
|
-
*/
|
|
36
|
-
static from(elements: readonly ElementValue[], more?: UnknownElement, optional?: readonly ElementValue[]): CfValue[] | PartialArrayValue;
|
|
37
|
-
/**
|
|
38
|
-
* Why the array may hold a matching element besides its known ones: its
|
|
39
|
-
* first unknown element, or that it may hold more, unless it may hold only
|
|
40
|
-
* optional elements, none of which match.
|
|
51
|
+
* An array of elements, known in part when one is unknown or may be lacking,
|
|
52
|
+
* or when it may hold `more`, which then come after the first `moreFrom`.
|
|
41
53
|
*/
|
|
54
|
+
static from(elements: readonly ArrayElement[], more?: UnknownElement, moreFrom?: number): CfValue[] | PartialArrayValue;
|
|
55
|
+
/** Why the array may hold a matching element besides the known ones it surely has, when it may. */
|
|
42
56
|
unknownMatch(matches: (value: CfValue) => boolean): UnknownElement | undefined;
|
|
43
|
-
/** Why the whole array is unknown
|
|
57
|
+
/** Why the whole array is unknown. */
|
|
44
58
|
unknown(): Unknown;
|
|
45
|
-
/** The
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
/** The first reason why the array is not known whole. */
|
|
60
|
+
firstUnknown(): UnknownElement;
|
|
61
|
+
/** The array without the elements it may lack, as ones it does not list. */
|
|
62
|
+
withoutOptional(): PartialArrayValue;
|
|
63
|
+
/** The values of the known elements the array surely has. */
|
|
64
|
+
knownValues(): CfValue[];
|
|
50
65
|
/** The element at an index, nil past the end. */
|
|
51
66
|
at(index: number): Evaluated<CfValue>;
|
|
52
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-values.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/access-values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1F;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC;AAE3C,sEAAsE;AACtE,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC;AAE3D,+FAA+F;AAC/F,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,GAAG,iBAAiB,CAAC,GAAG,cAAc,CAAC;AAEhF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,IAAI,cAAc,CAElF;
|
|
1
|
+
{"version":3,"file":"access-values.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/access-values.ts"],"names":[],"mappings":"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"}
|
|
@@ -3,78 +3,132 @@ import { isUnknown, known } from './outcome.js';
|
|
|
3
3
|
export function isUnknownElement(element) {
|
|
4
4
|
return typeof element === 'function';
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/** An element of an array that the array may lack, and why it may. */
|
|
7
|
+
export class OptionalElement {
|
|
8
|
+
element;
|
|
9
|
+
reason;
|
|
10
|
+
constructor(element, reason) {
|
|
11
|
+
this.element = element;
|
|
12
|
+
this.reason = reason;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** The element listed, as it is where the array has it. */
|
|
16
|
+
export function listedElement(listed) {
|
|
17
|
+
return listed instanceof OptionalElement ? listed.element : listed;
|
|
18
|
+
}
|
|
19
|
+
/** An element in the place of one listed, which an array lacks where it lacks that one. */
|
|
20
|
+
export function inPlaceOf(listed, element) {
|
|
21
|
+
return listed instanceof OptionalElement ? new OptionalElement(element, listed.reason) : element;
|
|
8
22
|
}
|
|
9
23
|
/**
|
|
10
|
-
* An array some of
|
|
11
|
-
* request header
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
24
|
+
* An array known in part while evaluating: some of its elements are unknown,
|
|
25
|
+
* as a request header's value that Worker context lacks, or it may lack some,
|
|
26
|
+
* as filter() may keep an element or not, or hold some it does not list, as a
|
|
27
|
+
* request header list that may be cut. What it lists is surely in order only
|
|
28
|
+
* before any element it does not list. Its known elements can still settle
|
|
29
|
+
* any() and all(), has_value(), and an index whose position is certain, and
|
|
30
|
+
* mapped calls, concat() and filter() keep them; anything else that reads the
|
|
31
|
+
* whole array is unknown. Arrays from one list still line up; see
|
|
32
|
+
* pairArrays().
|
|
17
33
|
*/
|
|
18
34
|
export class PartialArrayValue {
|
|
19
35
|
elements;
|
|
20
36
|
more;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
|
|
37
|
+
moreFrom;
|
|
38
|
+
/** How many elements the array surely has. */
|
|
39
|
+
shortest;
|
|
40
|
+
/** How many elements at its start have certain positions. */
|
|
41
|
+
leading;
|
|
42
|
+
/** Why the array's length is unknown, when it is, and so are its positions past the leading ones. */
|
|
43
|
+
unknownLength;
|
|
44
|
+
constructor(elements,
|
|
45
|
+
/** Why the array may hold elements it does not list, when it may. */
|
|
46
|
+
more,
|
|
47
|
+
/** How many of the elements listed come before any that is not. */
|
|
48
|
+
moreFrom) {
|
|
28
49
|
this.elements = elements;
|
|
29
50
|
this.more = more;
|
|
30
|
-
this.
|
|
31
|
-
|
|
51
|
+
this.moreFrom = moreFrom;
|
|
52
|
+
let optional = 0;
|
|
53
|
+
let leading = moreFrom;
|
|
54
|
+
let unknownLength = more;
|
|
55
|
+
for (let index = 0; index < elements.length; index++) {
|
|
56
|
+
const listed = elements[index];
|
|
57
|
+
if (!(listed instanceof OptionalElement))
|
|
58
|
+
continue;
|
|
59
|
+
optional++;
|
|
60
|
+
if (index < leading) {
|
|
61
|
+
leading = index;
|
|
62
|
+
unknownLength = listed.reason;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this.shortest = elements.length - optional;
|
|
66
|
+
this.leading = leading;
|
|
67
|
+
this.unknownLength = unknownLength;
|
|
32
68
|
}
|
|
33
69
|
/**
|
|
34
|
-
* An array of elements,
|
|
35
|
-
*
|
|
36
|
-
* conditions over a collection that may end early, `optional` lists them.
|
|
70
|
+
* An array of elements, known in part when one is unknown or may be lacking,
|
|
71
|
+
* or when it may hold `more`, which then come after the first `moreFrom`.
|
|
37
72
|
*/
|
|
38
|
-
static from(elements, more,
|
|
73
|
+
static from(elements, more, moreFrom = 0) {
|
|
74
|
+
if (more)
|
|
75
|
+
return new PartialArrayValue(elements, more, moreFrom);
|
|
39
76
|
const values = [];
|
|
40
|
-
for (const
|
|
41
|
-
if (isUnknownElement(
|
|
42
|
-
return new PartialArrayValue(elements,
|
|
43
|
-
values.push(
|
|
77
|
+
for (const listed of elements) {
|
|
78
|
+
if (listed instanceof OptionalElement || isUnknownElement(listed))
|
|
79
|
+
return new PartialArrayValue(elements, undefined, elements.length);
|
|
80
|
+
values.push(listed.value);
|
|
44
81
|
}
|
|
45
|
-
return
|
|
82
|
+
return values;
|
|
46
83
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Why the array may hold a matching element besides its known ones: its
|
|
49
|
-
* first unknown element, or that it may hold more, unless it may hold only
|
|
50
|
-
* optional elements, none of which match.
|
|
51
|
-
*/
|
|
84
|
+
/** Why the array may hold a matching element besides the known ones it surely has, when it may. */
|
|
52
85
|
unknownMatch(matches) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (const element of this.optional) {
|
|
86
|
+
for (const listed of this.elements) {
|
|
87
|
+
const element = listedElement(listed);
|
|
56
88
|
if (isUnknownElement(element))
|
|
57
89
|
return element;
|
|
58
|
-
if (matches(element.value))
|
|
59
|
-
return
|
|
90
|
+
if (listed instanceof OptionalElement && matches(element.value))
|
|
91
|
+
return listed.reason;
|
|
60
92
|
}
|
|
61
|
-
return
|
|
93
|
+
return this.more;
|
|
62
94
|
}
|
|
63
|
-
/** Why the whole array is unknown
|
|
95
|
+
/** Why the whole array is unknown. */
|
|
64
96
|
unknown() {
|
|
65
|
-
return this.firstUnknown();
|
|
97
|
+
return this.firstUnknown()();
|
|
66
98
|
}
|
|
67
|
-
/** The
|
|
99
|
+
/** The first reason why the array is not known whole. */
|
|
100
|
+
firstUnknown() {
|
|
101
|
+
for (const listed of this.elements) {
|
|
102
|
+
if (listed instanceof OptionalElement)
|
|
103
|
+
return listed.reason;
|
|
104
|
+
if (isUnknownElement(listed))
|
|
105
|
+
return listed;
|
|
106
|
+
}
|
|
107
|
+
return this.more;
|
|
108
|
+
}
|
|
109
|
+
/** The array without the elements it may lack, as ones it does not list. */
|
|
110
|
+
withoutOptional() {
|
|
111
|
+
if (this.shortest === this.elements.length)
|
|
112
|
+
return this;
|
|
113
|
+
return new PartialArrayValue(this.elements.filter(listed => !(listed instanceof OptionalElement)), this.unknownLength, this.leading);
|
|
114
|
+
}
|
|
115
|
+
/** The values of the known elements the array surely has. */
|
|
68
116
|
knownValues() {
|
|
69
|
-
const values =
|
|
70
|
-
|
|
117
|
+
const values = [];
|
|
118
|
+
for (const listed of this.elements) {
|
|
119
|
+
if (!(listed instanceof OptionalElement || isUnknownElement(listed)))
|
|
120
|
+
values.push(listed.value);
|
|
121
|
+
}
|
|
122
|
+
return values;
|
|
71
123
|
}
|
|
72
124
|
/** The element at an index, nil past the end. */
|
|
73
125
|
at(index) {
|
|
74
|
-
if (this.more)
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
126
|
+
if (index >= this.elements.length && !this.more)
|
|
127
|
+
return known(null);
|
|
128
|
+
if (index >= this.leading)
|
|
129
|
+
return this.unknownLength();
|
|
130
|
+
const element = listedElement(this.elements[index]);
|
|
131
|
+
return isUnknownElement(element) ? element() : element;
|
|
78
132
|
}
|
|
79
133
|
}
|
|
80
134
|
/**
|
|
@@ -136,7 +190,7 @@ export class RuleMapValue {
|
|
|
136
190
|
if (isUnknownElement(value))
|
|
137
191
|
return value;
|
|
138
192
|
// As one element, values known in part are unknown, and may stand for any number of values.
|
|
139
|
-
return value.value instanceof PartialArrayValue ? value.value.
|
|
193
|
+
return value.value instanceof PartialArrayValue ? value.value.firstUnknown() : known(value.value ?? []);
|
|
140
194
|
});
|
|
141
195
|
return PartialArrayValue.from(elements, this.more);
|
|
142
196
|
}
|
|
@@ -175,16 +229,33 @@ export function applyRuntimeAccessPath(value, accessPath) {
|
|
|
175
229
|
}
|
|
176
230
|
/**
|
|
177
231
|
* Applies the access after a `[*]` to each element. An unknown element can
|
|
178
|
-
* give any number of results, so with access after it,
|
|
232
|
+
* give any number of results, so with access after it, its results are not
|
|
233
|
+
* listed.
|
|
179
234
|
*/
|
|
180
235
|
function applyExpandedAccess(array, rest) {
|
|
181
236
|
if (!(array instanceof PartialArrayValue))
|
|
182
237
|
return applyArrayAccessPath(array, rest, true);
|
|
183
238
|
if (rest.length === 0)
|
|
184
239
|
return array;
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
240
|
+
const results = [];
|
|
241
|
+
let unknown;
|
|
242
|
+
let { moreFrom } = array;
|
|
243
|
+
let resultsFrom = 0;
|
|
244
|
+
array.elements.forEach((listed, index) => {
|
|
245
|
+
const element = listedElement(listed);
|
|
246
|
+
if (isUnknownElement(element)) {
|
|
247
|
+
unknown ??= element;
|
|
248
|
+
moreFrom = Math.min(moreFrom, index);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const values = applyArrayAccessPath([element.value], rest, true);
|
|
252
|
+
if (Array.isArray(values))
|
|
253
|
+
for (const value of values)
|
|
254
|
+
results.push(inPlaceOf(listed, known(value)));
|
|
255
|
+
if (index < moreFrom)
|
|
256
|
+
resultsFrom = results.length;
|
|
257
|
+
});
|
|
258
|
+
return PartialArrayValue.from(results, unknown ?? array.more, resultsFrom);
|
|
188
259
|
}
|
|
189
260
|
/**
|
|
190
261
|
* Applies postfix array access while preserving Cloudflare's vectorized `[*]`
|