nestjs-security
Authentication, RBAC, and Hardening standards.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
NestJS Security Standards
Priority: P0 (CRITICAL)
Authentication (JWT)
-
Strategy: Use
@nestjs/passportwithpassport-jwt. -
Algorithm: Enforce
RS256(preferred) orHS256. Rejectnone. -
Claims: Validate
issandaud. - Tokens: Short access (15m), Long httponly refresh (7d).
- MFA: Require 2FA for admin panels.
Authorization (RBAC)
-
Deny by default: Bind
AuthGuardglobally (APP_GUARD). -
Bypass: Create
@Public()decorator for open routes. -
Roles: Use
Reflector.getAllAndOverridefor Method/Class merge.
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
@nestjs/throttlerin production. - CSRF: Required for cookie-based auth. See implementation.
Data Protection
-
Sanitization: Use
ClassSerializerInterceptor+@Exclude(). -
Validation:
ValidationPipe({ whitelist: true })to prevent mass assignment. - Audit: Log mutations (Who, What, When). See implementation.
Secrets Management
-
CI/CD: Run
npm audit --prodin pipelines. -
Runtime: Inject via vault (AWS Secrets Manager / HashiCorp Vault), not
.env.
Anti-Patterns
-
No Shadow APIs: Audit routes regularly; disable
/docsin production. - No SSRF: Allowlist domains for all outgoing HTTP requests.
-
No SQLi: Use ORM; avoid raw
query()with string concatenation. -
No XSS: Sanitize HTML input with
dompurify.
Related Topics
common/security-standards | architecture | database
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!