AI pentesting guides / By tech stack

Stack guide: NestJS

NestJS security testing

NestJS security testing comes down to checking that guards, pipes and DTOs are applied everywhere you think they are: NestJS gives you good primitives, but a controller without @UseGuards or a ValidationPipe without whitelist enabled behaves exactly like an unprotected Express route.

NestJS apps also tend to publish detailed Swagger documentation through @nestjs/swagger. That is convenient for your frontend team and equally convenient for an attacker, so it is the first thing a tester looks for.

Guards that are missing or too coarse

  • Guards applied per controller rather than globally leave new controllers open by default. A global guard with an explicit @Public() decorator is safer.
  • Role guards that check the role but not ownership of the resource still allow cross-user access (BOLA).
  • GraphQL resolvers in a Nest app need guards on field resolvers too, not only on the top-level query.

DTOs, ValidationPipe and mass assignment

If ValidationPipe runs without whitelist: true and forbidNonWhitelisted: true, properties not declared on the DTO pass through. When the service then spreads the body into a TypeORM or Prisma update, a client can set role, ownerId or isVerified. Testing for this is simple from outside: add the extra field and see whether the stored object changes.

Exposed documentation and dev tooling

  • @nestjs/swagger commonly serves the JSON spec at /api-json, alongside the UI at /api. In production that maps every endpoint, including internal ones.
  • CVE-2025-54782: @nestjs/devtools-integration up to 0.2.0 exposed a local endpoint that executed code it was sent, reachable from a malicious website. It was fixed in 0.2.1, and devtools should never ship in production builds.
  • Default exception filters can leak stack traces when errors are thrown outside HttpException.
With Pentest-Swarm

Pointing Pentest-Swarm at a NestJS API

Pentest-Swarm treats your Nest service as a black box, which suits NestJS well: what matters is which guards actually fire on the deployed build.

  • Recon probes the NestJS Swagger paths (/api-json and /api/docs-json among others) and turns the published spec into endpoint targets.
  • Run the api-security playbook with two test users' tokens in separate runs to look for BOLA and BFLA.
  • If you expose GraphQL through @nestjs/graphql, run the graphql-audit playbook against the /graphql endpoint as well.
  • Use --verify so findings carry oracle-backed evidence before they reach your issue tracker.

Where it falls short

Black-box testing cannot confirm that every controller has a guard; it can only show which ones it reached without one. Code review or a SAST rule that flags controllers lacking guards gives you that coverage. Tests also only exercise the roles you give credentials for.

Questions

Should I disable Swagger in production for NestJS?

If the API is not public, yes, or put it behind authentication. Hiding documentation is not a control on its own, but there is no reason to publish a full map of internal endpoints.

Does ValidationPipe stop mass assignment?

Only with whitelist enabled, and ideally forbidNonWhitelisted so unexpected fields are rejected rather than silently stripped. Without those options it validates declared fields and passes the rest.

Is NestJS more secure than plain Express?

It makes good patterns easier, such as global guards and typed DTOs, but it runs on Express or Fastify underneath and the same access-control mistakes are possible.

Sources

  1. NVD: CVE-2025-54782