node-express-security

A security checklist for Node.js web APIs built with Express or similar frameworks such as Fastify, Koa, or Nest. An API is a program interface that lets applications exchange data over the web.

In plain words
What is it for?
Reviewing or building backend APIs for login checks, permissions, object ownership, signed tokens, cross-origin access, injection protection, and request limits.
Why use it?
It highlights common mistakes that can expose data, allow unauthorized actions, or let attackers inject commands or database queries.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/coldtatooine/vuln-skill-pack/node-express-security
Clone the repo
git clone --depth 1 https://github.com/coldtatooine/vuln-skill-pack
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 658 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00658
Opus 5 $0.00000 $0.00329
Sonnet 5 $0.00000 $0.00132
Haiku 4.5 $0.00000 $0.00066

Measured 2d ago against content hash 82532d0fbff0, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

node-express-security scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

- **Command**: avoid `child_process.exec` with input; use `execFile`/`spawn` with an argument array and no shell.
cursor/rules/node-express-security.mdc · 37 lines

How it starts

The opening of the file, as written. The whole thing — 37 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Node.js & Express API Security Footguns

1. Authentication & authorization

  • Auth middleware must actually be applied to every protected route. A route registered before/outside the app.use(auth) line, or a router mounted without it, is public. Trace middleware order.
  • Authentication ≠ authorization. A valid token proves who, not whether they may. Check role/ownership per route.
  • IDOR is the #1 API hole: GET /users/:id / DELETE /orders/:id must verify the token's user owns/may access that object — never look up by the path ID alone.

2. JWT pitfalls

  • Verify, don't decode: jwt.verify(token, secret) — never jwt.decode() for auth (no signature check).
  • Pin the algorithm: { algorithms: ['HS256'] }. Accepting alg: none or RS256↔HS256 confusion lets attackers forge tokens.
  • Strong secret key (not a default/committed value). Check exp. Have a revocation story.

3. CORS

  • cors({ origin: '*', credentials: true }) is invalid and dangerous — with credentials, reflect a strict origin allowlist, never *. Don't reflect the incoming Origin header unchecked.

4. Injection

  • SQL/NoSQL: parameterized queries / prepared statements only; never string-concatenate input. For Mongo, guard operator injection ({ $gt: '' }) by validating/casting types.
  • Command: avoid child_process.exec with input; use execFile/spawn with an argument array and no shell.
  • Path traversal: normalize user-supplied filenames into fs/path.join, confine to a base dir, reject ...

5. Missing defenses

  • Rate limiting on auth, password reset, expensive endpoints (express-rate-limit).
  • Security headers: helmet(). Body size limit: cap express.json({ limit }).
  • Mass assignment: Object.assign(user, req.body) lets a client set isAdmin/role. Allowlist writable fields.

6. Other

  • Don't send stack traces / internal errors to clients in prod — central error handler, generic messages.
  • Prototype pollution: deep-merge of untrusted JSON with __proto__; validate/sanitize.
  • SSRF: allowlist hosts for server-side requests to user URLs; block internal ranges and cloud metadata.
  • Secrets from process.env, never committed; validate presence at boot.

Read the full file on GitHub · 37 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 37 lines · 0 tokens per session scan A 82532d0fbff0

Subscribe to this mod's changes

node-express-security is a cursor rule published in the GitHub repository coldtatooine/vuln-skill-pack (2 stars, last pushed 7d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 658 tokens. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.