NestJS (TypeScript / Node) · CWE-362

NestJS: TOCTOU & Concurrency Race Conditions

Stop concurrent requests from double-spending balances, reusing single-use coupons, or bypassing step quotas. Applied specifically to NestJS: Enforce Guards plus DTO ValidationPipe with whitelist: true.

Primary AegisSec skill
business-logic-race-testing ->
Companion: owasp-api-graphql-audit
Coverage ledger tracking key
surface:nestjs::boundary:race-condition-toctou::principal:ctx.user.id
Parallel HTTP/2 burst verification comparing invariant balance/quota conservation
Risk boundary
// Unverified NestJS path (CWE-362)
// Handler accepts client input without validating ctx.user.id or boundary invariants before sink.
Hardened guard
// Hardened NestJS pattern (CWE-362)
// 1. Enforce Guards plus DTO ValidationPipe with whitelist: true
// 2. Move balance/quota assertions into atomic database conditional UPDATE predicates or row-level locks.

Verification steps

  1. 01Seed coverage-ledger.json for every NestJS route handling this boundary.
  2. 02Inspect the code trace from request input down to the persistence or egress sink.
  3. 03Confirm with paired User A vs User B requests (or staging baseline-vs-payload replay) via owasp-api-graphql-audit.