# javascript-node-security-v1

> javascript-node-security-v1: 16 Keryn rules for javascript, typescript (2 error, 8 warning, 6 info).

Source: https://keryn.dev/rules/javascript-node-security-v1/

16 rules · Keryn Software Licence · rules 0.8.0 · [all packs](https://keryn.dev/rules/)

**How to read a rule**

- **Severity**: How bad the finding is if it is real: `error` fails a default gate, `warning` and `info` do 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

`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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

[CWE-78](https://keryn.dev/taxonomies/cwe/#cwe-78-os-command-injection) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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](https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback)

## 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 &#123; execFile &#125; = 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

[CWE-78](https://keryn.dev/taxonomies/cwe/#cwe-78-os-command-injection) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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](https://nodejs.org/api/child_process.html)

## 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](https://keryn.dev/docs/edges/edge-kinds/#reads) one thing reads from another.

[CWE-22](https://keryn.dev/taxonomies/cwe/#cwe-22-path-traversal) [CWE-73](https://keryn.dev/taxonomies/cwe/#cwe-73-external-control-of-file-name-or-path) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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/fs.html) · [https://nodejs.org/api/path.html#pathresolvepaths](https://nodejs.org/api/path.html#pathresolvepaths)

## 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](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-22](https://keryn.dev/taxonomies/cwe/#cwe-22-path-traversal) [CWE-73](https://keryn.dev/taxonomies/cwe/#cwe-73-external-control-of-file-name-or-path) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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/fs.html) · [https://nodejs.org/api/path.html#pathresolvepaths](https://nodejs.org/api/path.html#pathresolvepaths)

## 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](https://keryn.dev/docs/edges/edge-kinds/#depends-on) something relies on a component it does not verify; it crosses the [`supply-chain`](https://keryn.dev/docs/edges/trust-boundaries/#supply-chain) boundary (code, models or prompts pulled in from outside).

[CWE-706](https://keryn.dev/rules/?cwe=CWE-706) [CWE-829](https://keryn.dev/taxonomies/cwe/#cwe-829-inclusion-of-functionality-from-untrusted-control-sphere) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Replace require(name) with a lookup in a fixed table, e.g. const PLUGINS = &#123; csv: () =&gt; require('./csv'), json: () =&gt; require('./json') &#125;; PLUGINS[name]?.() after checking Object.hasOwn(PLUGINS, name).

**References:** [https://nodejs.org/api/modules.html#requireid](https://nodejs.org/api/modules.html#requireid)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-1333](https://keryn.dev/rules/?cwe=CWE-1333) [CWE-625](https://keryn.dev/rules/?cwe=CWE-625) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) · [https://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS](https://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-1333](https://keryn.dev/rules/?cwe=CWE-1333) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS) · [https://nodejs.org/en/learn/asynchronous-work/dont-block-the-event-loop](https://nodejs.org/en/learn/asynchronous-work/dont-block-the-event-loop)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-125](https://keryn.dev/rules/?cwe=CWE-125) [CWE-787](https://keryn.dev/rules/?cwe=CWE-787) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Call buf.readUInt32LE(offset) / buf.writeUInt32LE(value, offset) without the third/second boolean, check offset + size &lt;= 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](https://nodejs.org/docs/latest-v8.x/api/buffer.html#buffer_buf_readuint8_offset_noassert)

## 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](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-908](https://keryn.dev/rules/?cwe=CWE-908) [CWE-665](https://keryn.dev/rules/?cwe=CWE-665) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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) · [https://nodejs.org/api/buffer.html#new-bufferarray](https://nodejs.org/api/buffer.html#new-bufferarray)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

[CWE-79](https://keryn.dev/taxonomies/cwe/#cwe-79-cross-site-scripting) [CWE-116](https://keryn.dev/taxonomies/cwe/#cwe-116-improper-encoding-or-escaping-of-output) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Remove the assignment (escaping is the default), and render untrusted values with the escaping tag (&#123;&#123; &#125;&#125;), never the raw one.

**References:** [https://github.com/janl/mustache.js#variables](https://github.com/janl/mustache.js#variables)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another.

[CWE-352](https://keryn.dev/rules/?cwe=CWE-352) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** app.use(express.methodOverride()) must come before app.use(express.csrf()).

**References:** [https://github.com/expressjs/method-override#readme](https://github.com/expressjs/method-override#readme)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party; it crosses the [`secret->outside`](https://keryn.dev/docs/edges/trust-boundaries/#secret-to-outside) boundary (a secret leaving the trusted side).

[CWE-208](https://keryn.dev/rules/?cwe=CWE-208) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**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](https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b)

## 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](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party.

[CWE-338](https://keryn.dev/rules/?cwe=CWE-338) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure)

**Fix:** Replace crypto.pseudoRandomBytes(n) with crypto.randomBytes(n).

**References:** [https://nodejs.org/api/deprecations.html#DEP0115](https://nodejs.org/api/deprecations.html#DEP0115)

## 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](https://keryn.dev/docs/edges/edge-kinds/#writes) one thing writes to another.

[CWE-1321](https://keryn.dev/rules/?cwe=CWE-1321) [CWE-915](https://keryn.dev/taxonomies/cwe/#cwe-915) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**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/Object/proto) · [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

[CWE-451](https://keryn.dev/rules/?cwe=CWE-451) [CWE-1007](https://keryn.dev/rules/?cwe=CWE-1007) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain)

**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://trojansource.codes/) · [https://www.unicode.org/reports/tr9/](https://www.unicode.org/reports/tr9/)

## 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](https://keryn.dev/docs/edges/edge-kinds/#calls) one thing invokes another; it crosses the [`model->code`](https://keryn.dev/docs/edges/trust-boundaries/#model-to-code) boundary (model output reaching code, a shell, a query or a page).

[CWE-1007](https://keryn.dev/rules/?cwe=CWE-1007) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain)

**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://www.unicode.org/charts/PDF/U3130.pdf) · [https://certitude.consulting/blog/en/invisible-backdoor/](https://certitude.consulting/blog/en/invisible-backdoor/)
