@zvenigora/ng-eval-core 0.12.0 → 0.13.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.
package/CHANGELOG.md CHANGED
@@ -14,7 +14,263 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
14
14
 
15
15
  ---
16
16
 
17
- ## [0.12.0] - 2026-10-13
17
+ ## [0.13.0] - 2026-10-20
18
+
19
+ **The route through `this` is closed, in both halves — the value and the receiver — and the
20
+ evaluation context is no longer writable by an expression, nor obtainable as a value the walk
21
+ produces.** A minor carrying breaking changes
22
+ ([A39](../../docs/backlog-retired.md#a39), [A42](../../docs/backlog-retired.md#a42); the
23
+ [A35 plan](../../docs/a35/plan.md)). Every change is internal: the `.d.ts` is byte-identical to
24
+ 0.12.1's.
25
+
26
+ **It does not close every route.** A container the host itself provides, a context the host nests
27
+ in the evaluation data or hands back behind a promise, the context `EvalResult.trace` holds after
28
+ an expression evaluated `this.k`, and a host-built AST that uses one `this` node in two places all
29
+ remain documented limits in every version, 0.13.0 included —
30
+ `SECURITY.md`'s [documented limits](../../SECURITY.md#documented-limits) state each one. So
31
+ 0.12.1's [mitigations](../../SECURITY.md#mitigations) still apply unchanged: place no listed
32
+ function in the context, and in a browser serve a Content Security Policy without `'unsafe-eval'`.
33
+
34
+ **`eval-signals` 0.6.0 and `eval-forms` 0.6.0 are the releases that admit it.** Every earlier one
35
+ excludes it by its own peer range — `eval-signals` 0.5.1 declares `>=0.11.0 <0.13.0` and
36
+ `eval-forms` 0.5.0 `>=0.12.0 <0.13.0` — so all three move together, and bumping `eval-core` alone
37
+ leaves a peer graph nothing can satisfy.
38
+
39
+ ### Breaking
40
+ - **`this` evaluates only as the object of a member access** — `this.k`, `this["k"]`, `this.fn()`,
41
+ and any spelling of `this` in that place under `caseInsensitive` — which resolves against the
42
+ context as before. Anywhere else it now throws
43
+ `Access to "this" outside a member access is blocked for security reasons`: as a value, an
44
+ argument or an operand, `typeof this` included. Up to 0.12.1 it evaluated to the `EvalContext`
45
+ the walk ran against. Together with the receiver entry below, this **closes the route through
46
+ `this`** that 0.12.1's Security entry states as open ([A39](../../docs/backlog-retired.md#a39)).
47
+ Keep 0.12.1's mitigations in place regardless — place no listed function in the context, and
48
+ serve a Content Security Policy without `'unsafe-eval'` — since a container the host itself
49
+ provides remains a documented limit, which this release does not close.
50
+ - **The assertions it changes**: three, all in `eval-forms`' suite, none in `eval-core`'s or
51
+ `eval-signals`'. Each evaluated `this` outside a member access to reach a rule's context and read
52
+ its lookups ([D5](../../docs/backlog-retired.md#d5)). They now take the context where it is built.
53
+ - **A function the context holds is called with a guarded view of the `EvalContext`**, not the
54
+ context and not the object behind it. **The rule**: every receiver the evaluator resolved out of
55
+ the context's own chain is now that view. In practice that is a bare call, `fn()`; a bare tagged
56
+ template, `` fn`x` ``; and `this.fn()` for any key the context resolves — one held directly on
57
+ it, one a lookup answers, one a prior scope answers without declaring a `thisArg`, and one bound
58
+ by a scope the expression or a source function pushed.
59
+ **What is unchanged**: `obj.fn()` and `ns.fn()`, a prior scope's **declared** `thisArg`, and a
60
+ call on an object the context merely holds — including one that refers back to the context
61
+ itself. Those receivers are the host's own, not the evaluator's choice.
62
+ On the view, `push` and `pop` still act on the real context, so a function that pushes or pops a
63
+ scope is unaffected. **Every other read throws**
64
+ `Access to "<key>" on the evaluation context is blocked for security reasons`, and **a write
65
+ throws** a `TypeError` in strict mode, which compiled module code is, or is silently dropped in
66
+ sloppy mode; up to 0.12.1 a read answered from the context and a write landed on it.
67
+ - **What this breaks**: a method held directly on the context and called as `this.fn()` can no
68
+ longer reach its sibling keys through its own `this`.
69
+ - **The migration**: give that object its own named scope with an explicit `thisArg`, which this
70
+ release does not change. `ns.fn()` and `obj.fn()` are unchanged too — only a receiver the
71
+ evaluator resolved out of the context's own chain is narrowed.
72
+ - **The view's identity is not stable**: every call receives a new one, even two calls in one
73
+ evaluation on one context. Do not key anything on a function's `this` — not a `WeakMap`, not a
74
+ `Set`, not an identity comparison. Nothing retains a view, which is what keeps the guard's cost
75
+ off the ordinary one-shot evaluation.
76
+ - **`push` and `pop` are the ones the context's class defines**, found on its prototype chain, so
77
+ a subclass override is used and a property set on the instance is not. A context whose class
78
+ defines neither has them refused like any other key.
79
+ - Together with the entry above this closes [A39](../../docs/backlog-retired.md#a39), the
80
+ receiver half of it. The member-write policy still receives the real context as its write
81
+ target, so a context implementing `checkMemberWrite` sees what it always did.
82
+ - **The assertions it changes**: six — two in `eval-core`'s suite pinning a receiver's identity,
83
+ two pinning a context method's reach into its siblings, and two in `eval-signals`'. Each is
84
+ rewritten to assert the new contract, none is dropped. Together with the three in `eval-forms`
85
+ named above, nine in all across the three suites.
86
+ - **A write whose target is the evaluation context now throws**
87
+ `Write to the evaluation context is blocked for security reasons`, where up to 0.12.1 it
88
+ succeeded ([A42](../../docs/backlog-retired.md#a42)).
89
+ - **What this is.** `this.k = v` is a member write, and for a key the context does **not**
90
+ resolve the target is the `EvalContext` itself — so the write added an own property to the
91
+ evaluator's own object. It applies to every form the evaluator offers: dotted and computed
92
+ member writes, compound writes and the update expressions. It is matched **by class**, so it
93
+ also covers a signal context and a context reached under some other name.
94
+ - **What is unchanged**: a write to a key the context **does** resolve. `this.n = 7`, `n = 7`
95
+ and `this.n++`, for a key the caller's object holds, land on that object exactly as before,
96
+ through `EvalContext.set` and the write policy a subclass may override. That is the write path
97
+ consumers use, and it is untouched.
98
+ - **What this breaks**: an expression that wrote to the context under a key nothing resolves now
99
+ throws where it used to succeed. Nothing could read the result back — `EvalContext.get`
100
+ resolves through the scopes, the original, the prior scopes and the lookups, and never off the
101
+ instance — so an expression that depended on reading it back cannot exist; one that made the
102
+ write and ignored it will now fail.
103
+ - **Native writers are refused the same way**: `Object.assign`, `Object.defineProperty`,
104
+ `Object.defineProperties`, `Object.setPrototypeOf`, `Object.freeze`, `Object.seal`,
105
+ `Object.preventExtensions`, `Reflect.set`, `Reflect.defineProperty`, `Reflect.deleteProperty`,
106
+ `Reflect.setPrototypeOf` and `Reflect.preventExtensions`, including when reached through
107
+ `call`, `apply` or `bind`. A context that implements `checkMemberWrite` is still asked first,
108
+ so its own refusal is still the error a consumer sees.
109
+ - **The context is also not a value an expression can hold.** Every value the walk pushes is
110
+ refused if it is an `EvalContext`, so a bare identifier naming one, a member read of one, an
111
+ object spread or destructuring of one, and `Object.values` or `JSON.stringify` of one all throw
112
+ `Access to the evaluation context is blocked for security reasons`. The one exemption is the
113
+ walk's **own** context as a member's object, matched by identity as well as position, so
114
+ `this.k` is unaffected — it resolves through the context's chain and reads nothing off the
115
+ instance. **Two routes are outside this by construction**: the check reads the value pushed and
116
+ does not look inside it, and it does not run on `evaluateAsync`'s promise unwrap, which happens
117
+ after the walk — so a host that places its own context inside a value an expression can read,
118
+ nested in an object or an array or behind a promise, still gets it back as a result. Reading it
119
+ back one hop later is refused.
120
+ - **A `checkMemberWrite` held as an instance property now throws.** The policy and the opt-in
121
+ that turns object recording on are both resolved from the context's **prototype chain**, so a
122
+ policy on the instance would be inert. Rather than fail open in silence, building an
123
+ `EvalState` around such a context throws, naming the condition and the remedy.
124
+ **Declare it as a *method*** — `class C extends EvalContext { override checkMemberWrite(write) { … } }`,
125
+ which is what `@zvenigora/ng-eval-signals` does. **A class field will not do**:
126
+ `class C extends EvalContext { checkMemberWrite = (write) => … }` is an instance property, as
127
+ is an assignment in a constructor or `context.checkMemberWrite = fn` after the fact, and all
128
+ three now throw. This is the same rule as for `push` and `pop` above, and for the same reason:
129
+ an expression must not be able to supply one — and the only party who can still hold one on an
130
+ instance is a host that meant it, which deserves to be told exactly what to change.
131
+ - **A context whose class defines `push` but no `pop` is refused at the first scope push**,
132
+ with the same named refusal. The pop runs in a `finally`, where a throw would replace the
133
+ error the body was propagating, so it is tolerant; refusing the pair at the push is what
134
+ keeps them symmetric. No context `EvalContext.fromContext` produces has this shape.
135
+ - **Why it is in this release rather than later.** The own property shadowed a method of the
136
+ class, and the evaluator calls `push` on the context at four sites, so a planted function was
137
+ invoked with the real context as its `this` — the capture that made a cross-context disclosure
138
+ possible. It is also an **availability** defect: a plant over `push` that evaluates anything
139
+ recurses until the stack is gone and persists on the context, so every later evaluation on a
140
+ reused context throws. `@zvenigora/ng-eval-signals` and `@zvenigora/ng-eval-forms` both reuse
141
+ one context by design; neither is exposed, because a signal context refuses the planting write
142
+ through `checkMemberWrite`, and `eval-forms` evaluates through `eval-signals`.
143
+ - **Methods the evaluator calls on a context are taken from its class**, not from the instance,
144
+ at the scope pushes and pops, the write path and the policy — so an own property arriving by
145
+ any other route is not what the evaluator invokes.
146
+
147
+ ### Performance
148
+ - **These checks cost about 10% on the member-write path, and less elsewhere.** Measured against
149
+ 0.12.1's evaluator in plain Node, production bundles, twelve paired rotations per path, medians:
150
+ a member write **+10.0%**, a bare call **+7.6%**, a member read **+1.85%**. The member write is
151
+ positive in all twelve rotations, so it is a consistent cost rather than one that disappears
152
+ into run-to-run variation, and it is stated here as such: an expression that assigns to object
153
+ properties in a loop is the shape that pays most. The member read is indistinguishable from the
154
+ baseline. No evaluation result changes.
155
+
156
+ ---
157
+
158
+ ## [0.12.1] - 2026-10-17
159
+
160
+ **Partial hardening of the call sandbox, which does not close every route, so keep
161
+ [`SECURITY.md`'s mitigations](../../SECURITY.md#mitigations) in place whatever the version.** A
162
+ tagged template's tag goes through the call sandbox ([A36](../../docs/backlog-retired.md#a36)), and
163
+ a dangerous function value is refused at the call, `new` and tag sites and at every other read the
164
+ walk makes but `typeof`'s operand ([A35](../../docs/backlog-retired.md#a35)). A sequence leaves one value on
165
+ the stack ([A37](../../docs/backlog-retired.md#a37)). Two routes past the walk's own values stay
166
+ open: a container the host provides, which stays a limit, and a route through `this`, which 0.13.0
167
+ closes. The Security entry below states both, and `SECURITY.md`'s
168
+ [documented limits](../../SECURITY.md#documented-limits) give the rest. It is a patch although an
169
+ expression that reads a dangerous function now throws where it used to give a value: none of the
170
+ three packages' existing cases reads one, and the defect is a security one. No exported symbol
171
+ changes shape: the `.d.ts` is byte-identical to 0.12.0's. `eval-signals` 0.5.1 and `eval-forms` 0.5.0 admit it: their peer
172
+ ranges are `>=0.11.0 <0.13.0` and `>=0.12.0 <0.13.0`.
173
+
174
+ ### Fixed
175
+ - **A sequence leaves exactly one value on the stack, and shows one node to hooks —
176
+ [A37](../../docs/backlog-retired.md#a37).** No visitor was registered for `SequenceExpression`, so
177
+ the walk left every value but the last on the stack: `(0, 1)` left one entry and `((1, 2), 3)` two.
178
+ Within one walk, a `for` loop whose update is a sequence (`i++, j--`) left one entry per iteration,
179
+ and an arrow body `x => (a, b)` one per call, and a reused state accumulated them all. No hook saw
180
+ the node. Every published version up to 0.12.0 is affected.
181
+ - **No residual stack values**: each sequence leaves only its own value, so a reused state no
182
+ longer accumulates anything.
183
+ - **One `before` and one `after` node-hook event per sequence**, the `after` carrying the last
184
+ value, where there were none. So under `trackTime`, `nodeTimings` gains a `SequenceExpression`
185
+ entry.
186
+ - **One trace entry per sequence**, carrying the last value, where there was none. So
187
+ `tracePushCount` counts one more per sequence, and `traceTruncated` can be set on a walk that
188
+ used to fit under `maxTraceItems`.
189
+ - **Evaluated values are unchanged.** A sequence's value was already its last expression's, since
190
+ each consumer reads only the top of the stack.
191
+
192
+ ### Security
193
+ - **A tagged template's tag goes through the call sandbox and the write policy —
194
+ [A36](../../docs/backlog-retired.md#a36).** The visitor applied the tag with no check at all, so
195
+ with `Function` in the context `` Function`return 7`() `` gave 7. Every published version up to
196
+ 0.12.0 is affected.
197
+ - **Now refused**, with the call's message `Function call blocked for security reasons: <name>`:
198
+ a tag the call sandbox refuses, by its written name, by `Function`'s identity, or by the
199
+ source-pattern test. A member tag is checked under its property name, a computed key included,
200
+ as a member call is, so `` obj["fetch"]`x` `` is refused as `obj["fetch"]()` is.
201
+ - **Now asked**: a context's `checkMemberWrite`, before a tag that is a built-in writing into its
202
+ receiver or its first argument, as before such a call.
203
+ - **A member tag's `this` is now its object**, or a prior scope's `thisArg`, as a member call's
204
+ is. It was the evaluation context. So a mutating built-in used as a member tag writes into its
205
+ object: `` a.push`x` `` now appends to `a`, where it wrote into the context. Any other tag's
206
+ `this` is still the context, as a bare call's is.
207
+ - **A member tag raises no `before` or `after` node-hook events, and leaves no trace entry, for
208
+ its own `MemberExpression` node**, as a member call's callee already does. Its read event is
209
+ unchanged.
210
+ - **A tag that is not a function** throws the call's error, `Cannot call undefined or null
211
+ function` or `Value is not a function: <type>`. It threw a `TypeError` from `apply`.
212
+ - **A call, `new` or tagged template whose callee is a dangerous function is refused by its value,
213
+ under any name — [A35](../../docs/backlog-retired.md#a35).** The sandboxes read the callee's written name,
214
+ so with `eval` in the context as `run`, `run("1+1")` gave 2. `new`'s list of names never held the
215
+ timers either. In a browser application with zone.js, `new setTimeout("<code>", 0)` constructed
216
+ under the timer's own name, and zone.js handed the string to the browser's timer, which runs it
217
+ unless a CSP forbids `unsafe-eval`. Every published version up to 0.12.0 is affected.
218
+ - **A listed value** is one of the realm's dangerous functions, matched by identity: the global
219
+ value of each name the call sandbox refuses, where the realm has it, and zone.js's saved
220
+ original of each; and `GeneratorFunction`, `AsyncFunction` and `AsyncGeneratorFunction`, read
221
+ from function literals, where they are not `Function` itself. A bound function is a listed value
222
+ too when its name, stripped of every `bound ` prefix, is one of those names.
223
+ - **Now refused**, with the site's existing message, `Function call blocked for security
224
+ reasons: <name>` or `Constructor blocked for security reasons: <name>`: a callee whose value is
225
+ a listed value, under any name. That covers an alias, a member, a call result, `this.k`, a scope
226
+ namespace, a destructured name, an optional call, a case variant under `caseInsensitive`, and
227
+ `new setTimeout(…)` or `new setInterval(…)` under the timer's own name. The name is the written
228
+ name, the property name, or `anonymous`. A callee under which the listed value is read takes
229
+ the read's message instead, from the entry below, since the value is refused where it is read,
230
+ before the call. Such a callee is a sequence, a conditional, a logical, an assignment, or a
231
+ parenthesised or optional-chain expression.
232
+ - **Every read of a dangerous function the walk makes is refused, except as a callee, a tag or
233
+ `typeof`'s operand — [A35](../../docs/backlog-retired.md#a35).** The call sandbox checked only the
234
+ callee, so a listed value handed on as anything else reached the native code that calls it. With
235
+ `eval` in the context, `["1+1"].map(eval)` gave `[2]` and `eval.call(null, "1+1")` gave 2. With
236
+ `Function`, `Function.call(null, "return 7")()` gave 7. Every published version up to 0.12.0 is
237
+ affected.
238
+ - **The rule.** Whenever the walk reads a listed value, as defined above, it throws
239
+ `Access to dangerous function "<name>" is blocked for security reasons`. The name is the
240
+ identifier, the member's property name, or the function's own `name`. Among the reads that
241
+ hand it on:
242
+ - an argument;
243
+ - the receiver of `call`, `apply` or `bind`;
244
+ - an element of an array or a property of an object the expression builds;
245
+ - a branch of a conditional or a logical;
246
+ - the last expression of a sequence used as a callee, a constructor or a tag;
247
+ - a parenthesised callee under `preserveParens`;
248
+ - the expression's own result.
249
+ - **Reads that only inspect the value throw too**, since the rule has no exception for them:
250
+ - assigning over a listed function, `fetch = 1` or `obj.fetch = 1`, since an assignment reads
251
+ its target before writing it;
252
+ - updating one, `obj.fetch++`, which writes first and then throws, so the failed evaluation
253
+ leaves its write behind ([A40](../../docs/backlog.md#a40));
254
+ - an operator's operand, `x instanceof Function` or `obj.fetch != null`;
255
+ - a conditional's test, `obj.fetch ? 1 : 0`;
256
+ - a template interpolation, `` `${eval}` ``, and a declaration's initializer;
257
+ - `typeof (eval)` under `preserveParens`, whose operand is the parenthesis, not the identifier.
258
+ - **Not refused.** A callee or a tag itself is refused by the entry above, with its site's
259
+ message. `typeof`'s operand is exempt, so `typeof eval` is still `"function"`. Only that node
260
+ itself is exempt, never what is under it: in `(0, eval)("1+1")` the callee is the sequence, so
261
+ the read of `eval` inside it is refused.
262
+ - **Not covered: two routes by which a listed value reaches native code without passing through
263
+ the walk's own values.** So this release is partial hardening.
264
+ - **A container the host provides**, whose elements are spread into a native call.
265
+ - **A route through `this`**, which 0.13.0 closes.
266
+
267
+ `SECURITY.md` states both as limits. It gives the mitigations that hold whatever the route:
268
+ a host places no listed function in the context, and in a browser, a Content Security Policy
269
+ without `'unsafe-eval'` stops `eval`, `Function` and a string timer.
270
+
271
+ ---
272
+
273
+ ## [0.12.0] - 2026-10-14
18
274
 
19
275
  **Colon-joined names, opt-in — Phase 9 ([plan](../../docs/colon-identifiers/phase-9-plan.md)) — and
20
276
  a parse cache that honours the options it is asked with.** A minor: two additions, the