This document outlines the security measures implemented in the WhatsApp API Monetization Platform and provides guidelines for maintaining security.
- JWT Tokens: Access tokens (24h) and refresh tokens (7d)
- API Keys: SHA-256 hashed, stored securely
- Password Hashing: Bcrypt with 10 salt rounds
- Password Requirements:
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character
- Global Rate Limit: 100 requests per minute per user
- Login Rate Limit: 5 attempts per 15 minutes, then 15-minute block
- Password Verification: 3 attempts per 5 minutes
- All string inputs are sanitized to prevent XSS
- UUID format validation for IDs
- Email format validation
- Phone number validation
- Request body size limits (10MB)
- Helmet.js: Configured with CSP, HSTS, and other security headers
- CORS: Configurable origin whitelist for production
- Content Security Policy: Strict CSP rules
- HSTS: 1 year max-age with includeSubDomains and preload
- SQL Injection Prevention: Parameterized queries only
- API Key Caching: Redis cache with TTL
- Sensitive Data Logging: Audit logs for critical operations
- Password Verification: Rate-limited with audit logging
- Centralized error handling
- No sensitive information in error messages
- Proper HTTP status codes
- Request ID tracking
CRITICAL: Never use default values in production!
- Generate secure secrets:
node scripts/generate-secrets.js-
Update
.envfile with generated values -
Configure CORS origins:
CORS_ORIGINS=https://yourdomain.com,https://www.yourdomain.com- JWT Secrets: Generate 64-byte random hex strings
- Database Password: Use strong password (32+ characters)
- Redis Password: Enable and set strong password
- CORS Origins: Whitelist only your domains
- HTTPS: Enable HTTPS and redirect HTTP to HTTPS
- Environment: Set
NODE_ENV=production
- Generate and set strong JWT secrets
- Set strong database password
- Enable and set Redis password
- Configure CORS whitelist
- Enable HTTPS
- Review and update CSP rules
- Set up SSL/TLS certificates
- Configure firewall rules
- Enable database encryption at rest
- Set up backup encryption
- Configure log rotation
- Set up monitoring and alerts
- Review all environment variables
- Remove test/debug routes in production
- Update docker-compose.yml for production
- Rotate JWT secrets every 90 days
- Update dependencies monthly
- Review security logs weekly
- Audit user permissions quarterly
- Test backup restoration quarterly
- Review and update CSP rules as needed
- Monitor rate limit effectiveness
- Check for security vulnerabilities
- Use
.envfile (never commit to git) - Use
.env.exampleas template - Generate secrets with provided script
Recommended options:
- AWS Secrets Manager (recommended for AWS)
- HashiCorp Vault
- Azure Key Vault (for Azure)
- Google Secret Manager (for GCP)
- Environment variables (encrypted at rest)
For Docker Swarm:
echo "your_secret" | docker secret create jwt_secret -Update docker-compose.yml to use secrets:
secrets:
jwt_secret:
external: true-
Immediately:
- Rotate all affected secrets
- Invalidate all active sessions
- Review access logs
- Notify affected users
-
Investigation:
- Identify breach source
- Assess impact
- Document timeline
-
Prevention:
- Implement additional controls
- Update security procedures
- Train team members
If you discover a security vulnerability:
- DO NOT open a public issue
- Email: security@yourdomain.com
- Include:
- Description of vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if any)
- Never commit secrets to version control
- Always use parameterized queries
- Always validate and sanitize user input
- Never log sensitive information
- Always use HTTPS in production
- Always implement proper error handling
- Never expose internal error details to users
- Always use rate limiting on public endpoints
- Always implement proper authentication
- Never trust client-side validation alone
- Keep all dependencies up to date
- Monitor security advisories
- Regularly review access logs
- Implement network segmentation
- Use principle of least privilege
- Enable database audit logging
- Set up intrusion detection
- Implement DDoS protection
- Regular security audits
- Maintain incident response plan
- User data encryption
- Right to deletion
- Data export functionality
- Privacy policy
- Cookie consent
- Data retention policies
- Secure payment processing
- No storage of card data
- Use Stripe for payment handling
- Regular security audits
- Access control
- OWASP Top 10
- Node.js Security Best Practices
- Express Security Best Practices
- Helmet.js Documentation
This document should be reviewed and updated:
- After any security incident
- When new features are added
- At least quarterly
- When security best practices change
Last Updated: 2024-01-13