The production security checklist we run on every Node.js API: headers, rate limiting, validation, parameterized queries, JWT hygiene, CORS, secrets, error handling and more — with code.

Francis K Njenga
Senior Developer
Most API breaches are not exotic zero-days — they are missing basics: an endpoint without rate limiting, a query built with string concatenation, a stack trace leaked to the client, a secret committed to git. This is the exact 12-point checklist our team runs before any Node.js API goes to production. It maps closely to the OWASP API Security Top 10, and every item has a concrete implementation below.
One middleware disables MIME sniffing, hides X-Powered-By, sets HSTS, frameguard and a sane Content-Security-Policy baseline. There is no reason to skip it.
Terminate TLS at your reverse proxy (Nginx/Caddy), redirect HTTP → HTTPS, and enable HSTS. Tokens and credentials over plain HTTP are credentials in plaintext.
Global limits stop scrapers and brute force; tighter limits on auth endpoints stop credential stuffing. Return 429 with Retry-After. In multi-instance deployments, back the limiter with Redis so counts are shared.
import helmet from "helmet";
import rateLimit from "express-rate-limit";
import type { Express } from "express";
export function applySecurity(app: Express) {
app.use(helmet());
app.set("trust proxy", 1); // behind Nginx — needed for correct client IPs
app.use(rateLimit({
windowMs: 15 * 60 * 1000,
limit: 300,
standardHeaders: "draft-7",
legacyHeaders: false,
}));
app.use("/api/auth", rateLimit({
windowMs: 15 * 60 * 1000,
limit: 10,
message: { error: "Too many attempts. Try again later." },
}));
}Auth endpoints get 10 attempts per 15 minutes per IP — brute force becomes impractical.
Never trust the client — including your own frontend. Parse request bodies, query params and route params with a schema library (zod is our default). Reject unknown fields, coerce types explicitly, and bound lengths and ranges. Validation is also your first defense against mass-assignment attacks where a caller sneaks in {"role": "admin"}.
import { z } from "zod";
const ContactSchema = z.object({
name: z.string().min(2).max(120),
email: z.string().email().max(255),
message: z.string().min(10).max(5000),
}).strict(); // unknown keys => rejection
export async function createContact(req, res) {
const parsed = ContactSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: "Invalid payload" });
}
const { name, email, message } = parsed.data;
// ...persist parsed.data only — never req.body
res.status(201).json({ ok: true });
}stripUnknown-style safety: only declared fields survive.
SQL injection is still in the OWASP top ten because string-built queries still ship. Use your driver's placeholders or an ORM/query builder (Drizzle, Prisma, Kysely) — and treat raw SQL escape hatches as code-review red flags.
import postgres from "postgres";
const sql = postgres(process.env.DATABASE_URL!);
// SAFE: value is a parameter, not SQL text
export function findUserByEmail(email: string) {
return sql`SELECT id, email, name FROM users WHERE email = ${email}`;
}
// NEVER do this:
// sql("SELECT ... WHERE email = '" + email + "'")
postgres.js tagged templates are parameterized by construction.
Use bcrypt (cost ≥ 12) or argon2id. Never MD5/SHA-1/SHA-256 alone, never reversible encryption, never plaintext "temporarily". Enforce a minimum length and check against known-breached password lists for consumer apps.
Short-lived access tokens (15 min), refresh tokens stored server-side or in HttpOnly; Secure; SameSite=Strict cookies, algorithm pinned to HS256/RS256 (never accept alg: none), and always verify iss and aud. Prefer cookie sessions for browser apps — localStorage tokens are one XSS away from theft.
Authentication tells you who; authorization decides what they may do. Check ownership on every object access (WHERE id = $1 AND user_id = $2) — broken object-level authorization (BOLA) is the #1 API vulnerability. Never rely on the frontend hiding buttons.
Access-Control-Allow-Origin: * with credentials is a misconfiguration browsers will reject anyway. Enumerate your exact origins, and remember CORS is not an auth mechanism — server-side checks still apply.
No keys in code, no .env in git (our own vps.json-style credential files are gitignored for exactly this reason). Rotate on suspicion, scope credentials to least privilege, and use separate credentials per environment.
A global error handler returns a generic message and a request ID to the client while logging the full stack server-side. Unhandled rejections must crash loudly in dev and be caught-and-reported in production. Log auth failures, validation rejections and 5xx spikes — they are your early-warning system.
import { randomUUID } from "node:crypto";
export function errorHandler(err, req, res, _next) {
const requestId = randomUUID();
console.error({
requestId,
method: req.method,
path: req.path,
message: err.message,
stack: err.stack,
});
const status = err.status ?? 500;
res.status(status).json({
error: status === 500 ? "Internal server error" : err.message,
requestId,
});
}Stack traces, SQL snippets and internal paths never leave the server.
Run npm audit --omit=dev in CI, enable Dependabot/Renovate, pin versions with a lockfile, and review new dependencies before adding them — a typo-squatted package with install scripts is a real attack vector. Back up the database on a schedule and test restores; availability is part of security too.
The honest summary: none of these twelve items is clever. That is the point — attacks succeed against the boring gaps, not the clever defenses. Run the checklist on every service, every release.
If you want a second pair of eyes, security audits are a core part of what we do at Frank Tech — we run this checklist (and a lot more) against production systems and hand you a prioritized remediation plan. Book an audit.

Senior Developer
Francis Njenga is an experienced Lead Developer specializing in React, Next.js, and modern JavaScript frameworks, with a strong background in web development.