@zvenigora/ng-eval-core 0.12.1 → 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,13 +14,154 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
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
|
+
|
|
17
158
|
## [0.12.1] - 2026-10-17
|
|
18
159
|
|
|
19
160
|
**Partial hardening of the call sandbox, which does not close every route, so keep
|
|
20
161
|
[`SECURITY.md`'s mitigations](../../SECURITY.md#mitigations) in place whatever the version.** A
|
|
21
162
|
tagged template's tag goes through the call sandbox ([A36](../../docs/backlog-retired.md#a36)), and
|
|
22
163
|
a dangerous function value is refused at the call, `new` and tag sites and at every other read the
|
|
23
|
-
walk makes but `typeof`'s operand ([A35](../../docs/backlog.md#a35)). A sequence leaves one value on
|
|
164
|
+
walk makes but `typeof`'s operand ([A35](../../docs/backlog-retired.md#a35)). A sequence leaves one value on
|
|
24
165
|
the stack ([A37](../../docs/backlog-retired.md#a37)). Two routes past the walk's own values stay
|
|
25
166
|
open: a container the host provides, which stays a limit, and a route through `this`, which 0.13.0
|
|
26
167
|
closes. The Security entry below states both, and `SECURITY.md`'s
|
|
@@ -69,7 +210,7 @@ ranges are `>=0.11.0 <0.13.0` and `>=0.12.0 <0.13.0`.
|
|
|
69
210
|
- **A tag that is not a function** throws the call's error, `Cannot call undefined or null
|
|
70
211
|
function` or `Value is not a function: <type>`. It threw a `TypeError` from `apply`.
|
|
71
212
|
- **A call, `new` or tagged template whose callee is a dangerous function is refused by its value,
|
|
72
|
-
under any name — [A35](../../docs/backlog.md#a35).** The sandboxes read the callee's written name,
|
|
213
|
+
under any name — [A35](../../docs/backlog-retired.md#a35).** The sandboxes read the callee's written name,
|
|
73
214
|
so with `eval` in the context as `run`, `run("1+1")` gave 2. `new`'s list of names never held the
|
|
74
215
|
timers either. In a browser application with zone.js, `new setTimeout("<code>", 0)` constructed
|
|
75
216
|
under the timer's own name, and zone.js handed the string to the browser's timer, which runs it
|
|
@@ -89,7 +230,7 @@ ranges are `>=0.11.0 <0.13.0` and `>=0.12.0 <0.13.0`.
|
|
|
89
230
|
before the call. Such a callee is a sequence, a conditional, a logical, an assignment, or a
|
|
90
231
|
parenthesised or optional-chain expression.
|
|
91
232
|
- **Every read of a dangerous function the walk makes is refused, except as a callee, a tag or
|
|
92
|
-
`typeof`'s operand — [A35](../../docs/backlog.md#a35).** The call sandbox checked only the
|
|
233
|
+
`typeof`'s operand — [A35](../../docs/backlog-retired.md#a35).** The call sandbox checked only the
|
|
93
234
|
callee, so a listed value handed on as anything else reached the native code that calls it. With
|
|
94
235
|
`eval` in the context, `["1+1"].map(eval)` gave `[2]` and `eval.call(null, "1+1")` gave 2. With
|
|
95
236
|
`Function`, `Function.call(null, "return 7")()` gave 7. Every published version up to 0.12.0 is
|