Agent-skills-standard nestjs-security
Implement JWT authentication, RBAC guards, Helmet hardening, and Argon2 hashing in NestJS. Use when adding auth strategies, role-based access control, CSRF protection, or security headers. (triggers: **/*.guard.ts, **/*.strategy.ts, **/auth/**, Passport, JWT, AuthGuard, CSRF, Helmet)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nestjs/nestjs-security" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-nestjs-security && rm -rf "$T"
manifest:
skills/nestjs/nestjs-security/SKILL.mdsource content
NestJS Security Standards
Priority: P0 (CRITICAL)
Workflow: Secure NestJS Application
- Add Helmet —
inapp.use(helmet())
for HSTS, CSP headers.main.ts - Configure JWT strategy — Use
with RS256; validatepassport-jwt
andiss
claims.aud - Bind global AuthGuard — Register as
; useAPP_GUARD
for open routes.@Public() - Add throttling — Enable
with Redis store for rate limiting.@nestjs/throttler - Hash with Argon2id — Replace bcrypt with
.argon2.hash(password, { type: argon2.argon2id }) - Verify — Run
and test that unauthenticated requests return 401.npm audit --prod
Global Auth Guard Example
Argon2id Hashing Example
Authentication (JWT)
- Strategy: Use
with@nestjs/passport
.passport-jwt - Algorithm: Enforce
(preferred) orRS256
. RejectHS256
.none - Claims: Validate
andiss
.aud - Tokens: Short access (15m), Long httponly refresh (7d).
- MFA: Require 2FA for admin panels.
Authorization (RBAC)
- Deny by default: Bind
globally (APP_GUARD).AuthGuard - Bypass: Create
decorator for open routes.@Public() - Roles: Use
for Method/Class merge.Reflector.getAllAndOverride
Cryptography
- Hashing: Use Argon2id, not Bcrypt. See implementation.
- Encryption: Use AES-256-GCM with KMS rotation. See implementation.
Hardening
- Helmet: Mandatory. Enable HSTS, CSP.
- CORS: Explicit origins only. No
.* - Throttling: Use Redis-backed
in production.@nestjs/throttler - CSRF: Required for cookie-based auth. See implementation.
Data Protection
- Sanitization: Use
+ClassSerializerInterceptor
.@Exclude() - Validation:
to prevent mass assignment.ValidationPipe({ whitelist: true }) - Audit: Log mutations (Who, What, When). See implementation.
Secrets Management
- CI/CD: Run
in pipelines.npm audit --prod - Runtime: Inject via vault (AWS Secrets Manager / HashiCorp Vault), not
..env
Anti-Patterns
- No Shadow APIs: Audit routes regularly; disable
in production./docs - No SSRF: Allowlist domains for all outgoing HTTP requests.
- No SQLi: Use ORM; avoid raw
with string concatenation.query() - No XSS: Sanitize HTML input with
.dompurify