4 vulnerabilities, 4 fixes, one lab run. Our Node.js v22.13.1 lab reproduced four common mistakes, SQL injection, path traversal, prototype pollution and command injection, then blocked all four while normal inputs kept working. All four are bugs in application code, so npm audit will not report them.

Our lab: 4 of 4 reproduced, 4 of 4 blocked

The lab ran on 2026-11-06 with Node.js v22.13.1. The SQL attack x' OR '1'='1 returned 3 rows unsafe and 0 fixed, while a normal lookup returned 1 row on both. The traversal input ../secret.env reached the secret file unsafe and was refused fixed. The merge payload {"__proto__": {"isAdmin": true}} made ordinary objects read isAdmin as true unsafe and false fixed. The command input hello.txt; touch <tmp>/injected.txt ran the second command unsafe and nothing extra fixed. Totals: reproduced 4 of 4, blocked 4 of 4, normal inputs unchanged 2 of 2.

Fix 1: SQL injection, use placeholders

A template string puts user text inside the statement, so a quote closes the string literal and OR '1'='1 becomes part of the condition. The fix is a placeholder: db.prepare('SELECT id, email FROM users WHERE email = ?').all(email). SQLite compiles the statement before the value exists, so the fixed lookup returned 0 rows.

Fix 2: path traversal, resolve and check the prefix

path.join normalizes its result, and normalizing resolves .. segments, so join(pub, '../secret.env') is the parent folder's secret.env. The fix resolves to an absolute path and checks the prefix:

const file = path.resolve(PUBLIC_DIR, req.query.name); if (!file.startsWith(PUBLIC_DIR + path.sep)) return res.status(404).end(); 

Only the prefix check keeps an absolute input such as /etc/hosts inside the folder. The + path.sep stops a sibling folder named public-old from passing.

Fix 3: prototype pollution, validate before merging

JSON.parse('{"__proto__":{"isAdmin":true}}') creates an object with an own property named __proto__; parsing changes no prototype. The damage happens in a naive deep merge: when the key is "__proto__", reading t[k] returns Object.prototype, and the recursive call writes isAdmin = true onto it. After one merge call, objects created later reported isAdmin as true.

The production fix is an allow-list schema checked before anything is written: reject unknown keys, reject wrong types, recurse only into approved plain-object fields. __proto__ and constructor are rejected because they are not keys of the schema.

Fix 4: command injection, execFile with an argument array

On macOS, execSync uses /bin/sh, and shell parsing turns ; into a command separator, so the lab input ran the second command. The fix is execFileSync('ls', ['--', path.join(dir, name)]), which starts ls directly with an argument array and no shell. The whole name arrives as one argument, so nothing else ran.

Our take

The pattern behind all four is the same: request data reached an interpreter as code instead of as a value. Keep them apart with placeholders, a prefix check, a schema check, and an argument array.

Read the full article with the lab table and the allow-list merge code on System Design Simple: https://systemdesignsimple.com/nodejs-security-common-vulnerabilities/