This document outlines security best practices for developing and deploying the VibraGuard system.
NEVER commit sensitive credentials to version control!
All sensitive configuration values should be stored in environment variables:
- Database credentials (
DB_USERNAME,DB_PASSWORD) - Twilio API credentials (
TWILIO_ACCOUNT_SID,TWILIO_AUTH_TOKEN) - Phone numbers (
MY_PHONE_NUMBER,FRIEND_PHONE_NUMBER) - Server URLs and endpoints
Local Development:
- Copy
.env.exampleto.env - Fill in your actual values
- The
.envfile is already in.gitignoreand will not be committed
Production Deployment:
- Use your cloud provider's secrets management:
- Google Cloud: Secret Manager
- AWS: Secrets Manager or Parameter Store
- Azure: Key Vault
- Set environment variables in your deployment configuration
✅ DO:
- Use environment variables for credentials
- Use strong, randomly generated passwords
- Limit database user permissions to only what's needed
- Use SSL/TLS for database connections in production
- Regularly update PostgreSQL to patch security vulnerabilities
❌ DON'T:
- Hardcode passwords in
application.properties - Use default passwords like "mypassword" in production
- Grant superuser access to application database users
- Expose database ports to the public internet
✅ DO:
- Use authentication for MQTT broker
- Implement ACLs (Access Control Lists) to restrict topic access
- Use TLS/SSL for MQTT connections in production
- Monitor MQTT traffic for suspicious activity
❌ DON'T:
- Leave MQTT broker without authentication
- Allow anonymous connections in production
- Use unencrypted MQTT in production environments
✅ DO:
- Implement rate limiting on API endpoints
- Use HTTPS in production
- Validate and sanitize all input data
- Implement proper CORS policies
- Add authentication/authorization for sensitive endpoints
❌ DON'T:
- Expose admin endpoints without authentication
- Use HTTP in production
- Trust client-side data without validation
- Allow unlimited API requests (prone to DoS attacks)
✅ DO:
- Always close database connections
- Properly clean up MQTT clients in finally blocks
- Use connection pooling for efficiency
- Monitor resource usage and set limits
❌ DON'T:
- Leave connections open indefinitely
- Create new connections without cleanup
- Ignore resource leaks
This PR includes the following security improvements:
- Replaced hardcoded credentials with environment variables in
application.properties - Fixed MQTT client resource leaks - proper cleanup in finally blocks
- Removed hardcoded phone numbers from configuration files
- Added environment variable support to all test scripts
- Created
.env.exampletemplate for safe credential management
Run security checks regularly:
# Backend (Maven)
cd backend
mvn dependency-check:check
# Frontend (npm)
cd frontend
npm audit
npm audit fix # Fix automatic issues# Backend
mvn versions:display-dependency-updates
# Frontend
npm outdated
npm update- Never commit test credentials
- Use mock services for testing external APIs
- Rotate API keys regularly
- Use separate credentials for test environments
If credentials are accidentally committed:
- Immediately rotate all exposed credentials
- Remove from git history using
git filter-branchor BFG Repo-Cleaner - Force push to remote repository
- Notify team members to pull latest changes
- Review access logs for unauthorized usage
- All sensitive data moved to environment variables
-
.envfiles excluded from version control - Database using strong passwords
- HTTPS/TLS enabled for all connections
- MQTT broker authentication enabled
- Firewall rules properly configured
- Regular security updates scheduled
- Monitoring and alerting configured
- Backup and disaster recovery plan in place
If you discover a security vulnerability, please:
- DO NOT open a public GitHub issue
- Email the security team directly
- Provide details about the vulnerability
- Allow time for a fix before public disclosure