Conversation
Property initializers used as defaults were evaluated by executing them in a vm2 sandbox. This (a) runs code originating from the input .ts file, the concern raised in YousefED#628, and (b) depends on vm2, which has an unpatched sandbox-escape advisory (YousefED#631, GHSA-99p7-6v5w-7xg8). Read the literal value directly from the TypeScript AST instead, for the forms representable in a JSON Schema default: string, number (incl. negative), boolean, null, and arrays of these. Nothing is executed, so a malicious initializer yields `undefined` (and the existing "unknown initializer" warning) rather than running. Behaviour for valid literal defaults is unchanged. Adds a test fixture covering the supported forms, including single-quoted strings and negative numbers. Closes YousefED#631
domoritz
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please:
Readme.mdThis drops the
vm2dependency entirely.Why
Every scanner I point at a project that pulls this package in lights up because of
vm2— Dependabot,npm audit, our internal SCA, all of them.vm2is archived/unmaintained and the sandbox-escape advisory in #631 (GHSA-99p7-6v5w-7xg8) has no fix coming, because the maintainers concluded it's not really fixable. #635 bumped the version to quiet it down, but a version bump can't fix something that has no patched release, so it keeps coming back.Digging into why
vm2is even here: it's only used in one spot — evaluating a property's initializer to figure out thedefaultvalue:The history is kind of a loop, actually. #628 flagged that running the tool on a malicious
.tsfile could execute code (because it evals the initializer text), so #629 swappedvm→vm2to sandbox it harder... and then #631 pointed outvm2itself is the vulnerable thing now. So we went from "eval is scary" to "the thing we used to make eval less scary is scary." 🙃The fix / why this way
Instead of executing the initializer in any sandbox, just read the literal value straight off the TypeScript AST (
ts.isStringLiteralLike,ts.isNumericLiteral,ts.isArrayLiteralExpression, etc). We already have the parsed node — there's no real reason to run it through a VM to find out that[1, 2, 3]is[1, 2, 3].Nice side effect: this closes #628 too. Since nothing is ever executed, a malicious initializer like
bar = (() => { /* do evil */ })()just isn't a supported literal node, so it returnsundefinedand hits the existing"unknown initializer"warning path — same as before, minus the arbitrary code execution.I deliberately kept it to the raw AST layer and did not reach for the
TypeChecker. The TypeChecker would happily resolvebar = SOME_CONSTto its value by following references across files — which sounds nice but is exactly the "reach beyond what's literally written here" behavior that made this risky in the first place, and it also can't give you array literals as values (they widen to{}).vm2didn't resolve those references either, so staying at the AST layer keeps behavior identical for valid defaults.Supported literal forms: string, number (including negatives), boolean,
null, and arrays of those — which matches what the oldvm2block accepted.Testing
Added a
default-properties-initializerfixture covering the above, including a single-quoted string and a negative number (a couple of cases a naiveJSON.parseswap would've choked on, which is partly why I went the AST route). All existing tests still pass —default-properties/annotation-defaultare unchanged, so behaviour for real defaults is the same.api.mdpicked up the new fixture automatically viayarn docs.Happy to adjust naming or split things out if you'd prefer — first PR here so lmk if I got the conventions wrong.
Closes #631
Closes #628