anantbhandarkar/make-it-right/mir-backend-node-express

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Make It Right (Express module). Express 5 (now the npm default) + Express 4 maintenance-line reliability augmentation. Use alongside mir-backend and mir-backend-node when the target stack is Express — it carries the mechanical footguns that the framework-agnostic tiers deliberately omit: what Express 5 does and does not auto-catch for async handlers, the path-to-regexp route-syntax break that makes `app.get('*')` throw at boot, req.body being undefined rather than {}, the simple-vs-extended query parser change, middleware ordering as a hard contract, error-handler arity, the absence of built-in validation and what fills the gap, CORS/helmet/rate-limit being off by default, trust-proxy spoofing, and object-level authorization gaps that structural frameworks catch but Express doesn't. TRIGGER only when the Node backend stack is Express used directly — building, reviewing, or debugging an Express route, middleware, or error handler. Always loads TOGETHER WITH mir-backend (the gates) and mir-backend-node (V8 event-loop / process-model concerns: blocking, worker_threads, unhandled rejections, backpressure, timeouts, npm supply chain); this module only adds Express library mechanics. SKIP for Fastify, Hapi, or Koa (each has its own mir-backend-node-<framework> module), SKIP for NestJS even though NestJS runs on Express by default — that stack loads mir-backend-node-nestjs instead — and SKIP for non-Node runtimes.

Install

npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-node-express

SKILL.md

The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-node-express.

/mir-backend-node-express · Make It Right (Express)

Bottom tier of the chain: mir-backend (generic gates) → mir-backend-node (V8/Node event-loop model) → this (Express library mechanics). Run the gates first; load the Node runtime tier for event-loop and process-model concerns; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (blocking the event loop, worker_threads, unhandled rejections, stream backpressure, timeouts, heap limits, npm supply chain) live in `mir-backend-node` — not here.

Stack assumed (npm registry, 13 Aug 2026): express@5.2.1 is the latest tag; the 4.x maintenance line is latest-4 = 4.22.2. Express 5 requires Node ≥ 18 by its own engines field, but target Node 22/24 per the runtime tier — Node 20 is EOL. Do not pin 5.2.0: it shipped an unintended breaking change to extended query parsing and was superseded by 5.2.1 the same day.

If you are writing new Express code, write Express 5. npm install express has resolved to 5.x since 5.1.0 took the latest tag on 2025-03-31. Most training data — and most AI output — is still Express 4, which is where the next four items come from.

The Express footguns AI walks into most

1. Express 5 auto-forwards rejected promises — Express 4 does not, and neither catches callbacks

Express 5 awaits the promise returned by a route handler or by any middleware, and forwards a rejection to the error-handling middleware. That "or any middleware" matters: async auth and validation middleware get the same treatment, which is the reason the asyncHandler wrapper and the express-async-errors shim are both unnecessary on 5:

js
// CORRECT in Express 5 — a throw reaches the (err, req, res, next) handler
app.get('/users/:id', async (req, res) => {
const user = await db.findUser(req.params.id);
res.json(user);
});

Express 4 does not await the return value. The same code produces an unhandled rejection (which kills the process, see the Node tier) and the request hangs until the client times out. On 4.x, wrap or catch explicitly:

js
// Express 4 only — forward rejections to next
const asyncHandler = fn => (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
app.get('/users/:id', asyncHandler(async (req, res) => { /* ... */ }));

The part Express 5 does NOT fix, and the reason "we're on 5, we're fine" is wrong in review: only the returned promise is awaited. Everything else escapes the handler and lands at the process level — as two different failures that need two different handlers:

What escapesWhere it lands
a promise you started but did not return or awaitunhandledRejection → process exits (Node default)
a throw inside a setTimeout/setInterval or a plain callbackuncaughtException
an EventEmitter 'error' event with no listenerthrows → uncaughtException
a stream error with no 'error' handler and no pipeline()same

Wiring only process.on('unhandledRejection') and calling it done leaves the bottom three unhandled. See the Node tier §3 and §7.

js
// STILL BROKEN on Express 5 — nothing awaits this, the error escapes the handler
app.post('/orders', async (req, res) => {
auditLog.write(req.body); // returns a promise, not returned or awaited
stream.on('data', () => JSON.parse(chunk)); // throws inside a callback → process-level
res.json({ ok: true });
});

State the Express major in the design. If it is 4, every async handler needs a wrapper and the plan needs a migration note.

2. Express 5 changed the route syntax — app.get('*') throws at startup

Express 5 upgraded to path-to-regexp 8, which removed sub-expression regex patterns and requires wildcards to be named. AI writes Express 4 route strings constantly, and the failure is a boot-time TypeError about a missing parameter name, or a silent 404 — not a helpful message:

Express 4Express 5Notes
app.get('*', h)app.get('/*splat', h)wildcard must be named
'/files/*' matching /files too'/files/{*splat}'braces make the group optional
'/:file.:ext?''/:file{.:ext}'? optional marker removed
'/:id(\\d+)'validate req.params.id in the handlerinline regex removed for ReDoS reasons
req.params[0] for a wildcardreq.params.splat — an array of segmentsshape change, not just a name change

This applies everywhere a path string is accepted: app.use, router.use, and any path-based middleware mount.

3. Express 5 also changed three defaults that produce silent wrong behavior
ChangeExpress 4Express 5The failure
req.body with no body parser{}`undefined`req.body.email throws TypeError: Cannot read properties of undefined instead of being falsy
default query parserextended`simple`?filter[status]=open yields the string key 'filter[status]', not a nested object; filters silently stop working
res.status(n)anything acceptedmust be an integer 100–999res.status(err.code) with a driver error code now throws

Also removed in 5: app.del() (use app.delete()), req.param(name), res.sendfile(), res.send(body, status) / res.json(obj, status) (use res.status(s).json(o)), res.redirect(url, status) (argument order is now (status, url)), and res.redirect('back'). npx codemod@latest @expressjs/v5-migration-recipe applies the mechanical ones.

4. Middleware order is the contract — get it wrong and nothing else matters

Express resolves middleware strictly in registration order. The order is not a style choice; it is the execution contract:

body parser
└── request-id / correlation-id logger
└── rate limiter
└── authentication
└── authorization (object-level, per-router)
└── route handlers
└── 404 handler
└── error handler ← MUST be last, MUST have 4 args

Common ordering defects AI introduces:

  • Body parser after routes — req.body is undefined in the handler (and in Express 5 that is a TypeError, not an empty object).
  • Auth middleware missing from a router — a route added later slips in unauthenticated.
  • Error handler not registered last — it never runs.
  • Error handler with 3 args ((req, res, next)) — Express identifies error handlers by arity; 3-arg handlers are treated as regular middleware and skipped for errors.
js
// WRONG — error handler silently skipped (3 args)
app.use((err, res, next) => { res.status(500).json({ error: err.message }); });
// RIGHT — must have exactly 4 args
app.use((err, req, res, next) => { res.status(500).json({ error: 'Internal error' }); });
5. No built-in validation — without it, mass assignment and injection slip in

Express puts raw, unvalidated input on req.body / req.query / req.params. AI code that passes these straight to a database or service layer is vulnerable to:

  • Mass assignment / overposting — a client sends { "isAdmin": true } alongside a legitimate payload; if you spread req.body into an ORM object, you have just promoted them.
  • Type coercion surprises — query strings are always strings; passing req.query.limit to a DB call that expects a number without parsing is a latent bug. Express 5's simple query parser makes this worse, because nested keys arrive as flat strings.

Validate at the route boundary with zod (latest 4.4.3) or joi. Define a schema, parse, and use only the parsed output:

js
import { z } from 'zod';
// z.strictObject REJECTS unknown keys. Plain z.object() STRIPS them silently —
// safe against mass assignment, but you get no signal that a client is sending
// isAdmin. Prefer strictObject so overposting shows up as a 400.
const CreateUserSchema = z.strictObject({
email: z.email(), // Zod 4 top-level format; z.string().email() is legacy
name: z.string().min(1).max(100),
// id, isAdmin, role are NOT here — they're not accepted from the client
});
app.post('/users', async (req, res) => {
const body = CreateUserSchema.parse(req.body); // throws ZodError on invalid input
const user = await db.createUser(body); // only safe fields reach the DB
res.status(201).json(user);
});

Catch ZodError in the error handler and return a 400 with field-level detail. Never pass req.body to an ORM model constructor without schema-gating it first. Express has no response-side equivalent of Fastify's response schema, so also choose the fields you send back explicitly — do not res.json(userRow).

6. Object-level authorization is easy to miss — no structure enforces it

Express has no built-in guard or controller structure. Authentication (who are you?) is easy to add as a single middleware. Authorization (may *this user* act on *this specific resource*?) is easy to forget because there is no framework hook that forces it at the route level:

js
// WRONG — checks auth but not ownership; any authenticated user reads any user's data
app.get('/accounts/:id', requireAuth, async (req, res) => {
const account = await db.findAccount(req.params.id);
res.json(account); // IDOR: account might belong to a different user
});
// RIGHT — load the resource, then assert ownership before returning
app.get('/accounts/:id', requireAuth, async (req, res) => {
const account = await db.findAccount(req.params.id);
if (!account || account.userId !== req.user.id) {
return res.status(404).json({ error: 'Not found' });
}
res.json(account);
});

Return 404 (not 403) when the resource does not belong to the requester — 403 confirms the resource exists. Enforce object-level authorization at every endpoint that loads an entity by a client-supplied ID, including PATCH/DELETE, not just GET.

Security

Express-specific mechanics. Runtime-level items (SSRF, command injection, prototype pollution, path traversal, npm supply chain, secrets in logs) live in mir-backend-node.

Current advisory class: path-to-regexp ReDoS, and it reaches you transitively

Express 5 pulls path-to-regexp through router@2.2.0, declared as ^8.0.0. Two ReDoS CVEs published 2026-03-27 affect 8.0.0 up to but not including 8.4.0, fixed in 8.4.0 (registry latest is 8.4.2):

CVETrigger
CVE-2026-4923multiple wildcards plus at least one parameter, where the second wildcard is not at the end — e.g. /*foo-*bar-:baz, /x/*a-:b/*c/y. /*foo-:bar is safe.
CVE-2026-4926multiple sequential optional groups in brace syntax — e.g. {a}{b}{c}:z. Generated regex grows exponentially with group count.

A caret range means a fresh install picks up the fix; a lockfile committed before March 2026 does not. Check with npm ls path-to-regexp, not by reading package.json. Then audit your own route strings for the two shapes above — the fix removes the pathological regex generation, but multi-wildcard routes are worth simplifying anyway. Express's own security-updates page still only documents 4.x entries, so do not treat "no Express advisory" as "no risk"; Express's exposure mostly arrives through path-to-regexp, send, serve-static, qs, cookie, and body-parser.

Nothing secure is on by default

Express ships with no security headers, no CORS policy, and no rate limiting. Registered versions verified on the registry today: helmet@8.3.0, cors@2.8.6, express-rate-limit@8.6.2.

js
import helmet from 'helmet';
import cors from 'cors';
import rateLimit from 'express-rate-limit';

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-node-express/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-node-express)

Something wrong with this skill or its page? Tell us.