Skip to main content

Security for NestJSs

NestJS security covers authenticating users, authorising actions and hardening the HTTP surface. Typical pieces are Passport strategies, JWT issuing and verification, guards that check roles, password hashing, plus helmet, CORS and rate limiting through the throttler module.

Stage: Data and Security · Part of the NestJS roadmap · Last reviewed 19 November 2026

What to learn in Security

Security interview questions

What is a guard in NestJS and when does it run?

A guard is a class implementing CanActivate that decides whether a request may continue. It runs after middleware and before interceptors and pipes, and returns true or false, or throws an exception such as UnauthorizedException.

How do you implement role-based access in NestJS?

Attach roles to a route with a custom decorator using SetMetadata, then write a guard that reads the metadata through Reflector and compares it with the roles on the authenticated user, returning false if none match.

Where Security fits in the NestJS roadmap

Security belongs to the Data and Security stage (intermediate level). Persist and protect.

Back to the full NestJS roadmap