Node.js
Node.js is a V8-based JavaScript runtime. For Node.js security, the key fact is that every module it loads, npm packages included, runs with full privileges.
Also known as NodeJS, Node JS, Node.js runtime, Node.js security, Node.js permission model
Node.js is an open source JavaScript runtime, also written NodeJS or Node, that executes code outside the browser on Google's V8 engine and an event loop built on libuv. For Node.js security, the defining fact is its trust model: every module a process loads, including every npm dependency, runs with the full privileges of the user who started it.
Node.js draws no line between your code and your dependencies' code. They share one heap, one set of environment variables, and one set of operating system privileges. The project's own threat model says a malicious package can never be a Node.js vulnerability, because the runtime trusts every line of code it is asked to run. We think that is the right call for a runtime and the wrong mental model for the teams running it. Node.js security is mostly a question of which code gets into the process, and when. The opt-in permission model is a seat belt for trusted code, not a cage for hostile code, and it does nothing during npm install, which is where most npm malware runs.
How Node.js runs code
#Node.js is a C++ program that embeds V8 to execute JavaScript and libuv to perform asynchronous I/O. By default, one thread runs your JavaScript. The event loop hands file, socket, and timer work to libuv and runs your callback when the result comes back. In the project's own words, "A Node.js app runs in a single process, without creating a new thread for every request."
Built-in modules such as node:fs, node:net, and node:child_process are thin JavaScript wrappers over C++ bindings that make system calls. Whatever the operating system lets the current user do, those modules can do.
Code enters the process through the module loader. When a file calls require('evil'), Node.js looks for a node_modules directory in the current folder, then in every parent folder up to the filesystem root:
$ cd /srv/app && node -e "console.log(module.paths)"
[ '/srv/app/node_modules', '/srv/node_modules', '/node_modules' ]The loader then evaluates the file in the same V8 isolate as your application. Node.js has no per-package scope for capabilities. A dependency four levels deep gets the same require('node:child_process') your HTTP server gets. That design keeps npm's small-module culture cheap: importing a package costs a function call, not a process boundary. It is also why one compromised package anywhere in the tree owns the whole process.
Is Node.js secure? What its threat model trusts
#Node.js is built to be secure against untrusted input, not against untrusted code. The runtime treats data from network peers as untrusted, and a bug that lets such data escalate into code execution is a vulnerability. Everything else is trusted. The Node.js threat model lists "The code it is asked to run, including JavaScript, WASM and native code" and names "all dependencies installed from the npm registry" as an example. It also states that this code "inherits all the privileges of the execution user." Then it draws the consequence:
"Code is trusted by Node.js. Therefore any scenario that requires a malicious third-party module cannot result in a vulnerability in Node.js." (Node.js threat model, SECURITY.md)
That split decides what gets a CVE. On October 21, 2026, Node.js 26.12.1 shipped fixes for 10 CVEs, including TLS IP address normalization and a Brotli decoder bug, according to the Node.js 26 changelog. A malicious package gets no CVE at all, because under the threat model the runtime is working as designed. Malware does not get a CVE. Scanning dependencies against vulnerability databases therefore misses most supply chain attacks on Node.js.
What a dependency can do the moment it loads
#A Node.js dependency can read files, spawn shells, open sockets, and read secrets as soon as it is loaded. We wrote a minimal stand-in for a malicious dependency to show this. It does nothing exotic. It only calls built-in modules:
// What a malicious dependency does the moment it is require()d.
const cp = require('node:child_process');
const fs = require('node:fs');
const os = require('node:os');
const tryIt = (label, fn) => {
try { fn(); console.log('ALLOWED', label); }
catch (e) { console.log('DENIED ', label, e.code ?? e.message, e.permission ?? ''); }
};
tryIt('read ~/.npmrc', () => fs.readFileSync(`${os.homedir()}/.npmrc`));
tryIt('spawn a shell', () => cp.execSync('id'));
tryIt('write a file', () => fs.writeFileSync(`${__dirname}/dropped.sh`, '#!/bin/sh'));
tryIt('read NPM_TOKEN', () => { if (!process.env.NPM_TOKEN) throw new Error('unset'); });
require('node:net').connect(9, '127.0.0.1')
.on('error', e => console.log(e.code === 'ERR_ACCESS_DENIED' ? 'DENIED ' : 'ALLOWED', 'open a socket', e.code));The application is one line, require('evil'). Run normally on Node.js 22.23.4, every operation succeeds. The socket line reports ECONNREFUSED only because nothing listens on port 9; the connection attempt itself was allowed.
$ node app.js
ALLOWED read ~/.npmrc
ALLOWED spawn a shell
ALLOWED write a file
ALLOWED read NPM_TOKEN
ALLOWED open a socket ECONNREFUSEDReal payloads look like this. In the axios compromise on March 31, 2026, the attacker published axios@1.14.1 and axios@0.30.4 with one new dependency, plain-crypto-js@4.2.1. Its dropper, a 4,209-byte setup.js, hid 18 strings behind reversed Base64 and an XOR cipher. The first three decoded strings were child_process, os, and fs. Those three built-in modules were enough to detect the platform, download a second stage with curl, launch a remote access trojan on macOS, and then delete setup.js and swap in a clean package.json so the installed folder looked like an ordinary copy of crypto-js.
What is the Node.js permission model?
#The Node.js permission model is an opt-in mode, enabled with --permission, that denies a process access to sensitive resources unless each one is granted by a flag. It was added as experimental in v20.0.0 and marked stable in v23.5.0 and v22.13.0, according to the permissions documentation. Network access joined the model in v25.0.0 with --allow-net, and foreign function interface access in v26.1.0 with --allow-ffi. A denied call throws an error with code ERR_ACCESS_DENIED. Code can check its own grants with process.permission.has().
Here is the same application with the permission model on and read access granted only to the project folder:
$ node --permission --allow-fs-read=. app.js
DENIED read ~/.npmrc ERR_ACCESS_DENIED FileSystemRead
DENIED spawn a shell ERR_ACCESS_DENIED ChildProcess
DENIED write a file ERR_ACCESS_DENIED FileSystemWrite
ALLOWED read NPM_TOKEN
ALLOWED open a socket ECONNREFUSEDThree operations are now denied. Two are not. The permission model has no scope for environment variables, so process.env.NPM_TOKEN stays readable on every Node.js version. The socket stays open on Node.js 22 because network permission only exists from v25.0.0 onward. On Node.js 25 and 26, the documentation says the same connection throws ERR_ACCESS_DENIED unless --allow-net is passed. That leaves a malicious dependency on a Node.js 22 or 24 service able to read your tokens and send them anywhere, even under --permission.
As of November 2026, the model gates these capabilities:
| Capability | Gated by --permission? | Grant flag | Since |
|---|---|---|---|
| File system reads and writes | Yes | --allow-fs-read, --allow-fs-write | v20.0.0 |
| Child processes | Yes | --allow-child-process | v20.0.0 |
| Worker threads | Yes | --allow-worker | v20.0.0 |
| Native addons | Yes | --allow-addons | v21.6.0, v20.12.0 |
| WASI | Yes | --allow-wasi | v22.3.0, v20.16.0 |
| Network | Yes, on v25.0.0 and later | --allow-net | v25.0.0 |
| FFI | Yes | --allow-ffi | v26.1.0 |
| Environment variables | No | None | Never gated |
| Already-open file descriptors | No, a documented bypass | None | Not applicable |
Grants can also live in a config file under a permission key, which turns the model on automatically. An audit mode, --permission-audit, reports violations through node:diagnostics_channel without blocking them, which makes it practical to discover what an existing service actually uses before enforcing.
Figure 1 shows a service started with node --permission --allow-child-process app.js. Your app.js, express, body-parser, a utility package, and a malicious package four levels deep all run in the same process and the same V8 isolate. The gates for file system, child processes, workers, native addons and FFI, WASI, and network (v25 and later) sit on the process boundary, not between packages. Because the operator granted --allow-child-process for the application's own needs, the child process gate is open for every package, including the malicious one. process.env sits inside the process, shared by all packages and never gated.
Can the Node.js permission model stop a malicious npm package?
#The Node.js permission model cannot reliably stop a malicious npm package, and its own documentation says so: "This feature does not protect against malicious code." The model reduces the blast radius of mistakes in trusted code. Three structural limits keep it from being more than that.
Grants belong to the process, not the package. If your service shells out to git or writes uploads to disk, you pass --allow-child-process or --allow-fs-write, and every dependency inherits that grant. Node.js itself warns about it every time the flag is used: "SecurityWarning: The flag --allow-child-process must be used with extreme caution. It could invalidate the permission model." The model cannot express "my code may spawn processes and my dependencies may not."
Install scripts run outside it. When npm installs a package with a postinstall script, it spawns a shell, and that shell starts a fresh node process with no --permission flag. You can force the flag into every child with NODE_OPTIONS, but npm itself then needs the same grants a dropper needs. We tried it on Node.js 22.23.4 with its bundled npm 10.9.9 and a local package whose postinstall runs id -un through child_process. SecurityWarning lines are omitted from the output:
$ NODE_OPTIONS="--permission --allow-fs-read=*" npm install ../dep
npm error code ERR_ACCESS_DENIED
npm error Access to this API has been restricted. Use --allow-fs-write to manage permissions.
$ NODE_OPTIONS="--permission --allow-fs-read=* --allow-fs-write=* --allow-child-process" npm install ../dep
postinstall ran as root perm= true
added 1 package in 259msThe first run fails because npm cannot write node_modules. The second run gives npm what it needs, and the install script runs under the permission model with every capability it wanted. At install time the permission model is either broken or decorative.
Same-process code is out of scope. The threat model says the permission model "is not a sandbox against malicious same-process code," and bypasses keep getting patched. The Node.js 26.5.1 security release on July 29, 2026 fixed three permission model CVEs, including CVE-2026-58043, rated High. The 26.12.1 release on October 21 fixed two more, CVE-2026-106071 and CVE-2026-106073. Real isolation from hostile code needs an operating system boundary: a container, a VM, or a separate user account acting as a sandbox.
The Node.js Learn guide is more generous. It says the permission model "can help contain the impact of malicious or compromised dependencies." That is true for lazy malware that assumes ambient authority, as our demo showed. It is not true for a payload written with the model in mind, and the API reference and the threat model both say so. We would rather teams plan around the stricter statement.
Figure 2 compares the two phases. At install time, npm install runs a dependency's postinstall script through sh -c "node setup.js", which starts a new node process with no --permission flag and the installing user's full privileges: files, shell, network, tokens in ~/.npmrc, and environment variables. At run time, node --permission loads the same package with require('evil'); file system access outside the grants, child processes, and network access on v25 and later throw ERR_ACCESS_DENIED, while process.env and any capability granted to the process stay available.
Where Node.js security breaks: install time
#Install time is where most npm malware executes. npm runs each dependency's preinstall, install, and postinstall install scripts through a shell as the installing user, before any application code loads and before any runtime flag applies. That is how the axios dropper ran.
Package managers have started to fix the default. npm v12, generally available on July 8, 2026, ships with allowScripts off, so dependency install scripts, including the implicit node-gyp rebuild triggered by a binding.gyp file, do not run unless approved. pnpm 10 blocked lifecycle scripts by default in January 2025. Default-on install scripts were a design mistake, and these releases correct it.
Node.js users mostly have not received that fix yet. Node.js bundles npm, and the Release Working Group decided not to land npm 12 on Node.js 22, 24, or 26, according to nodejs/Release issue #1161. As of November 2026, Node.js 26.13.0, the Active LTS release since October 28, 2026, still bundles npm 11.20.0. On every supported LTS line, npm install as shipped still runs dependency install scripts by default. npm 12 is targeted at Node.js 27, which becomes Current in April 2027.
Teams do not have to wait. Running npm install -g npm@12, setting npm config set ignore-scripts true, or switching to pnpm turns scripts off today. The cost is real: native modules such as sharp, better-sqlite3, and bcrypt, and binary downloaders such as Playwright, Puppeteer, and Electron need explicit approval. Under npm v12 a skipped native build does not fail the install. It fails later, at runtime, when code loads a module that was never compiled.
Script blocking still leaves gaps. Code that runs on require() executes at runtime, as our first demo showed. Tools fetched with npx resolve their dependencies fresh against the registry and never appear in your lockfile, which is how the axios compromise reached at least one CI pipeline through a CLI run with npx, as we documented in the hidden blast radius of the axios compromise. Compromised maintainers can also publish through legitimate pipelines with valid provenance. After the social engineering campaign against Node.js maintainers, Express TC member Wes Todd warned that OIDC publishing "does not protect against a fully compromised machine."
The runtime does not tell you which packages use which capabilities, so that inventory has to come from analyzing the packages themselves. Socket reads the code a package actually ships. It raises Shell access when a package uses child_process APIs such as exec or spawn, and Environment variable access when it reads process.env. That is the per-package view of capabilities that Node.js grants only per process.
| Control | What it stops | What it misses | Cost |
|---|---|---|---|
| node --permission | Unintended file, child process, and (v25+) network access at runtime | Install scripts, environment variables, any grant the process needs, determined same-process code | Flag lists to maintain; one grant applies to every dependency |
| Install scripts off (npm v12, pnpm 10+, ignore-scripts) | Payloads in preinstall, install, postinstall, and implicit node-gyp builds | Code that runs on require(), npx resolution, malicious logic in normal code paths | Native modules and binary downloaders need an allowlist |
| OS sandbox (container, VM, separate user) | Damage outside the sandbox's files, network, and credentials | Everything inside it, including CI secrets and tokens in the environment | Operational overhead; rare on developer laptops |
| Pre-install package analysis | Known-malicious and suspicious packages before they reach node_modules | Brand-new payloads in the minutes before analysis completes | Another gate in the pipeline; alerts need triage |
Our verdict: turn install scripts off everywhere now, because it is cheap and it removes the most common execution path. Run production services under --permission with the narrowest grants, but treat it as a guardrail against your own mistakes. Only the last two rows address hostile code. Analyze what a package contains before it is installed, and isolate the machines that install and run untrusted code.
Node.js release lines and security support
#Security fixes only reach supported release lines. As of November 2026, the Node.js release schedule looks like this:
| Release line | Status (November 2026) | End of life |
|---|---|---|
| 26.x Lithium | Active LTS since October 28, 2026 | April 30, 2029 |
| 24.x Krypton | Maintenance LTS since October 20, 2026 | April 30, 2028 |
| 22.x Jod | Maintenance LTS | April 30, 2027 |
| 25.x | End of life | June 1, 2026 |
| 20.x Iron | End of life | April 30, 2026 |
Node.js 20 stopped receiving security fixes on April 30, 2026, so services still on it are running end-of-life dependencies at the base of the stack. The schedule is also changing. Starting with Node.js 27, the project moves to one major release per year, in April, and every release becomes LTS. Version numbers will track the year of first release, so 27.0.0 arrives in 2027.
The vulnerability intake behind those releases is under strain. Node.js paused bug bounty rewards in April 2026 after Internet Bug Bounty funding stopped, and the security team received 65 HackerOne reports in March 2026 alone, well above its historical baseline, as we reported in our coverage of the proposal to move lower-severity reports into a public workflow. Many of those reports were invalid, duplicated, or outside the threat model. A report that depends on a malicious dependency is closed as out of scope, which is correct and also means nobody upstream is assigned that risk.
The missing boundary is the package
#Node.js grants capabilities to processes, but supply chain risk arrives in packages. Per-package policy does exist outside core. LavaMoat runs Node.js programs with SES compartments and a policy file that limits which platform APIs each package can reach. The trade-off is a policy to maintain for every dependency and compatibility work for code that touches globals. No mainstream runtime ships package-level boundaries by default. Until one does, the last point where a decision can be made about a single package, rather than a whole process, is before that package is installed.
