This document outlines how this NestJS application addresses each of the OWASP Top 10 security risks.
Mitigations Implemented:
- ✅ JWT-based authentication with secure token generation
- ✅ Role-Based Access Control (RBAC) using guards (
RolesGuard,PermissionsGuard) - ✅ Request validation at controller level
- ✅ User session management with refresh tokens
- ✅ Token revocation via blacklist (refresh token stored in DB)
- ✅ Proper authorization checks in service layer
- ✅ Rate limiting on sensitive endpoints (login, password reset)
Code References:
src/auth/common/guards/roles.guard.tssrc/auth/common/guards/permissions.guard.tssrc/auth/strategy/jwt.strategy.ts
Mitigations Implemented:
- ✅ Passwords hashed with bcrypt (cost factor: 12)
- ✅ JWT tokens with secure signing algorithms (HS256)
- ✅ Sensitive data encrypted at rest (database-level encryption recommended)
- ✅ HTTPS enforcement in production (Helmet + secure cookies)
- ✅ Environment variables for secrets (never hardcoded)
- ✅ Secrets validation on application startup
Code References:
src/auth/auth.service.ts(bcrypt hashing)src/config/env.config.ts(secret validation)src/main.ts(Helmet security headers)
Recommendations:
- Use AWS Secrets Manager or HashiCorp Vault for production secrets
- Enable TLS 1.3 on load balancer/reverse proxy
- Implement database-level encryption for PII data
Mitigations Implemented:
- ✅ Prisma ORM (parameterized queries by default)
- ✅ Input validation using
class-validatorwith DTOs - ✅ Global ValidationPipe with
whitelistandforbidNonWhitelisted - ✅ Zod schemas for additional validation layers
- ✅ No raw SQL queries (all via Prisma)
- ✅ Command injection prevention (no shell execution of user input)
Code References:
src/main.ts(Global ValidationPipe configuration)src/auth/dto/*.dto.ts(DTO validation)src/prisma/prisma.service.ts(Prisma client)
Best Practices:
- Always use DTOs with validation decorators
- Never concatenate user input into queries
- Validate and sanitize file uploads
Mitigations Implemented:
- ✅ Rate limiting on all endpoints (global throttler)
- ✅ Brute-force protection on auth endpoints (failed login tracking)
- ✅ Account lockout after multiple failed attempts
- ✅ Email verification before account activation
- ✅ Two-factor authentication (2FA) support
- ✅ Secure password reset flow with OTP
- ✅ Password complexity requirements
- ✅ Health checks for monitoring and alerting
Code References:
src/app.module.ts(ThrottlerModule)src/auth/auth.service.ts(brute-force protection)src/health/health.controller.ts(health checks)
Mitigations Implemented:
- ✅ Helmet.js for security headers
- ✅ CORS properly configured (origin whitelist)
- ✅ Error messages sanitized in production
- ✅ No stack traces exposed to clients
- ✅ Dependencies regularly updated (Dependabot)
- ✅ Security scanning in CI/CD (Snyk, Trivy)
- ✅ Non-root Docker user
- ✅ Read-only filesystem in container (where applicable)
Code References:
src/main.ts(Helmet, CORS, error handling)Dockerfile(security best practices).github/workflows/ci.yml(security scanning)
Production Checklist:
- Disable Swagger in production
- Set
NODE_ENV=production - Use strong JWT secrets (min 32 characters)
- Enable HTTPS only
- Configure proper CORS origins
Mitigations Implemented:
- ✅ Dependabot for automated dependency updates
- ✅
pnpm auditin CI/CD pipeline - ✅ Snyk security scanning
- ✅ Trivy container image scanning
- ✅ Regular dependency updates (weekly schedule)
- ✅ Lock file (
pnpm-lock.yaml) committed - ✅ Only necessary dependencies installed
Code References:
.github/dependabot.yml.github/workflows/ci.yml
Maintenance:
# Check for vulnerabilities
pnpm audit
# Fix vulnerabilities automatically
pnpm audit --fix
# Update dependencies
pnpm updateMitigations Implemented:
- ✅ Strong password requirements (min 8 chars, complexity)
- ✅ Multi-factor authentication (2FA via OTP)
- ✅ Session management with JWT + refresh tokens
- ✅ Secure password reset with time-limited OTPs
- ✅ Account lockout after failed attempts
- ✅ Login attempt logging with IP/user-agent
- ✅ HttpOnly and Secure cookies for tokens
- ✅ OAuth integration (Google, Facebook)
Code References:
src/auth/auth.service.ts(authentication logic)src/auth/dto/register.user.dto.ts(password validation)
Security Features:
- Password hashing with bcrypt (cost factor: 12)
- OTP expiration (10 minutes)
- Refresh token rotation
- JWT expiration (access: 1 day, refresh: 7 days)
Mitigations Implemented:
- ✅ Lock file for reproducible builds
- ✅ Docker image signed and scanned
- ✅ CI/CD pipeline integrity (GitHub Actions)
- ✅ Database migrations tracked in version control
- ✅ Environment variable validation on startup
- ✅ No auto-deserialization of untrusted data
- ✅ Audit logging for critical actions
Code References:
prisma/migrations/(migration history)src/config/env.config.ts(environment validation)src/auth/common/services/audit.service.ts(audit logging)
Mitigations Implemented:
- ✅ Structured logging with Pino
- ✅ Request/response logging with correlation IDs
- ✅ Sensitive data redaction in logs
- ✅ Sentry for error tracking
- ✅ Health check endpoints for monitoring
- ✅ Login attempt tracking
- ✅ Audit trail for sensitive operations
- ✅ Prometheus metrics (recommended)
Code References:
src/app.module.ts(Pino logger configuration)src/main.ts(Sentry integration)src/health/health.controller.ts(health checks)
Recommended Integrations:
- Prometheus + Grafana for metrics
- ELK Stack for log aggregation
- PagerDuty/Opsgenie for alerting
Mitigations Implemented:
- ✅ No server-side URL fetching based on user input
- ✅ Whitelist approach for external API calls
- ✅ OAuth callbacks validated against allowed URLs
- ✅ Network segmentation in Docker/K8s
- ✅ Egress filtering recommended in production
Code References:
src/auth/strategy/google.strategy.ts(OAuth with verified providers)src/config/env.config.ts(URL validation)
Best Practices:
- Never allow user input in server-side HTTP requests
- Use allowlists for external APIs
- Validate and sanitize redirect URLs
- Implement network-level egress filtering
- Helmet.js configured with CSP headers
- CSP disabled in development for ease of use
- Production CSP should be customized based on frontend needs
- Global rate limit: 100 requests per 60 seconds
- Auth endpoint limit: 5 requests per 15 minutes (login, register)
- Configurable via environment variables
- HttpOnly cookies prevent XSS attacks
- Secure flag ensures HTTPS-only transmission
- SameSite attribute prevents CSRF
- Token rotation on refresh
- Prisma prevents SQL injection by default
- Connection pooling configured
- Prepared statements used exclusively
- Least-privilege database user recommended
- Immediately rotate all secrets (JWT, API keys, database passwords)
- Review audit logs for suspicious activity
- Force logout all users (invalidate tokens)
- Investigate and patch vulnerability
- Notify affected users if PII compromised
Please report security vulnerabilities to: security@yourdomain.com
Do not open public GitHub issues for security vulnerabilities.
- All environment variables set and validated
- Strong JWT secret (min 32 random characters)
- Database user has least privileges
- Sentry DSN configured for error tracking
- HTTPS enforced (no HTTP allowed)
- CORS origins restricted to known domains
- Rate limiting enabled and tested
- Swagger disabled (
NODE_ENV=production) - Dependencies audited and up-to-date
- Secrets stored in vault (not in code or env files)
- Logging configured and monitored
- Backup and disaster recovery plan in place
- Security headers verified (use securityheaders.com)
- Container image scanned for vulnerabilities
- Kubernetes security context configured (non-root)
- Network policies applied (restrict egress)
- Review Dependabot PRs and merge updates
- Check for new CVEs affecting dependencies
- Review failed login attempts
- Conduct security dependency audit
- Review and update access control lists
- Test backup restoration process
- Review Sentry error reports
- Penetration testing (internal or third-party)
- Security training for development team
- Review and update security policies
- Conduct threat modeling exercise
Last Updated: 2025-01-29
Next Review: 2025-04-29