@libreflare/worker-runtime 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/README.md +342 -22
  2. package/dist/rule-evaluator/accept-encoding.d.ts +3 -2
  3. package/dist/rule-evaluator/accept-encoding.d.ts.map +1 -1
  4. package/dist/rule-evaluator/accept-encoding.js +80 -35
  5. package/dist/rule-evaluator/accept-encoding.js.map +1 -1
  6. package/dist/rule-evaluator/access-values.d.ts +84 -1
  7. package/dist/rule-evaluator/access-values.d.ts.map +1 -1
  8. package/dist/rule-evaluator/access-values.js +165 -13
  9. package/dist/rule-evaluator/access-values.js.map +1 -1
  10. package/dist/rule-evaluator/analysis.d.ts +44 -13
  11. package/dist/rule-evaluator/analysis.d.ts.map +1 -1
  12. package/dist/rule-evaluator/analysis.js +82 -65
  13. package/dist/rule-evaluator/analysis.js.map +1 -1
  14. package/dist/rule-evaluator/ast.d.ts +165 -11
  15. package/dist/rule-evaluator/ast.d.ts.map +1 -1
  16. package/dist/rule-evaluator/ast.js +106 -3
  17. package/dist/rule-evaluator/ast.js.map +1 -1
  18. package/dist/rule-evaluator/byte-strings.d.ts +23 -0
  19. package/dist/rule-evaluator/byte-strings.d.ts.map +1 -0
  20. package/dist/rule-evaluator/byte-strings.js +150 -0
  21. package/dist/rule-evaluator/byte-strings.js.map +1 -0
  22. package/dist/rule-evaluator/constants.d.ts +7 -3
  23. package/dist/rule-evaluator/constants.d.ts.map +1 -1
  24. package/dist/rule-evaluator/constants.js +8 -1
  25. package/dist/rule-evaluator/constants.js.map +1 -1
  26. package/dist/rule-evaluator/country-codes.generated.js +1 -1
  27. package/dist/rule-evaluator/custom-lists.d.ts +15 -0
  28. package/dist/rule-evaluator/custom-lists.d.ts.map +1 -1
  29. package/dist/rule-evaluator/custom-lists.js +64 -1
  30. package/dist/rule-evaluator/custom-lists.js.map +1 -1
  31. package/dist/rule-evaluator/diagnostics.d.ts +10 -9
  32. package/dist/rule-evaluator/diagnostics.d.ts.map +1 -1
  33. package/dist/rule-evaluator/diagnostics.js +32 -52
  34. package/dist/rule-evaluator/diagnostics.js.map +1 -1
  35. package/dist/rule-evaluator/engine-observations.d.ts +37 -0
  36. package/dist/rule-evaluator/engine-observations.d.ts.map +1 -0
  37. package/dist/rule-evaluator/engine-observations.generated.d.ts +991 -0
  38. package/dist/rule-evaluator/engine-observations.generated.d.ts.map +1 -0
  39. package/dist/rule-evaluator/engine-observations.generated.js +292 -0
  40. package/dist/rule-evaluator/engine-observations.generated.js.map +1 -0
  41. package/dist/rule-evaluator/engine-observations.js +13 -0
  42. package/dist/rule-evaluator/engine-observations.js.map +1 -0
  43. package/dist/rule-evaluator/evaluator.d.ts +10 -3
  44. package/dist/rule-evaluator/evaluator.d.ts.map +1 -1
  45. package/dist/rule-evaluator/evaluator.js +91 -83
  46. package/dist/rule-evaluator/evaluator.js.map +1 -1
  47. package/dist/rule-evaluator/explain.d.ts +11 -2
  48. package/dist/rule-evaluator/explain.d.ts.map +1 -1
  49. package/dist/rule-evaluator/explain.js +234 -123
  50. package/dist/rule-evaluator/explain.js.map +1 -1
  51. package/dist/rule-evaluator/field-availability.d.ts +11 -10
  52. package/dist/rule-evaluator/field-availability.d.ts.map +1 -1
  53. package/dist/rule-evaluator/field-availability.js +136 -97
  54. package/dist/rule-evaluator/field-availability.js.map +1 -1
  55. package/dist/rule-evaluator/field-descriptions.generated.d.ts +114 -1
  56. package/dist/rule-evaluator/field-descriptions.generated.d.ts.map +1 -1
  57. package/dist/rule-evaluator/field-descriptions.generated.js +261 -1
  58. package/dist/rule-evaluator/field-descriptions.generated.js.map +1 -1
  59. package/dist/rule-evaluator/field-value-domains.d.ts.map +1 -1
  60. package/dist/rule-evaluator/field-value-domains.js +2 -4
  61. package/dist/rule-evaluator/field-value-domains.js.map +1 -1
  62. package/dist/rule-evaluator/fields.d.ts +37 -4
  63. package/dist/rule-evaluator/fields.d.ts.map +1 -1
  64. package/dist/rule-evaluator/fields.js +387 -87
  65. package/dist/rule-evaluator/fields.js.map +1 -1
  66. package/dist/rule-evaluator/function-availability.d.ts +16 -0
  67. package/dist/rule-evaluator/function-availability.d.ts.map +1 -0
  68. package/dist/rule-evaluator/function-availability.js +28 -0
  69. package/dist/rule-evaluator/function-availability.js.map +1 -0
  70. package/dist/rule-evaluator/function-descriptions.d.ts +15 -1
  71. package/dist/rule-evaluator/function-descriptions.d.ts.map +1 -1
  72. package/dist/rule-evaluator/function-descriptions.generated.d.ts +63 -7
  73. package/dist/rule-evaluator/function-descriptions.generated.d.ts.map +1 -1
  74. package/dist/rule-evaluator/function-descriptions.generated.js +122 -12
  75. package/dist/rule-evaluator/function-descriptions.generated.js.map +1 -1
  76. package/dist/rule-evaluator/function-descriptions.js +11 -2
  77. package/dist/rule-evaluator/function-descriptions.js.map +1 -1
  78. package/dist/rule-evaluator/function-signature-validation.d.ts +27 -3
  79. package/dist/rule-evaluator/function-signature-validation.d.ts.map +1 -1
  80. package/dist/rule-evaluator/function-signature-validation.js +351 -170
  81. package/dist/rule-evaluator/function-signature-validation.js.map +1 -1
  82. package/dist/rule-evaluator/functions.d.ts +38 -6
  83. package/dist/rule-evaluator/functions.d.ts.map +1 -1
  84. package/dist/rule-evaluator/functions.js +549 -279
  85. package/dist/rule-evaluator/functions.js.map +1 -1
  86. package/dist/rule-evaluator/hash-in-range.d.ts +33 -0
  87. package/dist/rule-evaluator/hash-in-range.d.ts.map +1 -0
  88. package/dist/rule-evaluator/hash-in-range.js +72 -0
  89. package/dist/rule-evaluator/hash-in-range.js.map +1 -0
  90. package/dist/rule-evaluator/log-sample.d.ts.map +1 -1
  91. package/dist/rule-evaluator/log-sample.js +14 -6
  92. package/dist/rule-evaluator/log-sample.js.map +1 -1
  93. package/dist/rule-evaluator/match-chain.d.ts +3 -3
  94. package/dist/rule-evaluator/match-chain.d.ts.map +1 -1
  95. package/dist/rule-evaluator/match-chain.js +19 -13
  96. package/dist/rule-evaluator/match-chain.js.map +1 -1
  97. package/dist/rule-evaluator/minifier.d.ts +2 -6
  98. package/dist/rule-evaluator/minifier.d.ts.map +1 -1
  99. package/dist/rule-evaluator/minifier.js +24 -28
  100. package/dist/rule-evaluator/minifier.js.map +1 -1
  101. package/dist/rule-evaluator/normalizer.d.ts +2 -6
  102. package/dist/rule-evaluator/normalizer.d.ts.map +1 -1
  103. package/dist/rule-evaluator/normalizer.js +13 -13
  104. package/dist/rule-evaluator/normalizer.js.map +1 -1
  105. package/dist/rule-evaluator/operators.d.ts +30 -4
  106. package/dist/rule-evaluator/operators.d.ts.map +1 -1
  107. package/dist/rule-evaluator/operators.js +217 -132
  108. package/dist/rule-evaluator/operators.js.map +1 -1
  109. package/dist/rule-evaluator/outcome.d.ts +65 -0
  110. package/dist/rule-evaluator/outcome.d.ts.map +1 -0
  111. package/dist/rule-evaluator/outcome.js +82 -0
  112. package/dist/rule-evaluator/outcome.js.map +1 -0
  113. package/dist/rule-evaluator/parse-cache.d.ts +3 -3
  114. package/dist/rule-evaluator/parse-cache.d.ts.map +1 -1
  115. package/dist/rule-evaluator/parse-cache.js +5 -13
  116. package/dist/rule-evaluator/parse-cache.js.map +1 -1
  117. package/dist/rule-evaluator/parser.d.ts +325 -12
  118. package/dist/rule-evaluator/parser.d.ts.map +1 -1
  119. package/dist/rule-evaluator/parser.js +1351 -340
  120. package/dist/rule-evaluator/parser.js.map +1 -1
  121. package/dist/rule-evaluator/quantifier.d.ts +2 -2
  122. package/dist/rule-evaluator/quantifier.d.ts.map +1 -1
  123. package/dist/rule-evaluator/quantifier.js +1 -16
  124. package/dist/rule-evaluator/quantifier.js.map +1 -1
  125. package/dist/rule-evaluator/request-headers.d.ts +101 -0
  126. package/dist/rule-evaluator/request-headers.d.ts.map +1 -0
  127. package/dist/rule-evaluator/request-headers.js +344 -0
  128. package/dist/rule-evaluator/request-headers.js.map +1 -0
  129. package/dist/rule-evaluator/rule-language-types.d.ts +84 -23
  130. package/dist/rule-evaluator/rule-language-types.d.ts.map +1 -1
  131. package/dist/rule-evaluator/rule-language-types.js +266 -76
  132. package/dist/rule-evaluator/rule-language-types.js.map +1 -1
  133. package/dist/rule-evaluator/tokenizer.d.ts +14 -4
  134. package/dist/rule-evaluator/tokenizer.d.ts.map +1 -1
  135. package/dist/rule-evaluator/tokenizer.js +49 -11
  136. package/dist/rule-evaluator/tokenizer.js.map +1 -1
  137. package/dist/rule-evaluator/transformation.d.ts.map +1 -1
  138. package/dist/rule-evaluator/transformation.js +10 -6
  139. package/dist/rule-evaluator/transformation.js.map +1 -1
  140. package/dist/rule-evaluator/url-decode.d.ts +8 -0
  141. package/dist/rule-evaluator/url-decode.d.ts.map +1 -0
  142. package/dist/rule-evaluator/url-decode.js +126 -0
  143. package/dist/rule-evaluator/url-decode.js.map +1 -0
  144. package/dist/rule-evaluator/validation.d.ts +8 -9
  145. package/dist/rule-evaluator/validation.d.ts.map +1 -1
  146. package/dist/rule-evaluator/validation.js +544 -253
  147. package/dist/rule-evaluator/validation.js.map +1 -1
  148. package/dist/rule-evaluator.d.ts +5 -5
  149. package/dist/rule-evaluator.d.ts.map +1 -1
  150. package/dist/rule-evaluator.js +1 -1
  151. package/dist/rule-evaluator.js.map +1 -1
  152. package/package.json +6 -3
  153. package/dist/rule-evaluator/custom-security-rule-analysis.d.ts +0 -36
  154. package/dist/rule-evaluator/custom-security-rule-analysis.d.ts.map +0 -1
  155. package/dist/rule-evaluator/custom-security-rule-analysis.js +0 -382
  156. package/dist/rule-evaluator/custom-security-rule-analysis.js.map +0 -1
  157. package/dist/rule-evaluator/warnings.d.ts +0 -2
  158. package/dist/rule-evaluator/warnings.d.ts.map +0 -1
  159. package/dist/rule-evaluator/warnings.js +0 -5
  160. package/dist/rule-evaluator/warnings.js.map +0 -1
package/README.md CHANGED
@@ -1,35 +1,23 @@
1
1
  # @libreflare/worker-runtime
2
2
 
3
- Shared runtime utilities for Libreflare-managed Cloudflare Workers.
3
+ Shared runtime utilities for Libreflare-managed Cloudflare Workers: request
4
+ handling and logging for managed Workers, and the Cloudflare Rules expression
5
+ tooling behind them.
4
6
 
5
- ## Package Contents
7
+ The package root exports everything. The `./rule-evaluator`,
8
+ `./runtime-config`, and `./log-handler` entry points export each part on its
9
+ own.
10
+
11
+ ## Request Handling
6
12
 
7
13
  - `handleRequest`: batched logging request handler for managed logging Workers.
8
14
  - `handleLibreflareRequest`: generated-config route/logging request handler. Pass `runtimeConfig` from a generated JSON import, or rely on the legacy `LIBREFLARE_CONFIG` env binding. For route-only v2 config, pass `apiURL`, `getSourceKey`, `apiAuthHeaders`, and related options to keep logging owned by the Worker repository.
9
- - `evaluateExpression`: Cloudflare Rules expression evaluator for Worker-side diagnostics. Unresolved Cloudflare list references are inferred as matches by default and can be disabled via options.
10
- - `analyzeRuleExpression`: versioned, JSON-safe Cloudflare Rules AST, symbol metadata, and optional block-comment metadata for dashboard inference.
11
- - `foldRuleExpressionAst`: bottom-up public AST reducer for custom dashboard inference.
12
- - `getRuleExpressionFieldDescriptions`: field descriptions filtered by the same preset and field availability override shape used by rule expression validation.
13
- - `RULE_EXPRESSION_COUNTRY_CODES`: generated ISO 3166-1 alpha-2 country codes plus Cloudflare's `T1` and `XX` special values, used by field metadata and semantic validation.
14
- - `getRuleExpressionFunctionDescriptions`: function reference metadata for dashboard editors, including signatures, return types, parameter roles, and evaluator support notes.
15
- - `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.
16
- - `normalizeRuleExpression`: syntax-aware readable formatter that preserves operator notation, grouping, and string literal spelling while canonicalizing grammar whitespace.
17
- - `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`.
18
- - `validateLoggingSourceKeyRuleExpressionSyntax`: runtime-only source-key rule validation using the pre-origin field context, without Custom List references or deployment length enforcement.
19
15
  - `parseLibreflareRuntimeConfig`: validates an object or JSON string against the runtime configuration contract.
20
16
 
21
17
  Version 2 runtime config accepts `routes: []` for a managed Worker that does not
22
18
  currently serve any Libreflare route. Such a config has no matching request
23
19
  path until a route is added.
24
20
 
25
- Rule expression validation, analysis, normalization, and minification expose structured
26
- `diagnostics` with stable `id`, explicit `severity`, and interpolation `params`
27
- for localization. The diagnostic `message` is an optional, deprecated
28
- compatibility field. The legacy `errors` and `warnings` string arrays on
29
- validation results, and `warnings` on analysis, normalization, and minification results, are also
30
- deprecated compatibility fields; new integrations should derive user-visible
31
- messages from diagnostic IDs and params.
32
-
33
21
  `handleRequest` calls that provide a custom `originFetcher` without
34
22
  `stripWorkerRoutePrefix` are deprecated. When `stripWorkerRoutePrefix` is
35
23
  configured, origin fetching and rule evaluation both use the stripped origin
@@ -40,6 +28,331 @@ config to add `request.client_hostname` to log events. The runtime performs a
40
28
  bounded reverse DNS lookup for the `cf-connecting-ip` header during the existing
41
29
  background logging work and caches resolved hostnames per Worker isolate.
42
30
 
31
+ ## Rule Expressions
32
+
33
+ Evaluation:
34
+
35
+ - `evaluateExpression`: Cloudflare Rules expression evaluator for Worker-side diagnostics. See [Rule Expression Evaluation](#rule-expression-evaluation).
36
+
37
+ Analysis:
38
+
39
+ - `analyzeRuleExpression`: versioned, JSON-safe Cloudflare Rules AST, symbol metadata, and optional block-comment metadata for dashboard inference.
40
+ - `foldRuleExpressionAst`: bottom-up public AST reducer for custom dashboard inference.
41
+
42
+ Validation:
43
+
44
+ - `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`.
45
+ - `validateLoggingSourceKeyRuleExpressionSyntax`: runtime-only source-key rule validation using the pre-origin field context, without Custom List references or deployment length enforcement.
46
+
47
+ Formatting:
48
+
49
+ - `normalizeRuleExpression`: syntax-aware readable formatter that preserves operator notation, grouping, and string literal spelling while canonicalizing grammar whitespace.
50
+ - `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.
51
+
52
+ Reference metadata for dashboard editors:
53
+
54
+ - `getRuleExpressionFieldDescriptions`: field descriptions filtered by the same preset and field availability override shape used by rule expression validation.
55
+ - `getRuleExpressionFunctionDescriptions`: function reference metadata, including signatures, return types, parameter roles, and evaluator support notes, filtered by preset like field descriptions.
56
+ - `RULE_EXPRESSION_COUNTRY_CODES`: generated ISO 3166-1 alpha-2 country codes plus Cloudflare's `T1` and `XX` special values, used by field metadata and semantic validation.
57
+
58
+ ### Diagnostics
59
+
60
+ Rule expression validation, analysis, normalization, and minification expose structured
61
+ `diagnostics` with stable `id`, explicit `severity`, and interpolation `params`
62
+ for localization. Each result always includes the diagnostics array. Validation
63
+ and analysis diagnostics identify their source expression, while normalization
64
+ and minification diagnostics apply directly to their single input expression.
65
+ Integrations derive user-visible messages from diagnostic IDs and params.
66
+
67
+ ### Analysis of Invalid Expressions
68
+
69
+ `analyzeRuleExpression` also returns an AST for an expression with syntax
70
+ errors, and keeps its valid parts. Syntax with an error is an `Invalid` node,
71
+ with its source text in `raw` and its `span`, wherever a condition, a function
72
+ argument, or a value belongs; its `raw` is empty where nothing is written, as
73
+ in the argument slot a stray comma leaves. A field or function call that the
74
+ error cut short, which may have been a comparison's left side, as `http.host`
75
+ in `http.host * "x"`, is the `operand` of its `Invalid` node, and the symbols
76
+ list it. An access segment with an error is `{ kind: 'invalid', raw, span }`
77
+ in its `accessPath`, and an inline list member with an error is an `Invalid`
78
+ node among the list's `values`, whose `elementType` comes from the valid
79
+ members.
80
+ What invalid input keeps from being known is unknown, never guessed: a value
81
+ whose type depends on invalid input has `valueType: 'Unknown'`, such as a field
82
+ with an invalid access segment, or a call whose result type comes from an
83
+ invalid argument: one to a function that can map over its first argument, as
84
+ `lower()` and `concat()` can, or to `coalesce()`, which returns its arguments'
85
+ type. Any other function keeps its catalog type, as `cidr()` returns an IP
86
+ address whatever its arguments are. A call to a function that can map over its
87
+ first argument has `evaluationMode: 'unknown'` in its node and its symbol when
88
+ that argument is invalid, or a syntax error left it uncertain.
89
+ `declaredReturnType` stays the function's catalog type.
90
+
91
+ ### Documented and Observed Behavior
92
+
93
+ Where Cloudflare's documentation and its ruleset engine disagree, validation
94
+ follows the engine, as observed with dry-run rule validation. For example, URL
95
+ rewrite expressions accept every field URL rewrite filters accept,
96
+ `hash_in_range()` takes one seed, `lookup_json_*()` keys must be literals,
97
+ header map keys such as `http.request.headers["x-a"]` must be lowercase, and
98
+ integer literals must fit in 64 bits, with a leading `0` making one octal. Field availability keeps each preset's
99
+ documented fields and the observed differences apart, and `fieldAvailability`
100
+ can still allow a field the engine was observed to reject. Source-key rules run
101
+ in the Worker rather than in a Cloudflare phase, so the URL rewrite phase's
102
+ observed differences do not apply to them.
103
+
104
+ Cloudflare does not document how `hash_in_range()` hashes, and may change it
105
+ without notice. The evaluator reproduces the results Cloudflare returned to
106
+ live requests, recorded in
107
+ [`test/fixtures/hash-in-range-probes.json`](https://github.com/Func86/libreflare-worker-runtime/blob/master/test/fixtures/hash-in-range-probes.json).
108
+ That includes results outside the range once a bound is beyond 2^53, where
109
+ Cloudflare's floating-point arithmetic rounds. Strings are hashed as the bytes
110
+ they hold, but a request value whose bytes are not valid UTF-8 can reach the
111
+ Worker changed, and then hashes differently. A missing (nil) seed gives nil, as
112
+ in Cloudflare, so `coalesce()` can supply a fallback.
113
+
114
+ Cloudflare's string functions work on bytes, as live requests showed:
115
+ `lower()`, `upper()` and case-insensitive wildcards fold ASCII letters only,
116
+ `len()` and `substring()` count bytes, and `remove_bytes()` removes each listed
117
+ byte. `url_decode()` keeps invalid escapes, and its `r` option repeats until
118
+ nothing changes. `decode_base64()` gives nil for input that is not standard
119
+ Base64. `to_string()` prints IPv6 addresses compressed, as in `2001:db8::1`,
120
+ and so do `cidr()` and `cidr6()`. A result that is not valid UTF-8 keeps its
121
+ bytes, such as a `substring()` that splits a character or a `url_decode()` of
122
+ `%FF`, and comparisons, `len()` and `hash_in_range()` read them as Cloudflare
123
+ does. `lookup_json_string()` and `lookup_json_integer()` give nil when such
124
+ bytes are in a key of an object on the path or in the string looked up.
125
+
126
+ The evaluator holds integers as JavaScript numbers, so integers beyond 2^53 are
127
+ approximate: literals, `lookup_json_integer()` values and `hash_in_range()`
128
+ results that large round, and so do the comparisons and `to_string()` output
129
+ that use them. An integer `hash_in_range()` seed that large gives an unknown
130
+ result instead, since a rounded seed hashes into an unrelated bucket.
131
+
132
+ URL rewrite filters and rewrite targets also reject the functions the URL
133
+ rewrite phase does not accept, such as `split()` in either and `to_string()`
134
+ in filters, with `function.unavailable`. Rewrite targets reject operators,
135
+ quantifiers, and conditions used as function arguments, such as `eq`, `any()`,
136
+ and `to_string((ssl))`, with `operator.unavailable`. In both,
137
+ `concat()`, `regex_replace()`, and `wildcard_replace()` can appear only once,
138
+ and the replacement functions cannot be nested. These phase rules depend on the
139
+ preset alone: `fieldAvailability` does not change them, and they do not apply
140
+ to source-key rules or when `evaluateExpression` decides whether an expression
141
+ is valid.
142
+ `getRuleExpressionFunctionDescriptions()` lists only the functions a preset
143
+ accepts, `url-rewrite-filter` by default as in validation; the
144
+ `logging-source-key` preset lists every function.
145
+
146
+ The observed behavior is recorded in
147
+ `src/rule-evaluator/engine-observations.generated.ts` by
148
+ `npm run probe:rules-engine`, which dry-runs probe expressions against a URL
149
+ rewrite ruleset. It also records every probe with the engine's verdict in
150
+ `test/fixtures/rules-engine-probes.json`, and `npm test` fails on any probe
151
+ where this package's validator disagrees with the recorded verdict. It needs
152
+ `CLOUDFLARE_API_TOKEN` (Zone Read and Transform Rules Edit),
153
+ `CLOUDFLARE_ZONE_ID`, and `CLOUDFLARE_URL_REWRITE_RULESET_ID`, and never changes
154
+ the ruleset. To probe through another client, write the probe list with
155
+ `--write-probes <file>` and pass the API responses back with
156
+ `--responses <file>`, as described in the script.
157
+
158
+ ## Rule Expression Evaluation
159
+
160
+ ### Valid Expressions Only
161
+
162
+ `evaluateExpression` and `explainExpressionMatch` evaluate only expressions
163
+ Cloudflare accepts. An expression with a syntax error, a type mismatch such as
164
+ a Number compared with a String, an invalid function call such as `coalesce()`
165
+ with one argument, or a field on the right of an operator other than `eq`,
166
+ `ne`, `lt`, `le`, `gt` or `ge` is not evaluated and does not match, even if
167
+ another branch would match. The warnings list the validation errors. Field
168
+ availability is not part of this check, but unknown fields are.
169
+
170
+ ### Comparisons and Missing Values
171
+
172
+ The right side of `eq`, `ne`, `lt`, `le`, `gt`, and `ge` can be a field,
173
+ indexed value, or function result, as in
174
+ `http.request.uri.path ne raw.http.request.uri.path`, and `coalesce()` provides
175
+ a fallback for missing values. `evaluateExpression` applies Cloudflare's
176
+ missing-value (nil) comparison results to absent map keys, out-of-bounds
177
+ indexes, and nil function results. For example, both sides being missing makes
178
+ `eq` true, and one missing side makes `ne` true.
179
+
180
+ A function argument can also be a condition, which is a Boolean value that is
181
+ never nil. For example, `has_value(http.request.uri.args["a"], "x")` is nil
182
+ when the `a` query argument is missing, so
183
+ `coalesce(has_value(http.request.uri.args["a"], "x"), http.host eq "x")` then
184
+ falls back to the comparison. As in Cloudflare, an argument that starts with
185
+ `(`, `not`, `any()` or `all()` is always a condition. It can combine
186
+ conditions with `and`, `or` and `xor`, while any other argument needs
187
+ parentheses around them, as in `(http.host eq "x" or ssl)`. A function call in
188
+ such parentheses is a condition too: it must return a Boolean, and a nil
189
+ result counts as false, so with the `a` query argument missing,
190
+ `coalesce((has_value(http.request.uri.args["a"], "x")), ssl)` is false. Since
191
+ conditions are never nil, validation warns that `coalesce()` never uses the
192
+ arguments after one. In the analysis AST, condition arguments keep their
193
+ predicate shape, a function call argument evaluated as a condition has
194
+ `condition: true`, and the AST version is 5.
195
+
196
+ Equality and ordering comparisons use each operand's declared type. Field
197
+ values are converted to that type, so a numeric `request.cf` value that
198
+ arrives as decimal text still compares as a number. Strings are ordered by code
199
+ point, which matches Cloudflare's byte order, with bytes that are not UTF-8
200
+ ordered as bytes, and IP addresses are compared as addresses rather than as
201
+ text. A field value that does not represent its declared type, such as other
202
+ text for a Number field or a number for a String field, is unknown, with a
203
+ warning.
204
+
205
+ ### Literals and Inline Lists
206
+
207
+ As in Cloudflare, inline list elements keep the type they are written as:
208
+ quoted elements are Strings that match exactly, so `{"10.0.0.0/8"}` is not a
209
+ CIDR, and unquoted elements are Integers, IP addresses, CIDRs, or ranges.
210
+ Inline lists only work with `in`.
211
+
212
+ There are no Boolean literals: `true` is accepted only as the entire
213
+ expression, which matches every request, and a non-Boolean field such as
214
+ `http.host` cannot be used as a condition on its own. Cloudflare's unquoted hex
215
+ byte literals, such as `65:78:61`, are not supported; write those values as
216
+ quoted strings.
217
+
218
+ ### Maps
219
+
220
+ The request header, cookie, and query argument maps are values too: functions
221
+ such as `coalesce()` and `has_key()` accept them, and `["key"]` and `[*]` work
222
+ on a function's map result as on the field itself, so
223
+ `coalesce(http.request.uri.args, http.request.cookies)["x"][0]` reads the query
224
+ argument. A map is never nil, so `coalesce()` returns its first map argument.
225
+ As in Cloudflare, `[*]` iterates a map's keys in byte order, so
226
+ `http.request.uri.args[*]` reads `?b=1&a=2` as `a`, then `b`.
227
+
228
+ ### Request Headers
229
+
230
+ Workers lowercases and sorts request header names, joins repeated headers into
231
+ one value, and adds headers of its own, such as `cf-ray`. The evaluator rebuilds
232
+ Cloudflare's header list from the undocumented `request.cf.requestHeaderNames`,
233
+ which names the headers the client sent, in order and spelling, and reads their
234
+ values from the Worker's headers. Live requests showed how Cloudflare lists
235
+ them, recorded in
236
+ [`test/fixtures/request-header-probes.json`](https://github.com/Func86/libreflare-worker-runtime/blob/master/test/fixtures/request-header-probes.json)
237
+ by `npm run probe:request-headers`, whose script describes the zone it needs:
238
+
239
+ - `http.request.headers.names` keeps each name's first spelling and groups
240
+ repeated names at their first position, in the order Cloudflare uses for the
241
+ request's HTTP version. Cloudflare leaves out some headers, such as
242
+ `Keep-Alive` and `CF-Ray`, and adds its own `X-Forwarded-Proto`.
243
+ - Header map keys are lowercase and compared exactly, so
244
+ `has_key(http.request.headers, "X-A")` is false.
245
+ - A repeated header's joined value is split into one value per header, unless
246
+ a value contains `, `, or `; ` for an HTTP/1 `Cookie`, which Cloudflare
247
+ joins with `; `.
248
+ - Values the Worker does not have are unknown: `Connection`,
249
+ `CF-Connecting-IP` and `CF-Visitor`, which Cloudflare replaces, headers
250
+ Workers does not receive, such as `CDN-Loop`, and `Accept-Encoding` without
251
+ `request.cf.clientAcceptEncoding`. Their names stay known, and so do the
252
+ other values: `any()` and `all()` over `http.request.headers.values` or `[*]`
253
+ on the header map, and `has_value()`, can still match or fail on a known
254
+ value, and `len()` still counts them, but whatever reads every value, such
255
+ as `join()`, is unknown.
256
+ - For a body sent without `Content-Length`, Cloudflare lists `Content-Length`
257
+ if the whole body arrived before its rules ran, and `Transfer-Encoding:
258
+ chunked` if not. The Worker sees a `Content-Length` either way, so that
259
+ header is unknown, name and value, though `len()` still counts it. Over
260
+ HTTP/3, Cloudflare listed `transfer-encoding` for every body size probed,
261
+ so it is known there.
262
+ - Other `Accept-Encoding` values come from `request.cf.clientAcceptEncoding`,
263
+ which keeps only the encodings Cloudflare supports, without weights.
264
+ - `request.cf.requestHeaderNames` lists at most 50 names. For a request with
265
+ that many, the headers it lists stay known, so `any()` can find one, but the
266
+ headers it does not list are unknown, and so are positions in the names and
267
+ values. A listed header can repeat after them too, so its value is unknown
268
+ when it contains `, `, or `; ` for an HTTP/1 `Cookie`, and so is
269
+ `Accept-Encoding`.
270
+ - `raw.http.request.headers` and its `names` and `values` list the same
271
+ headers as the other header fields, with two spellings of their own. Over
272
+ HTTP/3, raw names spell `X-Forwarded-Proto` in title case. A client header
273
+ that a Managed Transform replaced, such as `CF-IPCity` under Add visitor
274
+ location headers, has a lowercase raw name, which shows over HTTP/1, where
275
+ names keep the client's case. Worker context cannot tell what a Managed
276
+ Transform replaced, so raw names keep the client's spelling there.
277
+ - Cloudflare's header fields, raw or not, read the client's headers and values
278
+ from before request header transform rules and Managed Transforms, even in
279
+ the response phase, and `request.cf.requestHeaderNames` lists them too.
280
+ Workers sees the headers after them, so a value a transform replaced reads
281
+ the new value, with no warning, and one it removed is unknown. The
282
+ single-header fields, such as `http.user_agent`, read the Worker's values
283
+ too. Headers a transform adds are not listed, as in Cloudflare. Probes
284
+ covered a request header transform rule and the Managed Transforms Add
285
+ visitor location headers, Add TLS client auth headers and Remove visitor IP
286
+ headers.
287
+
288
+ Without `request.cf.requestHeaderNames`, as in local development, the Worker's
289
+ headers stand in, a repeated header holds one joined value, and the raw header
290
+ fields are unknown.
291
+
292
+ On a request from a Worker, which Cloudflare marks with `CF-Worker`, the header
293
+ fields are unknown when `request.cf.requestHeaderNames` is present. On the
294
+ subrequests probed, it named the headers of the request that Worker received,
295
+ while Cloudflare's header fields listed the subrequest's own.
296
+
297
+ ### Request Metadata
298
+
299
+ Most other fields read `request.cf`, and `ip.src` and `cf.ray_id` read headers
300
+ Cloudflare adds. Live requests compared them with Cloudflare's values over
301
+ HTTP/1.1, HTTP/2 and HTTP/3, and the evaluator follows what they showed:
302
+
303
+ - `cf.ray_id` adds the data center to the Worker's `CF-Ray`, as in
304
+ `8f1c2a3b4d5e6f70-LAX`.
305
+ - `cf.edge.client_tcp` is false over HTTP/3 and true over the other HTTP
306
+ versions, which run over TCP. Cloudflare's `cf.timings.client_tcp_rtt_msec`
307
+ was 1 ms more than `request.cf.clientTcpRtt` in every TCP request probed, and
308
+ the evaluator adds it. None had a TCP RTT of 0, which may mean under 1 ms or
309
+ not measured, so that is unknown. Over HTTP/3, both read 0.
310
+ - `ip.src.is_in_european_union` reads `request.cf.isEUCountry`, which Workers
311
+ gives as a Boolean rather than the `"1"` it documents, and is unknown without
312
+ it.
313
+ - `ip.src` reads `CF-Connecting-IPv6` when `CF-Connecting-IP` holds a Class E
314
+ address, from `240.0.0.0/4`. Pseudo IPv4, set to overwrite headers, puts one
315
+ there and keeps the client's IPv6 address in `CF-Connecting-IPv6`, which
316
+ Cloudflare's `ip.src` reads. A Class E address without that header is
317
+ unknown. Cloudflare removes a copy of the header sent by a client or relayed
318
+ by a Worker's subrequest, and with overwrite on, replaces a relayed one with
319
+ the real address.
320
+ - `cf.worker.upstream_zone` reads `CF-Worker`, which Cloudflare sets on a
321
+ Worker's subrequests, removing a client's copy, and is empty without it. Live
322
+ requests compared subrequests from another zone, and same-zone ones under the
323
+ `global_fetch_strictly_public` compatibility flag and to a Custom Domain;
324
+ without the flag, a same-zone subrequest reaches a Worker only on a Custom
325
+ Domain, and otherwise goes to the origin. On all of them, Cloudflare reads
326
+ `cf.tls_version` as empty, `cf.edge.l4.delivery_rate` and
327
+ `cf.timings.client_tcp_rtt_msec` as 0, and `cf.edge.client_tcp` as false, and
328
+ so does the evaluator. The other fields read `request.cf`, since they matched
329
+ it. A subrequest comes from the fixed address `2a06:98c0:3600::103`, unless
330
+ it stays on the same zone without the flag and the calling Worker sends
331
+ `X-Real-IP`, which Cloudflare then uses. `ip.src` reads the address from
332
+ `CF-Connecting-IP`, or `CF-Connecting-IPv6` under Pseudo IPv4, as Cloudflare
333
+ does. The location followed the fixed address, except on a same-zone
334
+ subrequest without the flag, where Cloudflare and `request.cf` both kept the
335
+ location of the request the calling Worker received, whatever `ip.src` held.
336
+ - `cf.edge.server_port` is unknown: the Worker's URL takes its port from the
337
+ `Host` header, and Cloudflare's field the port the client connected to.
338
+
339
+ ### Unknown Values and List Inference
340
+
341
+ Values the evaluator cannot resolve are unknown rather than nil. These include
342
+ `raw.*` URI fields in Worker context, request metadata missing from the
343
+ request, such as `request.cf` properties or the `cf-connecting-ip` header behind
344
+ `ip.src`, which the Remove visitor IP headers Managed Transform removes, and
345
+ results of functions it cannot reproduce, such as `sha256()` and
346
+ `is_jwt_valid()`. An unknown value makes the functions and comparisons
347
+ that use it unknown. It also makes `not`, `and`, `or` and `xor` unknown, unless
348
+ another operand settles the result. An unknown result does not match, and the
349
+ evaluation warnings name the values involved.
350
+
351
+ Unresolved Cloudflare list references are the exception: they count as
352
+ inferred matches whenever assuming the list results alone can make the
353
+ expression match. Set `inferListMatches: false` to report such expressions as
354
+ not matched instead.
355
+
43
356
  ## Development
44
357
 
45
358
  ```powershell
@@ -55,11 +368,18 @@ npm pack --dry-run
55
368
 
56
369
  The package emits publishable files to `dist/`. Publishing is configured for restricted scoped package access.
57
370
 
371
+ Rule parser/evaluator refactor notes are tracked in
372
+ [`docs/rule-evaluator-refactor.md`](docs/rule-evaluator-refactor.md).
373
+
374
+ ### Diagnosing Rule Misses
375
+
58
376
  To diagnose why an expression does not match a captured request log:
59
377
 
60
378
  ```powershell
61
379
  npm run explain:rule -- --sample <log-json-path> --expr 'http.host eq "example.com"'
62
380
  ```
63
381
 
64
- Rule parser/evaluator refactor notes are tracked in
65
- [`docs/rule-evaluator-refactor.md`](docs/rule-evaluator-refactor.md).
382
+ The tool reports with `explainExpressionMatch`. In its results, `actual` and
383
+ `expected` hold only observed values, so `null` is a Cloudflare missing value
384
+ and `[]` an empty collection. An operand the evaluator cannot resolve is
385
+ omitted and named in `unavailable`.
@@ -1,4 +1,5 @@
1
1
  import { type ComparisonNode, type FuncNode } from './ast.js';
2
- import type { ResolverCtx } from './fields.js';
3
- export declare function warnIfAcceptEncodingZstdSensitive(node: ComparisonNode | FuncNode, ctx: ResolverCtx, currentResult: boolean | null, evaluateWithCtx: (testCtx: ResolverCtx) => boolean | null): void;
2
+ import { type ResolverCtx } from './fields.js';
3
+ import { type Outcome } from './outcome.js';
4
+ export declare function warnIfAcceptEncodingZstdSensitive(node: ComparisonNode | FuncNode, ctx: ResolverCtx, currentResult: boolean, evaluateWithCtx: (testCtx: ResolverCtx) => Outcome): void;
4
5
  //# sourceMappingURL=accept-encoding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accept-encoding.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/accept-encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,cAAc,EAAkB,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAgD/C,wBAAgB,iCAAiC,CAChD,IAAI,EAAE,cAAc,GAAG,QAAQ,EAC/B,GAAG,EAAE,WAAW,EAChB,aAAa,EAAE,OAAO,GAAG,IAAI,EAC7B,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,GAAG,IAAI,GACvD,IAAI,CA8BN"}
1
+ {"version":3,"file":"accept-encoding.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/accept-encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,cAAc,EAAkB,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC7F,OAAO,EAAiE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9G,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAgGvD,wBAAgB,iCAAiC,CAChD,IAAI,EAAE,cAAc,GAAG,QAAQ,EAC/B,GAAG,EAAE,WAAW,EAChB,aAAa,EAAE,OAAO,EACtB,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,GAChD,IAAI,CAoBN"}
@@ -1,20 +1,66 @@
1
- import { pushWarning } from './ast.js';
2
- import { extractQuantifierPredicate } from './quantifier.js';
1
+ import { unhandledNode } from './ast.js';
2
+ import { REQUEST_HEADER_ARRAYS, REQUEST_HEADER_MAPS, requestHeaderList } from './fields.js';
3
+ import { isUnknown } from './outcome.js';
4
+ import { isUnknownHeaderValues, requestHeaderKeyValues } from './request-headers.js';
5
+ /**
6
+ * Reads the Accept-Encoding header directly, reads the whole headers map, such
7
+ * as with [*] or coalesce(), or reads every header value. An invalid access
8
+ * may stand for any of them. Each Accept-Encoding value reads
9
+ * request.cf.clientAcceptEncoding. A field that reads it without using it,
10
+ * such as http.request.headers.values[0], costs only the second evaluation;
11
+ * recording reads would count it too, as the header arrays are built whole.
12
+ */
3
13
  function isAcceptEncodingFieldNode(node) {
4
- const mapKey = node.accessPath.find(access => access.kind === 'MapKeyAccess');
5
- return node.name === 'http.request.headers' && mapKey?.key.toLowerCase() === 'accept-encoding';
6
- }
7
- function funcUsesAcceptEncoding(node) {
8
- const arg0 = node.args[0];
9
- if (!arg0 || typeof arg0 !== 'object' || !('kind' in arg0))
14
+ if (REQUEST_HEADER_ARRAYS.get(node.name) === 'values')
15
+ return true;
16
+ if (!REQUEST_HEADER_MAPS.has(node.name))
10
17
  return false;
11
- if (arg0.kind === 'Field') {
12
- return isAcceptEncodingFieldNode(arg0);
18
+ const access = node.accessPath[0];
19
+ if (!access)
20
+ return true;
21
+ switch (access.kind) {
22
+ case 'MapKeyAccess':
23
+ return access.key === 'accept-encoding';
24
+ case 'ArrayIndexAccess':
25
+ case 'ArrayWildcardAccess':
26
+ case 'Invalid':
27
+ return true;
28
+ default:
29
+ return unhandledNode(access);
13
30
  }
14
- if (arg0.kind === 'Func') {
15
- return funcUsesAcceptEncoding(arg0);
31
+ }
32
+ /**
33
+ * Whether an expression reads the Accept-Encoding header anywhere, including
34
+ * in later function arguments, such as coalesce() fallbacks, and in nested
35
+ * any()/all() predicates.
36
+ */
37
+ function usesAcceptEncoding(node) {
38
+ switch (node.kind) {
39
+ case 'Field':
40
+ return isAcceptEncodingFieldNode(node);
41
+ case 'Func':
42
+ // Which keys a map has does not depend on their values.
43
+ return node.args.slice(node.name === 'has_key' ? 1 : 0).some(usesAcceptEncoding);
44
+ case 'Comparison':
45
+ return usesAcceptEncoding(node.left) || (node.right !== undefined && usesAcceptEncoding(node.right));
46
+ case 'Not':
47
+ return usesAcceptEncoding(node.operand);
48
+ case 'And':
49
+ case 'Or':
50
+ case 'Xor':
51
+ return node.operands.some(usesAcceptEncoding);
52
+ case 'BoolField':
53
+ case 'StringLiteral':
54
+ case 'NumberLiteral':
55
+ case 'IpLiteral':
56
+ case 'BoolLiteral':
57
+ case 'SetLiteral':
58
+ case 'ListRef':
59
+ case 'Invalid':
60
+ return false;
61
+ default:
62
+ return unhandledNode(node);
16
63
  }
17
- return false;
18
64
  }
19
65
  function parseAcceptEncodingTokens(value) {
20
66
  if (!value)
@@ -34,40 +80,39 @@ function toggleZstdInAcceptEncoding(value) {
34
80
  }
35
81
  return [...tokens, 'zstd'].join(', ');
36
82
  }
83
+ /** Header values read the override when read, so the copy keeps the header list. */
37
84
  function withAcceptEncodingOverride(ctx, acceptEncoding) {
38
85
  return {
39
86
  ...ctx,
40
87
  cf: { ...ctx.cf, clientAcceptEncoding: acceptEncoding },
41
- warnings: [],
88
+ warnings: new Set(),
42
89
  };
43
90
  }
91
+ /** The Accept-Encoding value rules read, which overriding changes, or null when it is unknown or absent. */
92
+ function acceptEncodingValue(ctx) {
93
+ const values = requestHeaderKeyValues(requestHeaderList(ctx), 'accept-encoding', ctx.cf);
94
+ return values === null || isUnknownHeaderValues(values) ? null : values[0] ?? null;
95
+ }
44
96
  export function warnIfAcceptEncodingZstdSensitive(node, ctx, currentResult, evaluateWithCtx) {
45
97
  const responseContentEncoding = ctx.response?.headers.get('content-encoding') ?? '';
46
98
  if (parseAcceptEncodingTokens(responseContentEncoding).some(token => token === 'zstd')) {
47
99
  return;
48
100
  }
49
- const usesAcceptEncoding = node.kind === 'Comparison'
50
- ? (node.left.kind === 'Func' ? funcUsesAcceptEncoding(node.left) : isAcceptEncodingFieldNode(node.left))
51
- : (() => {
52
- if (node.name !== 'any' && node.name !== 'all')
53
- return false;
54
- const fieldArg = extractQuantifierPredicate(node)?.source;
55
- if (!fieldArg)
56
- return false;
57
- if (fieldArg.kind === 'Func')
58
- return funcUsesAcceptEncoding(fieldArg);
59
- if (fieldArg.kind === 'Field') {
60
- return isAcceptEncodingFieldNode(fieldArg);
61
- }
62
- return false;
63
- })();
64
- if (!usesAcceptEncoding)
101
+ if (!usesAcceptEncoding(node))
65
102
  return;
66
- const toggledAcceptEncoding = toggleZstdInAcceptEncoding(ctx.cf.clientAcceptEncoding ?? ctx.request.headers.get('accept-encoding') ?? '');
67
- const toggledCtx = withAcceptEncodingOverride(ctx, toggledAcceptEncoding);
103
+ const acceptEncoding = acceptEncodingValue(ctx);
104
+ if (acceptEncoding === null)
105
+ return;
106
+ const toggledCtx = withAcceptEncodingOverride(ctx, toggleZstdInAcceptEncoding(acceptEncoding));
68
107
  const toggledResult = evaluateWithCtx(toggledCtx);
69
- if (toggledResult !== currentResult) {
70
- pushWarning(ctx.warnings, `Accept-Encoding checks may be unreliable in Workers: request.cf.clientAcceptEncoding currently drops 'zstd', and '${node.raw}' would evaluate differently if 'zstd' were toggled`);
71
- }
108
+ if (toggledResult === currentResult)
109
+ return;
110
+ const unknown = isUnknown(toggledResult);
111
+ ctx.warnings.add(`Accept-Encoding checks may be unreliable in Workers: request.cf.clientAcceptEncoding currently drops 'zstd', and '${node.raw}' ${unknown ? 'might' : 'would'} evaluate differently if 'zstd' were toggled`);
112
+ // The toggled run's warnings tell what left its result unknown.
113
+ if (!unknown)
114
+ return;
115
+ for (const warning of toggledCtx.warnings)
116
+ ctx.warnings.add(warning);
72
117
  }
73
118
  //# sourceMappingURL=accept-encoding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accept-encoding.js","sourceRoot":"","sources":["../../src/rule-evaluator/accept-encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsD,MAAM,UAAU,CAAC;AAE3F,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,SAAS,yBAAyB,CAAC,IAAe;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KA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