Authentication
JWT (JSON Web Tokens)
The API uses a dual-token authentication system:Access Token
- Short-lived (15 minutes default)
- Used for authenticated requests
- Included in Authorization header
- Expires quickly for security
Refresh Token
- Long-lived (7 days default)
- Used to obtain new access tokens
- Stored securely on client
- Rotated on each use
Token Usage
Making Authenticated Requests:Token Security Features
Token Rotation
Refresh tokens are rotated on each use. When you refresh, the old token is invalidated and a new pair is issued.
Reuse Detection
If a revoked refresh token is reused, all tokens for that user are invalidated, requiring re-authentication.
Password Security
Bcrypt Hashing
All passwords are hashed using bcrypt with configurable salt rounds:Higher salt rounds = more secure but slower. 12 rounds is recommended for production, providing strong security while maintaining reasonable performance.
Account Lockout
Protection against brute force attacks:- Max Attempts: 5 failed login attempts (configurable)
- Lockout Duration: 15 minutes (900000ms)
- Per Account: Lockout is account-specific, not IP-based
Rate Limiting
Multiple rate limiting tiers protect against abuse:Global Rate Limiting
Per-IP Across All Endpoints:- 200 requests per minute total
- Prevents a single IP from overwhelming the server
API Rate Limiting
General API Endpoints:- Password changes, account deletion: 3 requests per 5 minutes
- General admin: 30 requests per minute
- Write operations (create/update/delete): 10 requests per minute
Rate Limit Headers
All responses include rate limit information:CORS (Cross-Origin Resource Sharing)
Configuration
CORS is configured to allow only specified origins:Allowed Methods
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
Allowed Headers
- Content-Type
- Authorization
- X-Requested-With
Credentials
Credentials (cookies, authorization headers) are allowed for configured origins.Security Headers
The API automatically sets comprehensive security headers on all responses:Standard Security Headers
Content Security Policy (CSP)
API Routes (Strict):HSTS (HTTP Strict Transport Security)
In production:Docker Security
Non-Root User
The Docker container runs as a non-root user for enhanced security:Minimal Image
Multi-stage build ensures only necessary files are in production:- No dev dependencies
- No build tools
- Minimal attack surface
Best Practices
Environment Variables
Production Deployment
- Set
NODE_ENV=productionto enable HSTS and production optimizations - Use environment-specific
.envfiles - Configure firewall rules to restrict access
- Use MongoDB authentication and encryption
- Enable MongoDB TLS/SSL connections
- Regularly update dependencies
Monitoring
- Monitor failed authentication attempts
- Track rate limit violations
- Log security events
- Set up alerts for suspicious activity
- Monitor
/healthendpoint
Database Security
- Use MongoDB authentication (never run without auth in production)
- Use strong database passwords
- Limit database user permissions (principle of least privilege)
- Enable MongoDB access control
- Use connection string with
authSource=admin - Consider MongoDB TLS/SSL for connections
- Regularly backup database
API Keys and Tokens
- Store tokens securely on client (HttpOnly cookies for web)
- Implement token refresh before expiration
- Handle token expiration gracefully
- Clear tokens on logout
- Don’t log tokens or secrets
Vulnerability Reporting
If you discover a security vulnerability:- Do not open a public GitHub issue
- Email security details to: security@ceboelha.app
- Include:
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if any)
We appreciate responsible disclosure and will acknowledge your contribution in our security changelog.
Security Checklist
Before deploying to production:- Strong JWT secrets (32+ characters) configured
-
NODE_ENV=productionset - HTTPS configured with valid certificates
- MongoDB authentication enabled
- CORS origins properly configured
- Rate limiting configured appropriately
-
.envfile not committed to version control - Database backups scheduled
- Monitoring and alerting configured
- Security headers verified
- Account lockout configured
- Bcrypt salt rounds set to 12
Related Resources
- Deployment Guide - Production deployment
- API Authentication - Authentication endpoints
- Environment Configuration - Environment setup