Harden VM context disable codegen and avoid leaking host console#1024
Open
thesmartshadow wants to merge 3 commits intovercel:mainfrom
Open
Harden VM context disable codegen and avoid leaking host console#1024thesmartshadow wants to merge 3 commits intovercel:mainfrom
thesmartshadow wants to merge 3 commits intovercel:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 28da161 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
@thesmartshadow is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Signed-off-by: thesmartshadow <firaswq12@gmail.com>
38745ab to
28da161
Compare
|
Good Job allawi :* |
Author
Good Job, Allawi 😄 |
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.
Summary
This PR hardens the
node:vmexecution context used by Workflow by:eval,new Function, etc.)consoleobject into the VM by reference (provides a VM-local console stub)Security severity (risk rating)
Recommended severity: Medium (Security Hardening / Defense-in-Depth)
Why not “Critical”?
Why still Medium?
If your threat model includes attacker-controlled workflow code, this should be treated as a security-relevant hardening change.
Classification
Category: Security hardening / sandbox policy enforcement
Affected area: VM context creation and VM globals
Attack precondition: Attacker controls (or partially controls) code executed inside the VM realm
Impact: Attack-surface expansion + cross-realm mutation (integrity / observability)
CWE mapping (best-fit)
(runtime string codegen via
eval/Functioninside the VM realm)(host
consoleobject leaked to the VM by reference)(VM realm receives references that should remain host-only)
Root cause
VM context allowed dynamic code generation
vm.createContext()was created withoutcodeGenerationrestrictions.eval("...")new Function("...")Host
consoleleaked into VM by referencevmGlobalThis.console = globalThis.console(at minimum affecting logging/telemetry integrity and developer expectations).
Fix
A) Disable VM code generation
Create the VM context with:
codeGeneration.strings = falsecodeGeneration.wasm = falseThis blocks common runtime compilation primitives inside the VM realm.
B) Avoid leaking host console references
Instead of assigning
globalThis.consoleinto the VM realm, provide a VM-local console stub.Proof / PoC (before vs after)
This PR includes a focused regression suite:
packages/core/src/vm/vm-hardening.test.ts1) PoC: block
evalandnew FunctionBefore: VM realm can evaluate string code generation
After: VM realm throws (codegen blocked)
Conceptually:
Expected behavior:
2) PoC: prevent host console mutation (cross-realm reference leak)
Before: VM can mutate host console methods by reference
After: VM uses a VM-local console stub, so host console remains untouched
Conceptually:
Expected behavior:
Test plan
Core build + full test run:
pnpm --filter @workflow/core build pnpm --filter @workflow/core test(Optional) Run only the hardening suite:
pnpm --filter @workflow/core test -- src/vm/vm-hardening.test.tsNotes / rationale
node:vmis a sandbox only that these specific primitives are now constrained.