01The problem
A production CRM let admins run their own scripts against its data. The Node.js vm sandbox it used could be escaped through the constructor chain, giving a script full access to the server, and the usual fix (isolated-vm) would not compile on the deployed Node version.
02What I did
Reproduced the escape first, then built a dependency-free hardened sandbox: a locked-down context, pinned constructors, a data round-trip that keeps values like dates intact, and an SSRF guard that stops scripts reaching internal or cloud-metadata addresses. Wrote tests that prove the naive pattern is exploitable and the hardened one is not, and documented the limits plainly.
03Why it was needed
The Node.js CRM lets staff attach small JavaScript "App Scripts" to a page and run them by hand or on a schedule, with missed runs caught up after downtime. Running other people's code inside your server is exactly where things go wrong, so the runner had to be properly contained.
04What the hardened runner does
Scripts run in a separate context with code generation from strings and WebAssembly switched off, and no host built-ins handed in. Every value passed back is rebuilt inside the sandbox, and errors are re-created there carrying only their message, so nothing from the host leaks through an object's constructor.
Scripts can query data, send email, SMS or WhatsApp, and fetch URLs. Outbound requests are checked against private, loopback, link-local (including cloud metadata) and other internal address ranges, using a small classifier written for the job after npm audit flagged the usual library. Each user needs permission to run scripts, every run is logged, and a dry-run mode swaps writes and sends for log lines so a script can be tested safely.
05The outcome
The fix shipped to production, and the reference code and write-up are public as a reusable skill for other developers and AI coding agents.
06Tools & skills
- Node.js
- Application Security
- Threat Modelling
- Testing & Verification
- Technical Writing
- AI Coding Agents
- CI/CD (GitHub Actions)
- Git