Questions
24 of 25
1How do you implement a local (username/password) Passport strategy in NestJS?
2How do you register a global JWT guard so all routes are protected by default in NestJS?
3What is RBAC and how do you implement a basic roles guard in NestJS?
4What is the difference between RBAC and ABAC and when would you use each in NestJS?
5How does the OAuth2 authorization code flow work and how do you implement it with Passport in NestJS?
6How do you implement API key authentication as an alternative to JWT in NestJS?
7How do you implement multi-tenant authentication where each tenant has its own JWT secret in NestJS?
8How do you implement JWT refresh token rotation with secure storage in NestJS?
9How do you implement ABAC with CASL in a NestJS application?
10What is the difference between JWT and session-based authentication and when do you choose each in NestJS?
11How do you implement two-factor authentication (2FA) with TOTP in NestJS?
12How do you implement permission-based authorization at the field level in a GraphQL resolver in NestJS?
13How do you test authentication guards and strategies in NestJS?
14What is Passport.js and how does it integrate with NestJS?
15How do you implement row-level (resource-level) authorization to ensure users can only access their own records in NestJS?
16What is PKCE and when is it required in OAuth2 flows in NestJS?
17How do you implement an OAuth2 Authorization Server in NestJS?
18How do you implement session-based authentication in NestJS?
19How does the validate() method in a Passport strategy relate to the NestJS request lifecycle?
20How do you implement JWT authentication in NestJS with access and refresh tokens?
21What should and should not go inside a JWT payload?
22How do you implement JWT token revocation (blacklisting) without a database lookup on every request in NestJS?
23What is the difference between AuthGuard('jwt') from Passport and writing a custom JwtAuthGuard in NestJS?
24How do you secure session cookies against common attacks (CSRF, XSS, session fixation) in NestJS?
25How do you implement brute force protection on the login endpoint in NestJS?
24 / 25

How do you secure session cookies against common attacks (CSRF, XSS, session fixation) in NestJS?

Set httpOnly to prevent JavaScript access (XSS), secure to HTTPS-only, and sameSite: 'strict' for CSRF protection. Regenerate the session ID on login to prevent session fixation. Also regenerate after privilege escalation to prevent session hijacking via pre-authentication sessions.

Secure cookie flags and session regeneration
Cookie security flags explained:
  1. 1

    httpOnly — JavaScript cannot access the cookie via document.cookie; blocks XSS-based session theft.

  2. 2

    secure — cookie is only sent over HTTPS; prevents transmission over plain HTTP connections.

  3. 3

    sameSite: 'strict' — cookie is not sent on cross-site requests; the primary CSRF defense for modern browsers.

  4. 4

    Session fixation — attacker sets a known session ID before login; regenerate() issues a fresh ID at login.

  5. 5

    For cross-origin APIs (different domain frontend), use sameSite: 'none' + secure + add CSRF token header validation.