# general-injection-javascript-v1

> general-injection-javascript-v1: 6 Keryn rules for javascript, typescript (3 error, 3 warning).

Source: https://keryn.dev/rules/general-injection-javascript-v1/

6 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.sql-injection-request-to-query

`error` javascript, typescript data-flow rule javascript, typescript, express, koa, fastify, nestjs, nextjs

A request value is concatenated or interpolated into SQL text that is passed to a database driver or a raw-query method. The value can change the query. Keep the SQL text constant and pass the value as a bound parameter ($1 or ? placeholders, a values array, or a tagged template such as Prisma's $queryRaw).

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-89](https://keryn.dev/taxonomies/cwe/#cwe-89-sql-injection) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Pass the value separately from the SQL text: pool.query('select \* from t where id = $1', [id]), connection.execute('... where id = ?', [id]), knex.raw('... where id = ?', [id]), sequelize.query(sql, &#123; replacements &#125;), or the tagged form prisma.$queryRaw`...$&#123;id&#125;`. For a column or direction name that cannot be a parameter, pick it from a fixed allow-list.

**References:** [https://node-postgres.com/features/queries#parameterized-query](https://node-postgres.com/features/queries#parameterized-query) · [https://sidorares.github.io/node-mysql2/docs#using-prepared-statements](https://sidorares.github.io/node-mysql2/docs#using-prepared-statements) · [https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries) · [https://knexjs.org/guide/raw.html#raw-parameter-binding](https://knexjs.org/guide/raw.html#raw-parameter-binding) · [https://sequelize.org/docs/v6/core-concepts/raw-queries/#replacements](https://sequelize.org/docs/v6/core-concepts/raw-queries/#replacements)

## keryn.general.js.command-injection-request-to-shell

`error` javascript, typescript data-flow rule javascript, typescript, express, koa, fastify, nestjs, nextjs

A request value reaches a command line that a shell parses (exec, execSync, spawn with shell: true or sh -c), or chooses the program that is started. Shell metacharacters in the value run as commands. Start a fixed program with execFile or spawn and pass each value as its own argument.

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-78](https://keryn.dev/taxonomies/cwe/#cwe-78-os-command-injection) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Call execFile('/usr/bin/program', [arg1, arg2]) or spawn(program, [args]) without the shell option, with a fixed program path. Validate each argument against an allow-list or a strict pattern, and put -- before values that could start with a dash.

**References:** [https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback](https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback) · [https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback](https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback) · [https://nodejs.org/api/child_process.html#child_processspawncommand-args-options](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options)

## keryn.general.js.path-traversal-request-to-file

`error` javascript, typescript data-flow rule javascript, typescript, express, koa, fastify, nestjs, nextjs

A request value reaches a file-system call or a file response (fs read, write, delete, list; res.sendFile, res.download) without being reduced to a base name or confined to a directory. Sequences such as ../ escape the intended folder. Resolve the path against a fixed base and refuse it unless the result stays inside that base.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [reaches](https://keryn.dev/docs/edges/edge-kinds/#reaches) content or traffic gets to a thing; it crosses the [`user->prompt`](https://keryn.dev/docs/edges/trust-boundaries/#user-to-prompt) boundary (untrusted input reaching a prompt).

[CWE-22](https://keryn.dev/taxonomies/cwe/#cwe-22-path-traversal) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Take only path.basename(name), or compute full = path.resolve(base, name) and continue only when full starts with base + path.sep (or path.relative(base, full) does not start with ..). With Express, res.sendFile(name, &#123; root: base &#125;) refuses paths that leave the root. Prefer an id that the server maps to a path.

**References:** [https://nodejs.org/api/path.html#pathresolvepaths](https://nodejs.org/api/path.html#pathresolvepaths) · [https://nodejs.org/api/path.html#pathrelativefrom-to](https://nodejs.org/api/path.html#pathrelativefrom-to) · [https://nodejs.org/api/fs.html#file-system](https://nodejs.org/api/fs.html#file-system) · [https://expressjs.com/en/4x/api/#res.sendFile](https://expressjs.com/en/4x/api/#res.sendFile)

## keryn.general.js.ssrf-request-to-outbound-url

`warning` javascript, typescript data-flow rule javascript, typescript, express, koa, fastify, nestjs, nextjs

A request value decides the address of an outbound HTTP call (fetch, axios, got, node:http, undici, a headless browser). The server can be made to call internal services, cloud metadata endpoints or the loopback interface. Compare the parsed host with an allow-list before the call.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [reaches](https://keryn.dev/docs/edges/edge-kinds/#reaches) content or traffic gets to a thing; it crosses the [`user->prompt`](https://keryn.dev/docs/edges/trust-boundaries/#user-to-prompt) boundary (untrusted input reaching a prompt).

[CWE-918](https://keryn.dev/taxonomies/cwe/#cwe-918-server-side-request-forgery) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Parse the value with new URL(), require https, and continue only when url.hostname is in a fixed allow-list. If arbitrary hosts are a feature, resolve the name first and refuse private, loopback and link-local addresses, and do not follow redirects without checking each hop. Build service URLs from a fixed origin plus an encoded path segment.

**References:** [https://developer.mozilla.org/en-US/docs/Web/API/URL/URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) · [https://nodejs.org/api/http.html#httprequesturl-options-callback](https://nodejs.org/api/http.html#httprequesturl-options-callback) · [https://nodejs.org/api/net.html#class-netblocklist](https://nodejs.org/api/net.html#class-netblocklist)

## keryn.general.js.open-redirect-request-to-location

`warning` javascript, typescript data-flow rule javascript, typescript, express, koa, fastify, nestjs, nextjs

A request value becomes the target of an HTTP redirect (res.redirect, a Location header, NextResponse.redirect). A crafted link sends the visitor from this site to an attacker's page. Redirect only to a relative path of this site or to a host on an allow-list.

Confidence **P1**: dangerous in context. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [reaches](https://keryn.dev/docs/edges/edge-kinds/#reaches) content or traffic gets to a thing; it crosses the [`user->prompt`](https://keryn.dev/docs/edges/trust-boundaries/#user-to-prompt) boundary (untrusted input reaching a prompt).

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

**Fix:** Accept only a path: require the value to start with a single / and not with // or /\\\\, or parse it with new URL(value, origin) and compare url.origin with your own origin (or url.hostname with an allow-list) before redirecting. Otherwise redirect to a fixed default page.

**References:** [https://expressjs.com/en/4x/api/#res.redirect](https://expressjs.com/en/4x/api/#res.redirect) · [https://nextjs.org/docs/app/api-reference/functions/next-response#redirect](https://nextjs.org/docs/app/api-reference/functions/next-response#redirect) · [https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Location](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Location)

## keryn.general.js.xss-request-to-html-response

`warning` javascript, typescript data-flow rule javascript, typescript, express, koa, fastify, nestjs, nextjs

A request value is written into an HTML response body without encoding (res.send, res.write, res.end, ctx.body, a text/html Response). Markup in the value runs in the visitor's browser. Encode the value for HTML before writing it, or send it as JSON or plain text.

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-79](https://keryn.dev/taxonomies/cwe/#cwe-79-cross-site-scripting) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling)

**Fix:** Escape the five HTML characters (&amp; &lt; &gt; " ') in every value placed in markup, for example with a template engine that escapes by default or an escaping helper, or answer with res.json / res.type('text/plain'). For rich text, pass it through an HTML sanitizer with an allow-list of tags.

**References:** [https://expressjs.com/en/4x/api/#res.send](https://expressjs.com/en/4x/api/#res.send) · [https://koajs.com/#response-body](https://koajs.com/#response-body) · [https://developer.mozilla.org/en-US/docs/Web/API/Response/Response](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response)
