← スキル一覧に戻る

nestjs-security
by ngxtm
⭐ 0🍴 0📅 2026年1月23日
SKILL.md
name: NestJS Security description: Authentication, RBAC, and Hardening standards. metadata: labels: [nestjs, security, auth, jwt] triggers: files: ['/*.guard.ts', '/*.strategy.ts', '/auth/'] keywords: [Passport, JWT, AuthGuard, CSRF, Helmet]
NestJS Security Standards
Authentication
- Strategies: Use
@nestjs/passportwithpassport-jwt. - JWT Hardening:
- Algorithm: Enforce
algorithms: ['RS256'](preferred) or['HS256']. Rejectnone. - Claims: Validate
iss(Issuer) andaud(Audience). - Secrets: High entropy (> 256-bit) for HS256.
- Algorithm: Enforce
- State: Stateless. Short access tokens (15m), Long httponly refresh tokens (7d).
- MFA: Require 2FA for sensitive access (admin panels).
Authorization (RBAC)
- Strategy: Deny by default.
- Implementation: Bind
AuthGuardglobally (APP_GUARD). - Bypass: Create a
@Public()decorator and allow access if present in the Guard.
- Implementation: Bind
- Metadata: Use
Reflector.createDecorator<string[]>(). - Guards: Use
Reflectorto merge Method/Class roles (getAllAndOverride).
Cryptography & Hashing
- Hashing:
- Algorithm: Use Argon2id (
argon2) instead of Bcrypt (vulnerable to GPU/FPGA cracking). - Implementation:
await argon2.hash(password).
- Algorithm: Use Argon2id (
- Encryption (At Rest):
- Algorithm: Use AES-256-GCM (Authenticated Encryption).
- Keys: Never hardcode. Rotate keys using a KMS (Key Management Service).
- Native: Use Node.js
crypto.createCipheriv.
CSRF (Cross-Site Request Forgery)
- Context: Mandatory if using Cookie-based sessions or Cookie-based JWTs.
- Mitigation:
- Synchronizer Token: Use
csurfvia@nest-middlewares/csurfor similar wrapper. - State: Token must be cryptographically strong and verified on every state-changing request (POST/PUT/DELETE).
- Synchronizer Token: Use
- Note: If using strictly
Authorization: Bearerheaders (localStorage), CSRF is less critical butSameSite: Strictcookies are still recommended for defense-in-depth.
Hardening
- Helmet: Mandatory.
app.use(helmet()).- HSTS: Enable
Strict-Transport-Securitywithpreload. - CSP: Configure Content Security Policy specifically if serving any UI.
- HSTS: Enable
- Permissions-Policy: Restrict browser permissions via
helmet.permissionsPolicy(). - CORS: Explicit origins only. No
*. - Throttling:
- Distributed: Do not use in-memory rate limiting in production. Use
@nestjs/throttlerwith Redis storage (throttler-storage-redis) to sync limits across instances.
- Distributed: Do not use in-memory rate limiting in production. Use
Audit Logging
- Requirement: Track critical mutations (Who, What, When).
- Pattern: Implement an
AuditInterceptorthat logsPOST/PUT/DELETEactions to a secure, immutable log store (separate from app logs).
Secrets & Config
- CI/CD: Run
npm auditorpnpm audit --prodin pipelines. - Runtime: Avoid
.envfiles in production runtime. Inject secrets via environment variables from a vault (AWS Secret Manager / HashiCorp Vault) into the container environment.
Data Sanitization
- Transform: Use
ClassSerializerInterceptor+@Exclude()globally or per-controller to strip sensitive fields (passwords) from responses. - Validation:
ValidationPipe({ whitelist: true })prevents mass assignment attacks by stripping unknown properties from payloads.
Improper Assets Management
- Shadow APIs: Audit routes regularly.
- Deprecation: Disable Swagger/OpenAPI endpoints (
/api,/docs) in production.
Server-Side Request Forgery (SSRF)
- Validation: Validate/Allowlist domains for all outgoing HTTP requests (
HttpService). - Network: Restrict egress traffic (e.g., block AWS metadata
169.254.169.254) via infrastructure/firewall.
Injection Prevention
- SQLi: Prefer ORM/ODM methods. Avoid raw queries (
query()) with string concatenation. Use parameterized queries if raw SQL is strictly necessary. - XSS: Input validation is not enough. Sanitize HTML input (e.g.,
dompurify) before storage or output.
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です