The CAC E-commerce PWA takes security seriously. This document outlines security best practices, known security measures, and how to report vulnerabilities.
| Version | Supported |
|---|---|
| 1.0.x | ✅ |
CRITICAL: Never commit .env files to version control!
Always generate strong random secrets for production:
# Generate JWT_SECRET (64 bytes)
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
# Or use the provided script
node scripts/generate-secrets.jsBefore deploying to production, ensure:
-
JWT_SECRETis a strong random value (minimum 64 bytes) -
DATABASE_URLuses a strong database password -
NODE_ENVis set toproduction -
FRONTEND_URLis set to your actual domain - All
.envfiles are listed in.gitignore - No hardcoded secrets in source code
-
Use Strong Passwords
- Database passwords should be at least 16 characters
- Use a mix of uppercase, lowercase, numbers, and symbols
- Never use default passwords in production
-
Connection Security
- Use SSL/TLS for database connections in production
- Restrict database access to specific IP addresses
- Use separate database users for different environments
-
Backup Strategy
- Implement automated daily backups
- Store backups in a secure, encrypted location
- Test restore procedures regularly
-
Password Security
- Passwords are hashed using bcrypt (10 rounds minimum)
- Never store passwords in plain text
- Enforce minimum password requirements
-
JWT Tokens
- Tokens are stored in HttpOnly cookies to prevent XSS attacks
- Token expiration is set to 7 days by default
- Separate tokens for users and admins
-
Session Management
- Implement logout functionality that clears tokens
- Consider implementing token refresh mechanism
- Monitor for suspicious authentication attempts
-
File Type Validation
- Only PNG, JPG, and JPEG files are allowed
- File types are validated by MIME type and extension
- Maximum file size is 10MB
-
File Storage
- Files are stored with UUID filenames to prevent conflicts
- Consider migrating to cloud storage (AWS S3, Cloudinary) for production
- Implement file scanning for malware in production
-
Access Control
- Only authenticated admins can upload files
- File uploads are protected by AdminJwtAuthGuard
-
CORS Configuration
- CORS is configured to allow only specific origins
- Update
FRONTEND_URLin production to your actual domain - Never use
*for CORS origin in production
-
Rate Limiting
- Throttler is configured to prevent brute force attacks
- Consider implementing more granular rate limits per endpoint
- Monitor for unusual traffic patterns
-
Input Validation
- All inputs are validated using class-validator
- DTOs define strict type checking
- Sanitize user inputs to prevent injection attacks
- Update all environment variables
- Enable HTTPS/SSL certificates
- Configure secure cookies (
secure: truein production) - Disable Swagger documentation in production
- Set up error monitoring (e.g., Sentry)
- Configure logging and monitoring
- Review and update CORS settings
- Implement rate limiting
- Set up automated backups
- Configure firewall rules
Always use HTTPS in production:
// In production, update cookie settings
res.cookie('access_token', token, {
httpOnly: true,
secure: true, // Set to true in production
sameSite: 'strict',
maxAge: 3600000,
})-
Dependency Management
# Regularly audit dependencies npm audit npm audit fix # Update dependencies npm update
-
Security Headers
- Helmet middleware is configured for security headers
- CSP, XSS protection, and other headers are enabled
-
Sensitive Data
- Never log sensitive information (passwords, tokens, etc.)
- Use environment variables for all secrets
- Implement audit logging for admin actions
- ✅ JWT authentication with HttpOnly cookies
- ✅ Bcrypt password hashing
- ✅ Helmet security headers
- ✅ CORS configuration
- ✅ Input validation with class-validator
- ✅ File upload restrictions
- ✅ Admin authorization guards
- ✅ Rate limiting with Throttler
- ✅ SQL injection prevention (Prisma ORM)
- 🔄 Two-factor authentication (2FA)
- 🔄 Email verification for user registration
- 🔄 Account lockout after failed login attempts
- 🔄 Password reset functionality
- 🔄 Audit logging for all admin actions
- 🔄 CAPTCHA for login/registration
- 🔄 Content Security Policy (CSP) headers
- 🔄 Automated security scanning in CI/CD
If you discover a security vulnerability, please follow these steps:
- Do NOT open a public issue
- Email the security team at:
security@example.com(replace with your actual email) - Include the following information:
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Suggested fix (if available)
- Initial Response: Within 48 hours
- Status Update: Within 7 days
- Fix Timeline: Depends on severity
- Critical: Within 24-48 hours
- High: Within 7 days
- Medium: Within 30 days
- Low: Next release cycle
Security updates will be released as soon as possible after a vulnerability is confirmed and fixed. Users will be notified through:
- GitHub Security Advisories
- Release notes
- Email notifications (if provided)
This project aims to follow security best practices from:
- OWASP Top 10
- CWE Top 25
- Node.js Security Best Practices
This security policy is part of the CAC project and is licensed under the MIT License.
Last Updated: 2025-01-15
For questions about this security policy, please contact the maintainers.