@zvenigora/ng-eval-core 0.11.1 → 0.12.1
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 +167 -0
- package/README.md +45 -0
- package/fesm2022/zvenigora-ng-eval-core.mjs +1239 -530
- package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -1
- package/package.json +1 -1
- package/types/zvenigora-ng-eval-core.d.ts +54 -7
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,173 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
+
## [0.12.1] - 2026-10-17
|
|
18
|
+
|
|
19
|
+
**Partial hardening of the call sandbox, which does not close every route, so keep
|
|
20
|
+
[`SECURITY.md`'s mitigations](../../SECURITY.md#mitigations) in place whatever the version.** A
|
|
21
|
+
tagged template's tag goes through the call sandbox ([A36](../../docs/backlog-retired.md#a36)), and
|
|
22
|
+
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
|
|
24
|
+
the stack ([A37](../../docs/backlog-retired.md#a37)). Two routes past the walk's own values stay
|
|
25
|
+
open: a container the host provides, which stays a limit, and a route through `this`, which 0.13.0
|
|
26
|
+
closes. The Security entry below states both, and `SECURITY.md`'s
|
|
27
|
+
[documented limits](../../SECURITY.md#documented-limits) give the rest. It is a patch although an
|
|
28
|
+
expression that reads a dangerous function now throws where it used to give a value: none of the
|
|
29
|
+
three packages' existing cases reads one, and the defect is a security one. No exported symbol
|
|
30
|
+
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
|
|
31
|
+
ranges are `>=0.11.0 <0.13.0` and `>=0.12.0 <0.13.0`.
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
- **A sequence leaves exactly one value on the stack, and shows one node to hooks —
|
|
35
|
+
[A37](../../docs/backlog-retired.md#a37).** No visitor was registered for `SequenceExpression`, so
|
|
36
|
+
the walk left every value but the last on the stack: `(0, 1)` left one entry and `((1, 2), 3)` two.
|
|
37
|
+
Within one walk, a `for` loop whose update is a sequence (`i++, j--`) left one entry per iteration,
|
|
38
|
+
and an arrow body `x => (a, b)` one per call, and a reused state accumulated them all. No hook saw
|
|
39
|
+
the node. Every published version up to 0.12.0 is affected.
|
|
40
|
+
- **No residual stack values**: each sequence leaves only its own value, so a reused state no
|
|
41
|
+
longer accumulates anything.
|
|
42
|
+
- **One `before` and one `after` node-hook event per sequence**, the `after` carrying the last
|
|
43
|
+
value, where there were none. So under `trackTime`, `nodeTimings` gains a `SequenceExpression`
|
|
44
|
+
entry.
|
|
45
|
+
- **One trace entry per sequence**, carrying the last value, where there was none. So
|
|
46
|
+
`tracePushCount` counts one more per sequence, and `traceTruncated` can be set on a walk that
|
|
47
|
+
used to fit under `maxTraceItems`.
|
|
48
|
+
- **Evaluated values are unchanged.** A sequence's value was already its last expression's, since
|
|
49
|
+
each consumer reads only the top of the stack.
|
|
50
|
+
|
|
51
|
+
### Security
|
|
52
|
+
- **A tagged template's tag goes through the call sandbox and the write policy —
|
|
53
|
+
[A36](../../docs/backlog-retired.md#a36).** The visitor applied the tag with no check at all, so
|
|
54
|
+
with `Function` in the context `` Function`return 7`() `` gave 7. Every published version up to
|
|
55
|
+
0.12.0 is affected.
|
|
56
|
+
- **Now refused**, with the call's message `Function call blocked for security reasons: <name>`:
|
|
57
|
+
a tag the call sandbox refuses, by its written name, by `Function`'s identity, or by the
|
|
58
|
+
source-pattern test. A member tag is checked under its property name, a computed key included,
|
|
59
|
+
as a member call is, so `` obj["fetch"]`x` `` is refused as `obj["fetch"]()` is.
|
|
60
|
+
- **Now asked**: a context's `checkMemberWrite`, before a tag that is a built-in writing into its
|
|
61
|
+
receiver or its first argument, as before such a call.
|
|
62
|
+
- **A member tag's `this` is now its object**, or a prior scope's `thisArg`, as a member call's
|
|
63
|
+
is. It was the evaluation context. So a mutating built-in used as a member tag writes into its
|
|
64
|
+
object: `` a.push`x` `` now appends to `a`, where it wrote into the context. Any other tag's
|
|
65
|
+
`this` is still the context, as a bare call's is.
|
|
66
|
+
- **A member tag raises no `before` or `after` node-hook events, and leaves no trace entry, for
|
|
67
|
+
its own `MemberExpression` node**, as a member call's callee already does. Its read event is
|
|
68
|
+
unchanged.
|
|
69
|
+
- **A tag that is not a function** throws the call's error, `Cannot call undefined or null
|
|
70
|
+
function` or `Value is not a function: <type>`. It threw a `TypeError` from `apply`.
|
|
71
|
+
- **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,
|
|
73
|
+
so with `eval` in the context as `run`, `run("1+1")` gave 2. `new`'s list of names never held the
|
|
74
|
+
timers either. In a browser application with zone.js, `new setTimeout("<code>", 0)` constructed
|
|
75
|
+
under the timer's own name, and zone.js handed the string to the browser's timer, which runs it
|
|
76
|
+
unless a CSP forbids `unsafe-eval`. Every published version up to 0.12.0 is affected.
|
|
77
|
+
- **A listed value** is one of the realm's dangerous functions, matched by identity: the global
|
|
78
|
+
value of each name the call sandbox refuses, where the realm has it, and zone.js's saved
|
|
79
|
+
original of each; and `GeneratorFunction`, `AsyncFunction` and `AsyncGeneratorFunction`, read
|
|
80
|
+
from function literals, where they are not `Function` itself. A bound function is a listed value
|
|
81
|
+
too when its name, stripped of every `bound ` prefix, is one of those names.
|
|
82
|
+
- **Now refused**, with the site's existing message, `Function call blocked for security
|
|
83
|
+
reasons: <name>` or `Constructor blocked for security reasons: <name>`: a callee whose value is
|
|
84
|
+
a listed value, under any name. That covers an alias, a member, a call result, `this.k`, a scope
|
|
85
|
+
namespace, a destructured name, an optional call, a case variant under `caseInsensitive`, and
|
|
86
|
+
`new setTimeout(…)` or `new setInterval(…)` under the timer's own name. The name is the written
|
|
87
|
+
name, the property name, or `anonymous`. A callee under which the listed value is read takes
|
|
88
|
+
the read's message instead, from the entry below, since the value is refused where it is read,
|
|
89
|
+
before the call. Such a callee is a sequence, a conditional, a logical, an assignment, or a
|
|
90
|
+
parenthesised or optional-chain expression.
|
|
91
|
+
- **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
|
|
93
|
+
callee, so a listed value handed on as anything else reached the native code that calls it. With
|
|
94
|
+
`eval` in the context, `["1+1"].map(eval)` gave `[2]` and `eval.call(null, "1+1")` gave 2. With
|
|
95
|
+
`Function`, `Function.call(null, "return 7")()` gave 7. Every published version up to 0.12.0 is
|
|
96
|
+
affected.
|
|
97
|
+
- **The rule.** Whenever the walk reads a listed value, as defined above, it throws
|
|
98
|
+
`Access to dangerous function "<name>" is blocked for security reasons`. The name is the
|
|
99
|
+
identifier, the member's property name, or the function's own `name`. Among the reads that
|
|
100
|
+
hand it on:
|
|
101
|
+
- an argument;
|
|
102
|
+
- the receiver of `call`, `apply` or `bind`;
|
|
103
|
+
- an element of an array or a property of an object the expression builds;
|
|
104
|
+
- a branch of a conditional or a logical;
|
|
105
|
+
- the last expression of a sequence used as a callee, a constructor or a tag;
|
|
106
|
+
- a parenthesised callee under `preserveParens`;
|
|
107
|
+
- the expression's own result.
|
|
108
|
+
- **Reads that only inspect the value throw too**, since the rule has no exception for them:
|
|
109
|
+
- assigning over a listed function, `fetch = 1` or `obj.fetch = 1`, since an assignment reads
|
|
110
|
+
its target before writing it;
|
|
111
|
+
- updating one, `obj.fetch++`, which writes first and then throws, so the failed evaluation
|
|
112
|
+
leaves its write behind ([A40](../../docs/backlog.md#a40));
|
|
113
|
+
- an operator's operand, `x instanceof Function` or `obj.fetch != null`;
|
|
114
|
+
- a conditional's test, `obj.fetch ? 1 : 0`;
|
|
115
|
+
- a template interpolation, `` `${eval}` ``, and a declaration's initializer;
|
|
116
|
+
- `typeof (eval)` under `preserveParens`, whose operand is the parenthesis, not the identifier.
|
|
117
|
+
- **Not refused.** A callee or a tag itself is refused by the entry above, with its site's
|
|
118
|
+
message. `typeof`'s operand is exempt, so `typeof eval` is still `"function"`. Only that node
|
|
119
|
+
itself is exempt, never what is under it: in `(0, eval)("1+1")` the callee is the sequence, so
|
|
120
|
+
the read of `eval` inside it is refused.
|
|
121
|
+
- **Not covered: two routes by which a listed value reaches native code without passing through
|
|
122
|
+
the walk's own values.** So this release is partial hardening.
|
|
123
|
+
- **A container the host provides**, whose elements are spread into a native call.
|
|
124
|
+
- **A route through `this`**, which 0.13.0 closes.
|
|
125
|
+
|
|
126
|
+
`SECURITY.md` states both as limits. It gives the mitigations that hold whatever the route:
|
|
127
|
+
a host places no listed function in the context, and in a browser, a Content Security Policy
|
|
128
|
+
without `'unsafe-eval'` stops `eval`, `Function` and a string timer.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## [0.12.0] - 2026-10-14
|
|
133
|
+
|
|
134
|
+
**Colon-joined names, opt-in — Phase 9 ([plan](../../docs/colon-identifiers/phase-9-plan.md)) — and
|
|
135
|
+
a parse cache that honours the options it is asked with.** A minor: two additions, the
|
|
136
|
+
compiled-string key that goes with them, and the [A26](../../docs/backlog-retired.md#a26) fix. No
|
|
137
|
+
exported symbol changes shape: the `.d.ts` differs from 0.11.1 by `ParserOptions.colonIdentifiers`,
|
|
138
|
+
`provideColonIdentifiers` and documentation comments, beside a private member each on
|
|
139
|
+
`ParserService` and `CompilerService`. The peer ranges are unchanged, `acorn ^8.11.2` included: the
|
|
140
|
+
grammar's spec and corpus pass at 8.11.2 (the plan's § 8 q3). `eval-signals` 0.5.1 and `eval-forms` 0.5.0 admit it;
|
|
141
|
+
`eval-signals` 0.4.0–0.5.0 and `eval-forms` 0.4.x declare `>=0.11.0 <0.12.0` and do not.
|
|
142
|
+
|
|
143
|
+
### Added
|
|
144
|
+
- **`ParserOptions.colonIdentifiers`.** With it on, a colon-joined name such as `Q1:1` or `VP14:0`
|
|
145
|
+
parses as one `Identifier` whose `name` is the whole key, so it reads `context['Q1:1']`. It is
|
|
146
|
+
off by default, and with it off a parse is acorn's own, as before. Where JavaScript already gives
|
|
147
|
+
the colon a meaning, the name gives way or is refused and is never read as something else: in a
|
|
148
|
+
conditional's consequent it is written in parentheses, `c ? (Q1:1) : 0`, and as an object key it
|
|
149
|
+
is a `SyntaxError` — quote it. So under the option a compact object literal, `({a:1})`, needs a
|
|
150
|
+
space after the key's colon. Hooks, dependency tracking and every prototype-pollution refusal see
|
|
151
|
+
an ordinary identifier. The README's "Colon-joined names" gives the rule.
|
|
152
|
+
- **`provideColonIdentifiers()`**, which turns `colonIdentifiers` on for an application.
|
|
153
|
+
`ParserService` reads it when it is constructed, so every parse through `EvalService`,
|
|
154
|
+
`CompilerService` and `DiscoveryService` follows it, and a per-call `colonIdentifiers` overrides
|
|
155
|
+
it. It belongs in the root providers: in a child environment injector, such as a lazy route's, it
|
|
156
|
+
throws when that injector is created. `new ParserService()` outside an injection context keeps
|
|
157
|
+
the option off.
|
|
158
|
+
- **`CompilerService` keys a compiled string on the options its parse uses**, as `ParserService`
|
|
159
|
+
keys an AST, so a text compiled before `ParserService.parserOptions` was replaced through its
|
|
160
|
+
setter — with `colonIdentifiers` turned on, for one — is compiled again rather than served the
|
|
161
|
+
old function. A write in place into that object is not seen, as it is not for an AST
|
|
162
|
+
([A34](../../docs/backlog.md#a34)). Two narrower
|
|
163
|
+
changes: a subclass that sets `CompilerService`'s protected per-call options is served a function
|
|
164
|
+
for its current ones, compiled on every call when they carry an acorn callback or `program`, and
|
|
165
|
+
a value JSON cannot hold, set in `ParserService.parserOptions` under a key `defaultParserOptions`
|
|
166
|
+
does not carry, now compiles uncached.
|
|
167
|
+
|
|
168
|
+
### Fixed
|
|
169
|
+
- **`ParserService` serves a cached AST only to a parse with the options that produced it —
|
|
170
|
+
[A26](../../docs/backlog-retired.md#a26).** The parse cache was keyed on the expression alone, so
|
|
171
|
+
the first parse of a text decided what every later caller got for it, whatever options they
|
|
172
|
+
passed: after one `ParserService.parse('await p', { ecmaVersion: 2022, allowAwaitOutsideFunction:
|
|
173
|
+
true })`, `EvalService.simpleEval('await p')` returned a promise instead of throwing its
|
|
174
|
+
`SyntaxError`, and a direct `ParserService.parse` caller and the services, which ask for
|
|
175
|
+
differently shaped results, were each served the other's. The key now holds every option that
|
|
176
|
+
changes the parse, which is all but `cacheSize`, acorn's four callbacks and `program`. A parse
|
|
177
|
+
carrying a callback or a `program` neither reads nor writes the cache, so the callback runs on
|
|
178
|
+
every parse. A change made through the `parserOptions` setter is honoured for text already
|
|
179
|
+
cached; a write in place into an options object, the service's or one passed again, is not
|
|
180
|
+
([A34](../../docs/backlog.md#a34)). Every published version to 0.11.1 is affected.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
17
184
|
## [0.11.1] - 2026-10-10
|
|
18
185
|
|
|
19
186
|
**Two cache fixes: `CompilerService` no longer returns one AST's compiled function for another, and
|
package/README.md
CHANGED
|
@@ -78,6 +78,51 @@ const result = service.simpleEval('cat.action(args, cat.num, "times")', evalCont
|
|
|
78
78
|
|
|
79
79
|
Note that an `EvalContext` may back any number of evaluations, and that `caseInsensitive` set on the context alone does not reach the walk — pass it in the evaluation options too.
|
|
80
80
|
|
|
81
|
+
### Colon-joined names — `provideColonIdentifiers`
|
|
82
|
+
|
|
83
|
+
Some expression languages name their values `Q1:1` or `VP14:0`. With `colonIdentifiers` on, such a name parses as one identifier and reads the context key of the same spelling, `context['Q1:1']`. It is off by default, and with it off every expression parses as it always has.
|
|
84
|
+
|
|
85
|
+
`provideColonIdentifiers()` turns it on for an application: `ParserService` reads it when it is constructed, so every parse through `EvalService`, `CompilerService` and `DiscoveryService` follows it. Put it in the application's **root** providers. `ParserService` is provided in the root, so in a lazy route's providers, or any other child injector's, the provider would reach no parse; there it throws when that injector is created instead.
|
|
86
|
+
|
|
87
|
+
A per-call `colonIdentifiers` in the options of `ParserService.parse`, or of the exported `parse`, overrides it — and the exported `parse` sees only the options it is given. Setting `ParserService.parserOptions` to a new object is the imperative alternative: every later parse or compile follows it, of a text seen before as of a new one, while a function already compiled keeps the reading it was compiled with.
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
import { EvalService, ParserService,
|
|
91
|
+
provideColonIdentifiers } from '@zvenigora/ng-eval-core';
|
|
92
|
+
|
|
93
|
+
// app.config.ts: the application's root providers, not a lazy route's
|
|
94
|
+
export const appConfig = { providers: [provideColonIdentifiers()] };
|
|
95
|
+
|
|
96
|
+
const parser = inject(ParserService);
|
|
97
|
+
parser.parserOptions.colonIdentifiers; // true - the effective setting
|
|
98
|
+
|
|
99
|
+
const service = inject(EvalService);
|
|
100
|
+
service.simpleEval('Q1:1 + 1', { 'Q1:1': 2 }); // 3
|
|
101
|
+
service.simpleEval('Q1:1 + 1', { Q1: 100 }); // NaN - 'Q1:1' is a key of its own
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**The rule.** A colon-joined name is a first segment — an ASCII letter, `_` or `$`, then ASCII letters, digits, `_` or `$` — followed by one or more segments of the same characters, each after a `:`, which may start with a digit: `Q1:1`, `VP14:0`, `Q1:1:3`, `Q1:_x`. Nothing may sit inside it, no space, comment or line break, and the longest match wins, so `Q1:1:3` is one name. The name is an opaque key: `Q1:01` and `Q1:1` are different keys, and nothing splits one into segments. It joins wherever an identifier can stand — in an expression, after `.` and `?.` (`obj.Q1:1` reads `obj['Q1:1']`, and `sheet:A1.value` is `(sheet:A1).value`), as a binding (`let Q1:1 = 5`, `(Q1:1) => …`) and inside a template's `${…}` — and text stays text: `"Q1:1"`, a template's own text, a regex, a comment.
|
|
105
|
+
|
|
106
|
+
Some spellings keep the meaning they always had. A keyword does not start a name, so `true:1`, `this:1` and `typeof:1` are syntax errors as before, while a word acorn reads as a name, such as `let` or `async`, does start one. A first segment holding a non-ASCII character or a `\u` escape does not join, and neither does a colon followed by a non-ASCII character, so `Вопрос:1` and `Q1:Ответ` are labels; so is a colon with a space beside it: `Q1: 1` is the label `Q1`, under the option too. A non-ASCII character later in a segment ends the name there, and what follows it is a `SyntaxError`: `Q1:1é`.
|
|
107
|
+
|
|
108
|
+
**Where JavaScript already gives the colon a meaning**, the name gives way or is refused, and never reads silently as something else:
|
|
109
|
+
|
|
110
|
+
- **A conditional's consequent.** Between a `?` and the `:` that closes it, a name does not join at the conditional's own level, so `a?b:c` keeps its meaning. Put a colon-joined name there in parentheses, `c ? (Q1:1) : 0`; inside a call, an array or a template the consequent opens it joins as anywhere else, as it does in the test and the alternate: `Q1:1 ? f(Q2:2) : Q3:3`. Without the parentheses the leftover colon is a `SyntaxError` at its own position, whose message names the fix — except when the `:` that closes the conditional starts a line of its own, where it is acorn's plain `Unexpected token`.
|
|
111
|
+
- **An object key.** `{Q1:1}` would be `{Q1: 1}` to JavaScript and the shorthand `{'Q1:1': Q1:1}` here, so a colon-joined key is a `SyntaxError` naming both fixes. Quote a colon-named key, `{'Q1:1': v}`. A value, a computed key and a spread join as usual: `({a: Q1:1})`, `({[Q1:1]: 2})`, `({...o, k: Q1:1})`. So under the option a compact literal or pattern — `({a:1})`, `let {a:b} = o` — needs a space after the key's colon.
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
const ctx = { c: true, 'Q1:1': 5 };
|
|
115
|
+
|
|
116
|
+
service.simpleEval('c ? (Q1:1) : 0', ctx); // 5
|
|
117
|
+
service.simpleEval('c ? Q1:1 : 0', ctx); // throws SyntaxError: Unexpected token: a colon-joined
|
|
118
|
+
// name in the consequent of a conditional needs
|
|
119
|
+
// parentheses: (Q1:1) (1:9)
|
|
120
|
+
service.simpleEval("({ 'Q1:1': 2 })['Q1:1']"); // 2 - a colon-named key is quoted
|
|
121
|
+
service.simpleEval('({a:1}).a'); // throws SyntaxError - write ({a: 1})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Read events and dependencies stay dotted.** A colon-joined name is one segment of a `path`: reading `obj.Q2:3` reports the `key` `Q2:3` and the `path` `obj.Q2:3`, and `createDependencyTracker()` records `obj.Q2:3`. Split a path on `.`, never on `:`.
|
|
125
|
+
|
|
81
126
|
## Options
|
|
82
127
|
|
|
83
128
|
### Per-node timing
|