Security Best Practices
Least privilege for service IAM, database users, and outbound HTTP - these rules harden Node.js APIs against OWASP-class failures.
Search across all documentation pages
Least privilege for service IAM, database users, and outbound HTTP - these rules harden Node.js APIs against OWASP-class failures.
process.env leaks, fetch(req.body.url), and missing auth on new routes.unknown in, typed DTO out.:id route. tenantId and ownerId match the caller.express-rate-limit or gateway equivalent.req.body into ORM create/update. Explicit allowlist fields only..env baked into images.env module with Zod parse at boot. Ban scattered process.env reads in app code.authorization, cookies, connection strings.SELECT/INSERT on needed tables only, no SUPERUSER.safeFetch for user-supplied URLs. DNS resolve + block private IPs (SSRF Guards).169.254.169.254). Common SSRF target on AWS/GCP.*. Reflect exact allowed origins.x-powered-by and verbose error stacks in JSON 5xx responses.npm ci + npm audit --audit-level=high in CI. See Dependency Scanning.USER node. Read-only root filesystem where possible.BOLA checks on every ID route. Authentication without object-level authorization is the most common API breach.
Internal APIs still need auth, SSRF guards, and secret hygiene - lateral movement after one breach is common.
API keys: quarterly or on employee offboarding. DB passwords: on schedule and after incidents. JWT keys: support kid rotation.
Yes - WAF filters obvious attacks; app enforces BOLA and business rules. Neither replaces the other.
Global ValidationPipe with whitelist: true, guards on controllers, never skip auth on GraphQL resolvers.
Semgrep rules, npm audit, route inventory diff, and integration tests for BOLA cases.
Good first layer. Still rate limit expensive app endpoints (login, search) at origin.
Validation and SSRF checks add microseconds. Body limits and rate limits protect both security and availability.
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 16, 2026