@libreflare/worker-runtime 0.9.5 → 0.10.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 (62) hide show
  1. package/README.md +280 -9
  2. package/dist/log-handler.d.ts.map +1 -1
  3. package/dist/log-handler.js +3 -4
  4. package/dist/log-handler.js.map +1 -1
  5. package/dist/rule-evaluator/accept-encoding.d.ts.map +1 -1
  6. package/dist/rule-evaluator/accept-encoding.js +3 -0
  7. package/dist/rule-evaluator/accept-encoding.js.map +1 -1
  8. package/dist/rule-evaluator/access-values.d.ts +5 -3
  9. package/dist/rule-evaluator/access-values.d.ts.map +1 -1
  10. package/dist/rule-evaluator/access-values.js +9 -3
  11. package/dist/rule-evaluator/access-values.js.map +1 -1
  12. package/dist/rule-evaluator/country-codes.generated.js +1 -1
  13. package/dist/rule-evaluator/edge-evaluation.d.ts +128 -0
  14. package/dist/rule-evaluator/edge-evaluation.d.ts.map +1 -0
  15. package/dist/rule-evaluator/edge-evaluation.js +316 -0
  16. package/dist/rule-evaluator/edge-evaluation.js.map +1 -0
  17. package/dist/rule-evaluator/edge-record.d.ts +173 -0
  18. package/dist/rule-evaluator/edge-record.d.ts.map +1 -0
  19. package/dist/rule-evaluator/edge-record.js +771 -0
  20. package/dist/rule-evaluator/edge-record.js.map +1 -0
  21. package/dist/rule-evaluator/evaluator.d.ts +21 -0
  22. package/dist/rule-evaluator/evaluator.d.ts.map +1 -1
  23. package/dist/rule-evaluator/evaluator.js +60 -3
  24. package/dist/rule-evaluator/evaluator.js.map +1 -1
  25. package/dist/rule-evaluator/explain.d.ts +6 -0
  26. package/dist/rule-evaluator/explain.d.ts.map +1 -1
  27. package/dist/rule-evaluator/explain.js +54 -20
  28. package/dist/rule-evaluator/explain.js.map +1 -1
  29. package/dist/rule-evaluator/fields.d.ts +50 -6
  30. package/dist/rule-evaluator/fields.d.ts.map +1 -1
  31. package/dist/rule-evaluator/fields.js +72 -50
  32. package/dist/rule-evaluator/fields.js.map +1 -1
  33. package/dist/rule-evaluator/functions.d.ts +18 -0
  34. package/dist/rule-evaluator/functions.d.ts.map +1 -1
  35. package/dist/rule-evaluator/functions.js +58 -4
  36. package/dist/rule-evaluator/functions.js.map +1 -1
  37. package/dist/rule-evaluator/log-sample.d.ts +23 -0
  38. package/dist/rule-evaluator/log-sample.d.ts.map +1 -1
  39. package/dist/rule-evaluator/log-sample.js +5 -3
  40. package/dist/rule-evaluator/log-sample.js.map +1 -1
  41. package/dist/rule-evaluator/match-chain.d.ts +8 -0
  42. package/dist/rule-evaluator/match-chain.d.ts.map +1 -1
  43. package/dist/rule-evaluator/match-chain.js +16 -0
  44. package/dist/rule-evaluator/match-chain.js.map +1 -1
  45. package/dist/rule-evaluator/operators.d.ts +5 -0
  46. package/dist/rule-evaluator/operators.d.ts.map +1 -1
  47. package/dist/rule-evaluator/operators.js +52 -0
  48. package/dist/rule-evaluator/operators.js.map +1 -1
  49. package/dist/rule-evaluator/query-args.d.ts +2 -2
  50. package/dist/rule-evaluator/query-args.d.ts.map +1 -1
  51. package/dist/rule-evaluator/query-args.js +11 -4
  52. package/dist/rule-evaluator/query-args.js.map +1 -1
  53. package/dist/rule-evaluator/validation.d.ts.map +1 -1
  54. package/dist/rule-evaluator/validation.js +30 -19
  55. package/dist/rule-evaluator/validation.js.map +1 -1
  56. package/dist/rule-evaluator.d.ts +5 -0
  57. package/dist/rule-evaluator.d.ts.map +1 -1
  58. package/dist/rule-evaluator.js +3 -0
  59. package/dist/rule-evaluator.js.map +1 -1
  60. package/dist/tools/explain-rule-miss.js +259 -10
  61. package/dist/tools/explain-rule-miss.js.map +1 -1
  62. package/package.json +3 -3
@@ -0,0 +1,128 @@
1
+ import type { RuleExpressionCustomLists } from './custom-lists.js';
2
+ import { type EdgeLoggedFields, type EdgeRecord, type EdgeResolverOptions, type UrlNormalization } from './edge-record.js';
3
+ import type { SampleLogRecord } from './log-sample.js';
4
+ /**
5
+ * Evaluation on edge records. Cloudflare's match is given: the record lists
6
+ * the rule. Each condition the record cannot decide may have gone either
7
+ * way, and the result names the branch that matched when only one remains.
8
+ */
9
+ /** How certain an edge record's result is. */
10
+ export type EdgeEvaluationCertainty =
11
+ /** The record decided every condition, and the expression matched as Cloudflare's did. */
12
+ 'matched'
13
+ /** One branch remains possible, given Cloudflare's match, and it relies on conditions the record could not decide. */
14
+ | 'inferred'
15
+ /** More than one branch remains possible. */
16
+ | 'unknown'
17
+ /** The record's values rule out a match. */
18
+ | 'disagreed'
19
+ /** The expression could not be evaluated; the warnings say why. */
20
+ | 'unavailable';
21
+ /** A branch as managed request logs give it; see EvaluationResult. */
22
+ export interface EdgeEvaluationBranch {
23
+ matchChain: string[];
24
+ matchChainCompat: string[];
25
+ largeBlocks: Record<string, string>;
26
+ }
27
+ export interface EdgeEvaluationResult {
28
+ result: EdgeEvaluationCertainty;
29
+ /** The branch of a `matched` or `inferred` result. */
30
+ branch?: EdgeEvaluationBranch;
31
+ /** For an `unknown` result, the branches that remain possible, in expression order, at most four. */
32
+ candidates?: EdgeEvaluationBranch[];
33
+ /** For an `unknown` result, whether more branches remain possible than `candidates` lists. */
34
+ moreCandidates?: boolean;
35
+ warnings: string[];
36
+ }
37
+ export interface EdgeEvaluationOptions extends EdgeResolverOptions {
38
+ /** As in `evaluateExpression()`. */
39
+ largeNotBlockThreshold?: number;
40
+ }
41
+ /**
42
+ * Evaluates a rule expression on an edge record whose request Cloudflare
43
+ * matched with it. A condition the record cannot decide may have gone either
44
+ * way; one Cloudflare would not evaluate makes the result `unavailable`.
45
+ */
46
+ export declare function evaluateEdgeExpression(expr: string, record: EdgeRecord, options?: EdgeEvaluationOptions): EdgeEvaluationResult;
47
+ /** When a timeline entry took effect, as RFC 3339 text. */
48
+ interface EdgeTimelineEntry {
49
+ since: string;
50
+ }
51
+ /** A version of a Custom Rule. */
52
+ export interface EdgeRuleVersion extends EdgeTimelineEntry {
53
+ expression: string;
54
+ /** Cloudflare's rule version, which results name. */
55
+ version?: string;
56
+ }
57
+ /** An application of a managed route's expression. */
58
+ export interface EdgeRouteApplication extends EdgeTimelineEntry {
59
+ /** The route expression as stored, which the Managed Worker evaluates, not Cloudflare's minified text. */
60
+ expression: string;
61
+ /** The prefix the route's rewrite puts before the visitor's path. */
62
+ prefix: string;
63
+ /** The ID of the URL rewrite rule that applies the route, which a record's MatchedRules lists when it matched. */
64
+ rewriteRuleId: string;
65
+ /** The application, which results name. */
66
+ version?: string;
67
+ }
68
+ /** A Custom Rule linked to a managed route. */
69
+ export interface EdgeRouteLink {
70
+ route: string;
71
+ rule: string;
72
+ }
73
+ /** A state of the zone's logged fields. */
74
+ export interface EdgeLoggedFieldSet extends EdgeLoggedFields, EdgeTimelineEntry {
75
+ }
76
+ /**
77
+ * What evaluateEdgeRecordRules() chooses from by a record's time. Links have
78
+ * no times: they apply as they are.
79
+ */
80
+ export interface EdgeRuleTimeline {
81
+ /** Each Custom Rule's versions, by rule ID. */
82
+ rules: Readonly<Record<string, readonly EdgeRuleVersion[]>>;
83
+ /** Each managed route's applications, by route. */
84
+ routes?: Readonly<Record<string, readonly EdgeRouteApplication[]>>;
85
+ links?: readonly EdgeRouteLink[];
86
+ loggedFields?: readonly EdgeLoggedFieldSet[];
87
+ }
88
+ export interface EdgeRecordRulesOptions {
89
+ urlNormalization?: UrlNormalization;
90
+ customLists?: RuleExpressionCustomLists;
91
+ }
92
+ export interface EdgeRuleResult extends EdgeEvaluationResult {
93
+ ruleId: string;
94
+ version?: string;
95
+ /**
96
+ * The linked route the rule could only have matched through, when
97
+ * MatchedRules does not show that route's rewrite as the one applied.
98
+ */
99
+ unlistedRewrite?: string;
100
+ }
101
+ export interface EdgeRouteResult extends EdgeEvaluationResult {
102
+ route: string;
103
+ version?: string;
104
+ }
105
+ export interface EdgeRecordRulesEvaluation {
106
+ rayId: string;
107
+ /** One result per Custom Rule the record lists. */
108
+ rules: EdgeRuleResult[];
109
+ /** The route expression's result, when MatchedRules shows the route's rewrite applied. */
110
+ route?: EdgeRouteResult;
111
+ /** What the timeline lacked for the record's time. */
112
+ warnings: string[];
113
+ }
114
+ /**
115
+ * Evaluates each Custom Rule a mapped edge record lists, with the rule
116
+ * versions, route applications and logged fields in effect at the record's
117
+ * time. Custom Rules read the path after URL rewrites: when MatchedRules shows
118
+ * a route's rewrite applied, every rule is evaluated with the route's prefix
119
+ * before the visitor's path, and the route expression with the visitor's
120
+ * request. A linked rule that matches only through its route's rewrite, which
121
+ * MatchedRules does not show, keeps its result and gets `unlistedRewrite`.
122
+ *
123
+ * @throws {EdgeRecordError} When the record cannot be read; see readEdgeRecord().
124
+ * @throws {Error} When a timeline entry's `since` is not an RFC 3339 time.
125
+ */
126
+ export declare function evaluateEdgeRecordRules(sample: SampleLogRecord, timeline: EdgeRuleTimeline, options?: EdgeRecordRulesOptions): EdgeRecordRulesEvaluation;
127
+ export {};
128
+ //# sourceMappingURL=edge-evaluation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-evaluation.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/edge-evaluation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAKN,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAKvD;;;;GAIG;AAEH,8CAA8C;AAC9C,MAAM,MAAM,uBAAuB;AAClC,0FAA0F;AACxF,SAAS;AACX,sHAAsH;GACpH,UAAU;AACZ,6CAA6C;GAC3C,SAAS;AACX,4CAA4C;GAC1C,WAAW;AACb,mEAAmE;GACjE,aAAa,CAAC;AAEjB,sEAAsE;AACtE,MAAM,WAAW,oBAAoB;IACpC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,EA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IAChC,+CAA+C;IAC/C,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC,CAAC,CAAC;IAC5D,mDAAmD;IACnD,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,oBAAoB,EAAE,CAAC,CAAC,CAAC;IACnE,KAAK,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IACjC,YAAY,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,sBAAsB;IACtC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,WAAW,CAAC,EAAE,yBAAyB,CAAC;CACxC;AAED,MAAM,WAAW,cAAe,SAAQ,oBAAoB;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAgB,SAAQ,oBAAoB;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,0FAA0F;IAC1F,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACnB;AAoCD;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,sBAA2B,GAClC,yBAAyB,CA8D3B"}
@@ -0,0 +1,316 @@
1
+ import { unhandledNode } from './ast.js';
2
+ import { edgeRecordTime, edgeResolverCtx, parseEdgeTime, readEdgeRecord, } from './edge-record.js';
3
+ import { evaluateLeaf, isValidExpression } from './evaluator.js';
4
+ import { buildCompatMatchChain, formatMatchChainEntry } from './match-chain.js';
5
+ import { parseExpression } from './parse-cache.js';
6
+ /** How many branches an `unknown` result lists. */
7
+ const CANDIDATE_LIMIT = 4;
8
+ const EMPTY_CHAIN = { entries: [], key: '', assumed: false };
9
+ function chainOf(chainEntry, assumed) {
10
+ const member = chainEntry.matchedSetMember;
11
+ const text = formatMatchChainEntry(chainEntry);
12
+ return { entries: [chainEntry], key: member ? `${text}\u0001${member.type === 'integer' ? member.raw : member.value}` : text, assumed };
13
+ }
14
+ function joinChains(left, right) {
15
+ return {
16
+ entries: [...left.entries, ...right.entries],
17
+ key: left.key && right.key ? `${left.key}\u0000${right.key}` : left.key || right.key,
18
+ assumed: left.assumed || right.assumed,
19
+ };
20
+ }
21
+ function withAssumption(chain) {
22
+ return chain.assumed ? chain : { ...chain, assumed: true };
23
+ }
24
+ /** Distinct chains in the order added, at most CANDIDATE_LIMIT, and whether there were more. */
25
+ class Chains {
26
+ list = [];
27
+ more = false;
28
+ add(chain) {
29
+ const index = this.list.findIndex(other => other.key === chain.key);
30
+ if (index !== -1) {
31
+ if (chain.assumed)
32
+ this.list[index] = withAssumption(this.list[index]);
33
+ }
34
+ else if (this.list.length < CANDIDATE_LIMIT) {
35
+ this.list.push(chain);
36
+ }
37
+ else {
38
+ this.more = true;
39
+ }
40
+ }
41
+ }
42
+ function entry(node, inferred, matchedSetMember) {
43
+ return { node, inferred, ...(matchedSetMember ? { matchedSetMember } : {}) };
44
+ }
45
+ function walkLeaf(node, ctx) {
46
+ const { outcome, matchedSetMembers } = evaluateLeaf(node, ctx);
47
+ if (outcome === false)
48
+ return { chains: [], more: false, canFalse: true, blocked: null };
49
+ if (outcome !== true && outcome.cause.kind === 'incomparable')
50
+ return { chains: [], more: false, canFalse: false, blocked: outcome };
51
+ // A condition can match another inline list member in each reading, which the chain names. The member is not a
52
+ // condition's result, so it is not assumed: several make the result unknown. A condition the record cannot decide
53
+ // is true by an assumption.
54
+ const assumed = outcome !== true;
55
+ const chains = new Chains();
56
+ for (const member of matchedSetMembers)
57
+ chains.add(chainOf(entry(node, assumed, member), assumed));
58
+ return { chains: chains.list, more: chains.more, canFalse: assumed, blocked: null };
59
+ }
60
+ /**
61
+ * Walks an expression as Cloudflare evaluates it: `and` and `or` from left to
62
+ * right, stopping once their result is certain, and `xor` over every operand.
63
+ */
64
+ function walk(node, ctx) {
65
+ switch (node.kind) {
66
+ case 'BoolField':
67
+ case 'Comparison':
68
+ case 'Func':
69
+ return walkLeaf(node, ctx);
70
+ case 'Not': {
71
+ const inner = walk(node.operand, ctx);
72
+ // The chain names the negation, as on managed request logs.
73
+ const assumed = inner.chains.length > 0 || inner.blocked !== null;
74
+ return {
75
+ chains: inner.canFalse ? [chainOf(entry(node, assumed), assumed)] : [],
76
+ more: false,
77
+ canFalse: inner.chains.length > 0,
78
+ blocked: inner.blocked,
79
+ };
80
+ }
81
+ case 'And': {
82
+ let chains = [EMPTY_CHAIN];
83
+ let more = false;
84
+ let canFalse = false;
85
+ let blocked = null;
86
+ for (const operand of node.operands) {
87
+ const result = walk(operand, ctx);
88
+ canFalse ||= result.canFalse;
89
+ blocked ??= result.blocked;
90
+ if (result.chains.length === 0)
91
+ return { chains: [], more: false, canFalse, blocked };
92
+ const joined = new Chains();
93
+ for (const left of chains) {
94
+ for (const right of result.chains)
95
+ joined.add(joinChains(left, right));
96
+ }
97
+ chains = joined.list;
98
+ more ||= result.more || joined.more;
99
+ }
100
+ return { chains, more, canFalse, blocked };
101
+ }
102
+ case 'Or': {
103
+ const chains = new Chains();
104
+ let more = false;
105
+ let blocked = null;
106
+ // Whether the operands before this one are false only by an assumption.
107
+ let assumedFalse = false;
108
+ for (const operand of node.operands) {
109
+ const result = walk(operand, ctx);
110
+ blocked ??= result.blocked;
111
+ for (const chain of result.chains)
112
+ chains.add(assumedFalse ? withAssumption(chain) : chain);
113
+ more ||= result.more;
114
+ // No later operand is reached once this one cannot be false.
115
+ if (!result.canFalse)
116
+ return { chains: chains.list, more: more || chains.more, canFalse: false, blocked };
117
+ assumedFalse ||= result.chains.length > 0 || result.blocked !== null;
118
+ }
119
+ return { chains: chains.list, more: more || chains.more, canFalse: true, blocked };
120
+ }
121
+ case 'Xor': {
122
+ const results = node.operands.map(operand => walk(operand, ctx));
123
+ const after = suffixParities(results);
124
+ const chains = new Chains();
125
+ xorChains(results, after, 0, false, EMPTY_CHAIN, chains);
126
+ // An operand's omitted chains are possible only where it can be true with an odd count in all.
127
+ let more = chains.more;
128
+ let before = NONE_TRUE;
129
+ for (const [index, result] of results.entries()) {
130
+ const rest = after[index + 1];
131
+ more ||= result.more && ((before.even && rest.even) || (before.odd && rest.odd));
132
+ before = withOperand(result, before);
133
+ }
134
+ return { chains: chains.list, more, canFalse: after[0].even, blocked: results.find(result => result.blocked)?.blocked ?? null };
135
+ }
136
+ // Only an expression without syntax errors is evaluated.
137
+ case 'Invalid':
138
+ return { chains: [], more: false, canFalse: true, blocked: null };
139
+ default:
140
+ return unhandledNode(node);
141
+ }
142
+ }
143
+ const NONE_TRUE = { even: true, odd: false };
144
+ function withOperand(result, parities) {
145
+ const canTrue = result.chains.length > 0;
146
+ return {
147
+ even: (parities.even && result.canFalse) || (parities.odd && canTrue),
148
+ odd: (parities.odd && result.canFalse) || (parities.even && canTrue),
149
+ };
150
+ }
151
+ /** The parities the operands from each index on can reach, ending with the empty rest past the last. */
152
+ function suffixParities(results) {
153
+ const parities = [NONE_TRUE];
154
+ for (let index = results.length - 1; index >= 0; index--)
155
+ parities.unshift(withOperand(results[index], parities[0]));
156
+ return parities;
157
+ }
158
+ /**
159
+ * Adds, in expression order, the chains of each way an odd number of
160
+ * operands can be true, from operand `index` on. It skips the ways whose
161
+ * rest cannot make the count odd, so that each step leads to a chain, and
162
+ * stops once there are more than CANDIDATE_LIMIT.
163
+ */
164
+ function xorChains(results, after, index, odd, chain, into) {
165
+ if (!(odd ? after[index].even : after[index].odd))
166
+ return;
167
+ const result = results[index];
168
+ if (!result) {
169
+ into.add(chain);
170
+ return;
171
+ }
172
+ for (const operand of result.chains) {
173
+ if (into.more)
174
+ return;
175
+ xorChains(results, after, index + 1, !odd, joinChains(chain, operand), into);
176
+ }
177
+ if (!result.canFalse || into.more)
178
+ return;
179
+ const assumed = result.chains.length > 0 || result.blocked !== null;
180
+ xorChains(results, after, index + 1, odd, assumed ? withAssumption(chain) : chain, into);
181
+ }
182
+ /**
183
+ * Evaluates a rule expression on an edge record whose request Cloudflare
184
+ * matched with it. A condition the record cannot decide may have gone either
185
+ * way; one Cloudflare would not evaluate makes the result `unavailable`.
186
+ */
187
+ export function evaluateEdgeExpression(expr, record, options = {}) {
188
+ const warnings = new Set();
189
+ if (!isValidExpression(expr, warnings))
190
+ return { result: 'unavailable', warnings: [...warnings] };
191
+ const possible = walk(parseExpression(expr), edgeResolverCtx(record, options, warnings));
192
+ if (possible.blocked || (possible.chains.length === 0 && !possible.canFalse))
193
+ return { result: 'unavailable', warnings: [...warnings] };
194
+ if (possible.chains.length === 0)
195
+ return { result: 'disagreed', warnings: [...warnings] };
196
+ const threshold = options.largeNotBlockThreshold ?? 3;
197
+ const branches = possible.chains.map((chain) => ({
198
+ matchChain: chain.entries.map(formatMatchChainEntry),
199
+ ...buildCompatMatchChain(expr, chain.entries, threshold),
200
+ }));
201
+ if (branches.length === 1 && !possible.more) {
202
+ return { result: possible.chains[0].assumed ? 'inferred' : 'matched', branch: branches[0], warnings: [...warnings] };
203
+ }
204
+ return { result: 'unknown', candidates: branches, moreCandidates: possible.more, warnings: [...warnings] };
205
+ }
206
+ /** The entry in effect at a time: the latest that took effect by then. */
207
+ function entryAt(entries, epochMs) {
208
+ if (epochMs === undefined)
209
+ return undefined;
210
+ let latest;
211
+ for (const entry of entries ?? []) {
212
+ const since = parseEdgeTime(entry.since)?.epochMs;
213
+ if (since === undefined)
214
+ throw new Error(`timeline entry has since ${JSON.stringify(entry.since)}, which is not an RFC 3339 time`);
215
+ if (since <= epochMs && (!latest || since >= latest.since))
216
+ latest = { entry, since };
217
+ }
218
+ return latest?.entry;
219
+ }
220
+ /**
221
+ * The route whose rewrite set the path the Custom Rules read: the last route
222
+ * rewrite MatchedRules lists, since it lists a ruleset's rules in rule order
223
+ * and the last matching rewrite wins. A rule listed after it in the same
224
+ * ruleset is a rewrite of the operator's own, which may have set the path
225
+ * again.
226
+ */
227
+ function appliedRewrite(record, routes) {
228
+ for (const { ruleIds } of record.matchedRules) {
229
+ const last = ruleIds.findLastIndex(id => routes.has(id));
230
+ if (last < 0)
231
+ continue;
232
+ const after = last < ruleIds.length - 1 ? ruleIds.at(-1) : undefined;
233
+ return { route: routes.get(ruleIds[last]), ...(after ? { after } : {}) };
234
+ }
235
+ return {};
236
+ }
237
+ /**
238
+ * Evaluates each Custom Rule a mapped edge record lists, with the rule
239
+ * versions, route applications and logged fields in effect at the record's
240
+ * time. Custom Rules read the path after URL rewrites: when MatchedRules shows
241
+ * a route's rewrite applied, every rule is evaluated with the route's prefix
242
+ * before the visitor's path, and the route expression with the visitor's
243
+ * request. A linked rule that matches only through its route's rewrite, which
244
+ * MatchedRules does not show, keeps its result and gets `unlistedRewrite`.
245
+ *
246
+ * @throws {EdgeRecordError} When the record cannot be read; see readEdgeRecord().
247
+ * @throws {Error} When a timeline entry's `since` is not an RFC 3339 time.
248
+ */
249
+ export function evaluateEdgeRecordRules(sample, timeline, options = {}) {
250
+ const warnings = new Set();
251
+ const at = edgeRecordTime(sample)?.epochMs;
252
+ if (at === undefined)
253
+ warnings.add('the record has no RFC 3339 _time, so no rule version, route application or logged-field set applies to it');
254
+ const loggedFields = entryAt(timeline.loggedFields, at);
255
+ if (at !== undefined && !loggedFields) {
256
+ warnings.add("no logged-field set was in effect at the record's time, so the record's own headers and cookies stand in for the logged ones");
257
+ }
258
+ const record = readEdgeRecord(sample, { loggedFields, urlNormalization: options.urlNormalization });
259
+ const evaluation = { customLists: options.customLists };
260
+ const routes = new Map();
261
+ for (const [name, applications] of Object.entries(timeline.routes ?? {})) {
262
+ const application = entryAt(applications, at);
263
+ if (application)
264
+ routes.set(application.rewriteRuleId, { name, application });
265
+ }
266
+ const applied = appliedRewrite(record, routes);
267
+ const path = applied.after
268
+ ? { pathRewrittenBy: applied.after }
269
+ : applied.route ? { routePrefix: applied.route.application.prefix } : {};
270
+ // Without sources that tell them apart, a listed rule the timeline has no versions of is taken as another product's.
271
+ const unversioned = record.ruleSourcesAligned ? [] : record.customRuleIds.filter(ruleId => !timeline.rules[ruleId]?.length);
272
+ if (unversioned.length > 0) {
273
+ warnings.add(`the record's rule sources do not line up with its rule IDs, so ${unversioned.join(', ')}, which the timeline has no versions of, ${unversioned.length === 1 ? 'was not taken as a Custom Rule' : 'were not taken as Custom Rules'}`);
274
+ }
275
+ const rules = [];
276
+ for (const ruleId of record.customRuleIds) {
277
+ if (unversioned.includes(ruleId))
278
+ continue;
279
+ const version = entryAt(timeline.rules[ruleId], at);
280
+ if (!version) {
281
+ rules.push({ ruleId, result: 'unavailable', warnings: [`no version of rule ${ruleId} was in effect at the record's time`] });
282
+ continue;
283
+ }
284
+ const result = {
285
+ ruleId,
286
+ ...(version.version !== undefined ? { version: version.version } : {}),
287
+ ...evaluateEdgeExpression(version.expression, record, { ...evaluation, ...path }),
288
+ };
289
+ // Only a disagreed rule may have matched through its route's rewrite instead.
290
+ const link = result.result === 'disagreed' ? timeline.links?.find(candidate => candidate.rule === ruleId) : undefined;
291
+ if (link && link.route !== applied.route?.name) {
292
+ const application = entryAt(timeline.routes?.[link.route], at);
293
+ if (!application) {
294
+ warnings.add(`route '${link.route}' had no application in effect at the record's time, so its rewrite was not looked for in MatchedRules`);
295
+ }
296
+ else if (matches(evaluateEdgeExpression(version.expression, record, { ...evaluation, routePrefix: application.prefix }))) {
297
+ result.unlistedRewrite = link.route;
298
+ result.warnings = [
299
+ ...result.warnings,
300
+ `rule ${ruleId} matches only with route '${link.route}''s prefix, but MatchedRules does not show the route's rewrite ${application.rewriteRuleId} as the one applied`,
301
+ ];
302
+ }
303
+ }
304
+ rules.push(result);
305
+ }
306
+ const route = applied.route && {
307
+ route: applied.route.name,
308
+ ...(applied.route.application.version !== undefined ? { version: applied.route.application.version } : {}),
309
+ ...evaluateEdgeExpression(applied.route.application.expression, record, evaluation),
310
+ };
311
+ return { rayId: record.rayId, rules, ...(route ? { route } : {}), warnings: [...warnings] };
312
+ }
313
+ function matches({ result }) {
314
+ return result === 'matched' || result === 'inferred' || result === 'unknown';
315
+ }
316
+ //# sourceMappingURL=edge-evaluation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-evaluation.js","sourceRoot":"","sources":["../../src/rule-evaluator/edge-evaluation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAiB,MAAM,UAAU,CAAC;AAExD,OAAO,EACN,cAAc,EACd,eAAe,EACf,aAAa,EACb,cAAc,GAKd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAiB,MAAM,gBAAgB,CAAC;AAGhF,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAwB,MAAM,kBAAkB,CAAC;AAEtG,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AA4CnD,mDAAmD;AACnD,MAAM,eAAe,GAAG,CAAC,CAAC;AAU1B,MAAM,WAAW,GAAU,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAEpE,SAAS,OAAO,CAAC,UAA2B,EAAE,OAAgB;IAC7D,MAAM,MAAM,GAAG,UAAU,CAAC,gBAAgB,CAAC;IAC3C,MAAM,IAAI,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAC/C,OAAO,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,SAAS,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC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W,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;gBAC5H,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC;gBACpC,MAAM,CAAC,QAAQ,GAAG;oBACjB,GAAG,MAAM,CAAC,QAAQ;oBAClB,QAAQ,MAAM,6BAA6B,IAAI,CAAC,KAAK,kEAAkE,WAAW,CAAC,aAAa,qBAAqB;iBACrK,CAAC;YACH,CAAC;QACF,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,KAAK,GAAgC,OAAO,CAAC,KAAK,IAAI;QAC3D,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;QACzB,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1G,GAAG,sBAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC;KACnF,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;AAC7F,CAAC;AAED,SAAS,OAAO,CAAC,EAAE,MAAM,EAAwB;IAChD,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,SAAS,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,173 @@
1
+ import type { RuleExpressionCustomLists } from './custom-lists.js';
2
+ import { type EdgeResolverCtx } from './fields.js';
3
+ import { type SampleLogRecord, type SampleRequestCfProperties } from './log-sample.js';
4
+ import { type QueryArg } from './query-args.js';
5
+ /**
6
+ * Edge records are Cloudflare Logpush http_requests records as Libreflare's
7
+ * edge log mapping stores them (Vector's `edge_logs` transform). They hold
8
+ * some of the values the rules engine read, and
9
+ * test/fixtures/edge-record-probes.json compares each with the engine's. A
10
+ * field the record does not hold is unknown, never empty.
11
+ */
12
+ /** How the zone normalizes URLs, which the non-raw path fields read. */
13
+ export type UrlNormalization = 'off' | 'cloudflare' | 'rfc3986';
14
+ /** The request headers and cookies a zone's custom-field rules log. */
15
+ export interface EdgeLoggedFields {
16
+ /** Request headers logged in raw form, by name in any case. */
17
+ requestHeaders: readonly string[];
18
+ /**
19
+ * Request headers logged in transformed form, by name in any case. Their
20
+ * values are what the origin received, which a Transform Rule may have
21
+ * set, so they are unknown.
22
+ */
23
+ transformedRequestHeaders?: readonly string[];
24
+ /** Cookies logged, by name as configured; Cloudflare matches cookie names case-sensitively. */
25
+ cookies: readonly string[];
26
+ }
27
+ export interface EdgeRecordOptions {
28
+ /** The zone's logged fields at the record's time. Without them, the record's own headers and cookies stand in. */
29
+ loggedFields?: EdgeLoggedFields;
30
+ /** The zone's URL normalization. Without it, a path that a normalization would change is unknown. */
31
+ urlNormalization?: UrlNormalization;
32
+ }
33
+ /** A record's time, from `_time`, which Cloudflare's EdgeStartTimestamp sets. */
34
+ export interface EdgeRecordTime {
35
+ /** Milliseconds since the epoch. */
36
+ readonly epochMs: number;
37
+ /** As http.request.timestamp.sec reads it. */
38
+ readonly sec: number;
39
+ /** As http.request.timestamp.msec reads it: the millisecond within the second. */
40
+ readonly msec: number;
41
+ }
42
+ /** The rules of one ruleset that matched a request, from the record's MatchedRules. */
43
+ export interface EdgeMatchedRuleset {
44
+ readonly rulesetId: string;
45
+ /** In rule order. */
46
+ readonly ruleIds: readonly string[];
47
+ }
48
+ /** An edge record read for evaluation; see readEdgeRecord(). */
49
+ export interface EdgeRecord {
50
+ readonly rayId: string;
51
+ readonly time: EdgeRecordTime | undefined;
52
+ /**
53
+ * The Custom Rules the record lists, each once, in order, or every rule it
54
+ * lists when `ruleSourcesAligned` is false.
55
+ */
56
+ readonly customRuleIds: readonly string[];
57
+ /**
58
+ * Whether the record's rule sources line up with its rule IDs, which tell
59
+ * the Custom Rules apart. The mapping's compact() drops an empty entry from
60
+ * either array, and then they do not.
61
+ */
62
+ readonly ruleSourcesAligned: boolean;
63
+ /**
64
+ * The transform rules that matched, URL rewrites among them, by ruleset.
65
+ * MatchedRules lists no Custom Rules. The mapping drops it when empty.
66
+ */
67
+ readonly matchedRules: readonly EdgeMatchedRuleset[];
68
+ /** Whether the record's own headers and cookies stood in for logged fields that were not given. */
69
+ readonly assumedLoggedFields: boolean;
70
+ readonly urlNormalization: UrlNormalization | undefined;
71
+ /**
72
+ * The paths the non-raw path fields may read: one, or more when the
73
+ * normalization was not given or the order of its steps changes the path,
74
+ * or null when Cloudflare's normalization of the path is unknown.
75
+ */
76
+ readonly normalizedPaths: readonly string[] | null;
77
+ readonly method: string | undefined;
78
+ readonly scheme: string;
79
+ /** As http.host reads it: the host in lowercase, without a port or a trailing dot. */
80
+ readonly hostname: string;
81
+ /** The scheme and host as http.request.full_uri begins, without a port. */
82
+ readonly origin: string;
83
+ /** The path and query as the client sent them, which the raw fields read. */
84
+ readonly rawPath: string;
85
+ /** The query from its `?`, or empty. */
86
+ readonly search: string;
87
+ /** The query's arguments, which the query fields read. */
88
+ readonly queryArgs: readonly QueryArg[];
89
+ /** The query's arguments by name, with each name's values in order. */
90
+ readonly queryArgMap: ReadonlyMap<string, readonly string[]>;
91
+ readonly clientIp: string | undefined;
92
+ /** The client's source port, TCP or UDP. */
93
+ readonly clientPort: number | undefined;
94
+ /** The client connection's TCP round-trip time in whole milliseconds, 0 over HTTP/3. */
95
+ readonly tcpRttMs: number | undefined;
96
+ readonly zoneName: string | undefined;
97
+ readonly cf: SampleRequestCfProperties;
98
+ /** The request headers logged raw that the record holds, by lowercase name, with their first value. */
99
+ readonly headers: ReadonlyMap<string, string>;
100
+ /** The request headers logged raw, by lowercase name, but for those in `ambiguousHeaders`. */
101
+ readonly loggedHeaders: ReadonlySet<string>;
102
+ /** The request headers logged transformed, by lowercase name, which are unknown. */
103
+ readonly transformedHeaders: ReadonlySet<string>;
104
+ /**
105
+ * Logged request headers whose values are unknown because, flattened, a
106
+ * header named `cookie.<name>` and a logged cookie share a key.
107
+ */
108
+ readonly ambiguousHeaders: ReadonlySet<string>;
109
+ /** The logged cookies the record holds, by configured name. */
110
+ readonly cookies: ReadonlyMap<string, string>;
111
+ /** The logged cookies, by configured name. */
112
+ readonly loggedCookies: ReadonlySet<string>;
113
+ /**
114
+ * Logged cookies whose values are unknown: the record keeps one value
115
+ * under the lowercase name of those that differ only in case, and
116
+ * flattened, a logged header can share a cookie's key.
117
+ */
118
+ readonly ambiguousCookies: ReadonlySet<string>;
119
+ /**
120
+ * The record's cookie keys that the logged cookies do not name and that
121
+ * may stand for names with uppercase letters, since Logpush keys a cookie
122
+ * by its name in lowercase. A cookie of such a name is unknown.
123
+ */
124
+ readonly unnamedCookies: ReadonlySet<string>;
125
+ /** Whether the record shows that a Cookie header was sent. */
126
+ readonly cookieSent: boolean;
127
+ }
128
+ /** A record the evaluator cannot read, as opposed to a failure while evaluating one. */
129
+ export declare class EdgeRecordError extends Error {
130
+ readonly name = "EdgeRecordError";
131
+ }
132
+ /** Whether a sample is a mapped edge record, which has a Ray ID under `edge`, nested or flattened. */
133
+ export declare function isEdgeRecord(sample: SampleLogRecord): boolean;
134
+ /**
135
+ * Reads a mapped edge record, nested as the mapping writes it or flattened as
136
+ * VictoriaLogs returns it. Logpush logs only the first value of a header sent
137
+ * more than once, and the evaluator takes each logged header and cookie as
138
+ * sent once.
139
+ *
140
+ * @throws {EdgeRecordError} When the record has no `edge.ray_id`, or no http
141
+ * or https URL in `edge.url`.
142
+ */
143
+ export declare function readEdgeRecord(sample: SampleLogRecord, options?: EdgeRecordOptions): EdgeRecord;
144
+ /**
145
+ * The paths a mapped edge record's non-raw path fields may read with a URL
146
+ * normalization; see EdgeRecord.normalizedPaths.
147
+ *
148
+ * @throws {EdgeRecordError} When the record has no http or https URL in `edge.url`.
149
+ */
150
+ export declare function edgeRecordPaths(sample: SampleLogRecord, urlNormalization?: UrlNormalization): readonly string[] | null;
151
+ /** A mapped edge record's time, read without the rest of the record. */
152
+ export declare function edgeRecordTime(sample: SampleLogRecord): EdgeRecordTime | undefined;
153
+ /**
154
+ * An RFC 3339 time, such as `_time` or a rule version's time, or undefined
155
+ * for text that is not one, such as a month 13. Fractions below a
156
+ * millisecond are cut, and a leap second reads as the next minute's first,
157
+ * as in Unix time.
158
+ */
159
+ export declare function parseEdgeTime(text: string): EdgeRecordTime | undefined;
160
+ /** Options for reading fields from an edge record. */
161
+ export interface EdgeResolverOptions {
162
+ /** A route's prefix, which the non-raw path fields read before the visitor's path, as the route's rewrite puts it. */
163
+ routePrefix?: string;
164
+ /**
165
+ * A rewrite rule that is not a route's and set the path after a route's
166
+ * rewrite, which leaves the non-raw path fields unknown.
167
+ */
168
+ pathRewrittenBy?: string;
169
+ customLists?: RuleExpressionCustomLists;
170
+ }
171
+ /** A resolver context that reads an edge record. */
172
+ export declare function edgeResolverCtx(record: EdgeRecord, options: EdgeResolverOptions, warnings: Set<string>): EdgeResolverCtx;
173
+ //# sourceMappingURL=edge-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edge-record.d.ts","sourceRoot":"","sources":["../../src/rule-evaluator/edge-record.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAUN,KAAK,eAAe,EAEpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAA6C,KAAK,eAAe,EAAE,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAElI,OAAO,EAAiC,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG/E;;;;;;GAMG;AAEH,wEAAwE;AACxE,MAAM,MA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