javascript-node-security-v1
16 rules · Keryn Software Licence · rules 0.8.0 · all packs
How to read a rule
- Severity
- How bad the finding is if it is real:
errorfails a default gate,warningandinfodo not. - Confidence
- P0 exploitable as written; P1 dangerous in context; P2 a heuristic or a posture check: confirm by reading the code.
- False-positive risk
- low: an exact API or flag, so hits are almost always real; medium: the pattern is legitimate in many programs, so check each hit; high: it finds a lead to confirm, so expect benign hits.
- Edge
- The relationship the finding sits on. reaches: content or traffic gets to a thing; calls: one thing invokes another; reads: one thing reads from another; writes: one thing writes to another; sends: data leaves for another party; grants: authority is given or left unchecked; depends_on: something relies on a component it does not verify; trusts: one party believes another without evidence. The boundary it crosses, when there is one: user->prompt (untrusted input reaching a prompt); model->code (model output reaching code, a shell, a query or a page); secret->outside (a secret leaving the trusted side); supply-chain (code, models or prompts pulled in from outside).
- Taxonomy chips
- References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.
keryn.general.js.child-process-exec-dynamic
Section titled “keryn.general.js.child-process-exec-dynamic”warning javascript, typescript nodejs
child_process.exec() runs its first argument through /bin/sh (cmd.exe on Windows), and here that argument is not a constant string. Any part of it an attacker can influence becomes shell syntax. Call execFile() or spawn() with a fixed program and an argument array, or allow-list the command.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
Fix: Replace exec(cmd) with execFile(program, [arg1, arg2]) or spawn(program, args) (no shell), and validate every argument against an allow-list. If a shell is unavoidable, build the command only from constants and pass user data through the environment, never the command string.
References: https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback
keryn.general.js.child-process-module-passed
Section titled “keryn.general.js.child-process-module-passed”info javascript, typescript nodejs
The child_process module is loaded without being bound to a name: it is either required only for its side effects or handed whole to another function (a stub, a wrapper, a container). Command execution then happens through a reference that per-call checks cannot follow. Bind the functions you need by name (const { execFile } = require(‘child_process’)) so every call site stays visible.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
Fix: Import only the child_process functions the module uses, by name, at the top of the file, and review the code that receives the module object.
References: https://nodejs.org/api/child_process.html
keryn.general.js.fs-path-not-constant
Section titled “keryn.general.js.fs-path-not-constant”info javascript, typescript nodejs
A Node.js filesystem call receives a path that is not built only from constants (string literals, __dirname, import.meta.dirname, path.join/resolve over those). If any part of the path comes from a request, a message or a model, it can name files outside the intended directory (../, absolute paths). Resolve the path against a fixed base directory and check that the result stays inside it.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.
Edge inspected: reads one thing reads from another.
Fix: const full = path.resolve(BASE_DIR, name); if (!full.startsWith(BASE_DIR + path.sep)) throw new Error(‘bad path’); then pass full to the fs call. Prefer an allow-list of file names when the set is known.
References: https://nodejs.org/api/fs.html · https://nodejs.org/api/path.html#pathresolvepaths
keryn.general.js.fs-destination-not-constant
Section titled “keryn.general.js.fs-destination-not-constant”info javascript, typescript nodejs
A filesystem rename, link or symlink receives a destination path that is not constant. A fixed source path does not constrain where the operation writes. Resolve the destination against a fixed directory and verify its containment or use an allow-list.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.
Edge inspected: writes one thing writes to another.
Fix: const full = path.resolve(BASE_DIR, name); if (!full.startsWith(BASE_DIR + path.sep)) throw new Error(‘bad path’); then pass full to the fs call. Prefer an allow-list of file names when the set is known.
References: https://nodejs.org/api/fs.html · https://nodejs.org/api/path.html#pathresolvepaths
keryn.general.js.require-not-constant
Section titled “keryn.general.js.require-not-constant”warning javascript, typescript nodejs
require() is called with a module name that is not a constant. Whoever controls that value chooses which file Node loads and runs (any .js file on disk, a planted node_modules package). Map the allowed names to fixed require() calls instead.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: depends_on something relies on a component it does not verify; it crosses the supply-chain boundary (code, models or prompts pulled in from outside).
Fix: Replace require(name) with a lookup in a fixed table, e.g. const PLUGINS = { csv: () => require(‘./csv’), json: () => require(‘./json’) }; PLUGINS[name]?.() after checking Object.hasOwn(PLUGINS, name).
References: https://nodejs.org/api/modules.html#requireid
keryn.general.js.regexp-from-variable
Section titled “keryn.general.js.regexp-from-variable”info javascript, typescript nodejs
A RegExp is compiled from a value that is not a constant. If that value comes from a user or a model it can be a catastrophic pattern (nested quantifiers) that blocks the event loop, or change what the match accepts. Escape it before building the pattern, or match the literal text with includes()/indexOf().
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.
Edge inspected: calls one thing invokes another.
Fix: Escape untrusted text first (RegExp.escape(text), lodash _.escapeRegExp, escape-string-regexp) or avoid regular expressions for literal matching. When a user must supply a pattern, run it with a linear-time engine such as re2.
References: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp · https://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS
keryn.general.js.regex-catastrophic-backtracking
Section titled “keryn.general.js.regex-catastrophic-backtracking”warning javascript, typescript nodejs
This regular expression nests a repeated group inside another repetition (for example (x+x+)+y). On an input that almost matches, the backtracking engine tries exponentially many ways to split it and blocks the Node.js event loop. Rewrite it without nested quantifiers or anchor and bound the repeated parts.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: calls one thing invokes another.
Fix: Remove the ambiguity: make the inner and outer repetitions consume different characters, use a possessive-like rewrite with lookahead and back-reference, or check the input length first. For untrusted input, use re2.
References: https://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS · https://nodejs.org/en/learn/asynchronous-work/dont-block-the-event-loop
keryn.general.js.buffer-noassert
Section titled “keryn.general.js.buffer-noassert”warning javascript, typescript nodejs
A Buffer read or write method is called with noAssert set to true, which skips the offset bounds check: an out-of-range offset reads or writes memory outside the buffer on the Node.js versions that honour the flag. Drop the argument and validate the offset.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another.
Fix: Call buf.readUInt32LE(offset) / buf.writeUInt32LE(value, offset) without the third/second boolean, check offset + size <= buf.length yourself, and upgrade to a Node.js release where the flag is gone.
References: https://nodejs.org/docs/latest-v8.x/api/buffer.html#buffer_buf_readuint8_offset_noassert
keryn.general.js.buffer-constructor-non-literal
Section titled “keryn.general.js.buffer-constructor-non-literal”warning javascript, typescript nodejs
new Buffer(x) with a non-literal argument: when x is a number the deprecated constructor returns uninitialised memory (old releases) that can leak earlier data, and when it is attacker-chosen the caller cannot tell which overload runs. Use Buffer.from(data) or Buffer.alloc(size).
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: writes one thing writes to another.
Fix: Replace new Buffer(value) with Buffer.from(value) for data and Buffer.alloc(size) for zero-filled storage.
References: https://nodejs.org/api/buffer.html#new-bufferarray · https://nodejs.org/api/buffer.html#new-bufferarray
keryn.general.js.template-escape-markup-disabled
Section titled “keryn.general.js.template-escape-markup-disabled”warning javascript, typescript nodejs, mustache
escapeMarkup is set to false on a template engine, so interpolated values are written into the HTML unescaped and any value that carries markup becomes cross-site scripting. Keep escaping on and mark only vetted fragments as raw.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
Fix: Remove the assignment (escaping is the default), and render untrusted values with the escaping tag ({{ }}), never the raw one.
References: https://github.com/janl/mustache.js#variables
keryn.general.js.express-csrf-before-method-override
Section titled “keryn.general.js.express-csrf-before-method-override”warning javascript, typescript nodejs, express
express.csrf() is installed before express.methodOverride(). The CSRF check sees the original verb (a GET or HEAD is exempt), and the override middleware turns that request into a POST, PUT or DELETE afterwards, bypassing the token check. Register methodOverride() first.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another.
Fix: app.use(express.methodOverride()) must come before app.use(express.csrf()).
References: https://github.com/expressjs/method-override#readme
keryn.general.js.secret-compared-non-constant-time
Section titled “keryn.general.js.secret-compared-non-constant-time”info javascript, typescript nodejs
A secret-looking variable (password, secret, token, apiKey, auth, hash …) is compared with ==/===. String comparison stops at the first differing character, so the response time leaks how much of a guess is right. Compare digests with crypto.timingSafeEqual().
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.
Edge inspected: sends data leaves for another party; it crosses the secret->outside boundary (a secret leaving the trusted side).
Fix: Hash both values to the same length (crypto.createHash(‘sha256’)) and compare with crypto.timingSafeEqual(a, b); for passwords use a password-hash verify function (bcrypt.compare, argon2.verify).
References: https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
keryn.general.js.crypto-pseudo-random-bytes
Section titled “keryn.general.js.crypto-pseudo-random-bytes”warning javascript, typescript nodejs
crypto.pseudoRandomBytes() is a deprecated alias whose output was never meant to be cryptographically strong. Use crypto.randomBytes() (or crypto.randomUUID / getRandomValues) for keys, tokens and nonces.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: sends data leaves for another party.
Fix: Replace crypto.pseudoRandomBytes(n) with crypto.randomBytes(n).
References: https://nodejs.org/api/deprecations.html#DEP0115
keryn.general.js.plain-object-dynamic-key-write
Section titled “keryn.general.js.plain-object-dynamic-key-write”info javascript, typescript nodejs
An object literal is used as a dictionary and written with a key held in a variable. If the key comes from input, “__proto__” replaces the object’s prototype and “constructor”, “toString” or “hasOwnProperty” shadow inherited members, so later reads and checks see attacker-chosen values. Use a Map, or an object from Object.create(null), and reject __proto__ / constructor / prototype keys.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk high: it finds a lead to confirm, so expect benign hits.
Edge inspected: writes one thing writes to another.
Fix: const table = new Map(); table.set(key, value); or const table = Object.create(null); and refuse keys equal to “__proto__”, “constructor” or “prototype” before writing.
References: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto · https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
keryn.general.js.trojan-source-bidi-control
Section titled “keryn.general.js.trojan-source-bidi-control”error javascript, typescript nodejs
The source contains a Unicode bidirectional embedding, override or isolate control (U+202A-U+202E, U+2066-U+2069). It reorders how the code is displayed, so a reviewer can read a comment or string where the parser sees code (Trojan Source, CVE-2021-42574). The directional marks U+200E, U+200F and U+061C cannot reorder code and are normal in Arabic, Hebrew, Persian and Urdu text: not reported. Remove it; write the code point as an escape () where a string truly needs it.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
Fix: Delete the character or replace it with its escape sequence, and add a pre-commit or CI check that rejects these code points in source files.
References: https://trojansource.codes/ · https://www.unicode.org/reports/tr9/
keryn.general.js.invisible-hangul-filler
Section titled “keryn.general.js.invisible-hangul-filler”error javascript, typescript nodejs
The source contains an invisible Hangul filler character (U+3164 or U+FFA0). JavaScript accepts it as an identifier letter, so an identifier, argument or array element can be hidden in plain sight (a variable that looks like whitespace). Remove it; use an escape if a string really needs it.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: calls one thing invokes another; it crosses the model->code boundary (model output reaching code, a shell, a query or a page).
Fix: Delete the character, or write it as ㅤ / ᅠ inside a string literal if it is data, and reject the code points in CI.
References: https://www.unicode.org/charts/PDF/U3130.pdf · https://certitude.consulting/blog/en/invisible-backdoor/