Summary The AgentScript preset of @enclave-vm/ast is the static layer of the sandbox: it decides which scripts are run at all
Description
The AgentScript preset of @enclave-vm/ast is the static layer of the sandbox: it decides which scripts are run at all. Several of its rules matched one way of writing a construct and missed the others, so a script could pass validation while using a global, a property or a call the preset is documented to refuse. @enclave-vm/core and @enclave-vm/browser validate with this preset.
Details
All references are to v2.18.0.
- Scope confusion.
UnknownGlobalRuleand the identifier transform kept one set of declared names for the whole program. A declaration in a nested block, an arrow-function parameter or a catch clause made the same name count as a local variable everywhere, so a use of the real global of that name elsewhere in the script was neither reported nor rewritten. - Write targets were not checked. Identifiers in assignment targets, destructuring patterns and
for…ofheads are visited by the parser's walker as patterns, not as identifiers, and no rule looked at them. A script could assign to an allowed global or to a reserved runtime name. - Syntax nobody listed. Each rule named what it refused.
thisused as a value, classes without methods,new.targetanddebuggerwere on no list and were accepted, although the language description saysthisis blocked. - Reflection by property name. The legacy accessor methods were refused in destructuring but not as members; the prototype and descriptor functions of
Objectwere matched only as a direct call onObject, so an alias, a literal key,.callor passing the method as a value passed; an object literal with a__proto__key was accepted. - Indirect calls. The rules that require a literal tool name for
callTooland forbid callbacks forJSONonly saw a direct call. An alias,.call, a tagged template, a sequence callee or passing the function as a callback took the call out of their sight; an aliasedcallToolwith a computed name reached the tool handler. - Regular expressions from strings.
match,matchAllandsearchcompile a string argument into a regular expression, which the regex rules did not treat as one. - Loop counters. The counter that enforces
maxIterationswas a variable in the script's own scope with a predictable name.
The fix: a syntax allowlist (AllowedSyntaxRule), lexical scope analysis shared by the rule and the transform (checked against eslint-scope on 350,000 generated programs), write targets treated as references, property names refused in every statically resolvable spelling, callTool and JSON restricted to direct use, and counter names a script cannot mention.
Proof of concept
No reproduction is given here. Regression tests, in the private repository agentfront/enclave-security-tests: ATK-SYNTAX, ATK-SCOPE, ATK-GWRITE, ATK-PCHAIN, ATK-REFL, ATK-CTGT, ATK-JSONCB, ATK-RXSTR and ATK-LCTR in specs/ast/agentscript.syntax-hardening.spec.ts, and the case folders ast-*.
Impact
The static layer could be passed by scripts it was meant to refuse. On its own this gives a script names and operations the runtime layers then have to stop; together with the runtime defects fixed in the same release (see the advisories for @enclave-vm/core) it was part of a full sandbox escape. Applications that use @enclave-vm/ast as their only control are affected directly.
Patches
Fixed in 2.19.0.
Workarounds
None. Do not rely on validation alone for scripts from an untrusted source.