What was fixed:
- Removed hardcoded SerpAPI key from
SerpAPIClient.java - Replaced with secure configuration loading
- All API keys now loaded from environment variables
Current Implementation:
// β
SECURE - Loads from environment variables
private static final String API_KEY = ApplicationConfig.getInstance().getSerpApiKey();
// β INSECURE - Never do this
// private static final String API_KEY = "actual_api_key_here";Set these environment variables before running the application:
# Database Configuration
export DB_HOST=localhost
export DB_PORT=3306
export DB_NAME=jobrec
export DB_USERNAME=your_db_user
export DB_PASSWORD=your_secure_db_password
# Redis Configuration
export REDIS_HOST=localhost
export REDIS_PORT=6379
export REDIS_PASSWORD=your_redis_password
# API Keys (REQUIRED)
export SERPAPI_KEY=your_serpapi_key_here
export EDENAI_KEY=your_edenai_key_here
# Application Environment
export APP_ENVIRONMENT=prod- API Key Protection: All API keys loaded from environment variables
- Input Validation: Comprehensive validation in
ValidationUtil - SQL Injection Prevention: Prepared statements used throughout
- XSS Protection: Input sanitization implemented
- Error Handling: No sensitive information in error messages
- Session Management: Secure session handling
- Password Security: MD5 hashing (consider upgrading to bcrypt)
- Configuration Security: Sensitive data in environment variables
- Password Hashing: Upgrade from MD5 to bcrypt or Argon2
- HTTPS: Implement SSL/TLS in production
- Rate Limiting: Add API rate limiting
- CORS: Configure proper CORS policies
- Security Headers: Add security headers (CSP, HSTS, etc.)
- Audit Logging: Log security events
- Dependency Scanning: Regular security dependency updates
-
Immediate Actions:
# Revoke compromised keys immediately # SerpAPI: Go to https://serpapi.com/manage-api-key # EdenAI: Go to https://www.edenai.co/account # Generate new API keys # Update environment variables # Restart application
-
Investigation:
- Check git history for exposed keys
- Review access logs
- Identify scope of exposure
-
Prevention:
- Use git-secrets or similar tools
- Implement pre-commit hooks
- Regular security audits
If keys were committed to git:
# Remove sensitive data from git history
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch path/to/file/with/keys' \
--prune-empty --tag-name-filter cat -- --all
# Force push (WARNING: This rewrites history)
git push origin --force --all
git push origin --force --tagsMonitor these security events:
# Failed login attempts
grep "Authentication failed" /opt/tomcat/logs/application.log
# Invalid input attempts
grep "validation failed" /opt/tomcat/logs/application.log
# Database errors (potential injection attempts)
grep "SQLException" /opt/tomcat/logs/application.log
# API errors
grep "API call.*failed" /opt/tomcat/logs/application.logRegular security health checks:
# Check for hardcoded secrets
grep -r "password\|secret\|key" --include="*.java" src/
# Check for TODO security items
grep -r "TODO.*security\|FIXME.*security" --include="*.java" src/
# Verify environment variables
echo "Checking required environment variables..."
[ -z "$SERPAPI_KEY" ] && echo "β SERPAPI_KEY not set"
[ -z "$EDENAI_KEY" ] && echo "β EDENAI_KEY not set"
[ -z "$DB_PASSWORD" ] && echo "β DB_PASSWORD not set"# Set secure permissions
chmod 600 .env
chown app:app .env
# Verify no secrets in code
find . -name "*.java" -exec grep -l "api.*key\|password.*=" {} \;
# Check firewall rules
ufw status
# Verify SSL configuration
openssl s_client -connect localhost:8443 -servername localhostCreate .env.template for team members:
# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_NAME=jobrec
DB_USERNAME=your_username
DB_PASSWORD=your_password
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
# API Keys
SERPAPI_KEY=your_serpapi_key
EDENAI_KEY=your_edenai_key
# Application
APP_ENVIRONMENT=dev- No hardcoded credentials
- Input validation on all user inputs
- Proper error handling without information leakage
- SQL injection prevention (prepared statements)
- XSS prevention (input sanitization)
- Secure session management
- Proper logging without sensitive data
- Never commit secrets: Use environment variables
- Validate all inputs: Use
ValidationUtilfor all user inputs - Sanitize outputs: Prevent XSS attacks
- Use prepared statements: Prevent SQL injection
- Log securely: No sensitive data in logs
- Handle errors gracefully: No stack traces to users
- Keep dependencies updated: Regular security updates
For security issues:
- Security Issues: Create a private issue or contact maintainers
- Vulnerability Reports: Follow responsible disclosure
- Emergency Contact: Use secure communication channels
Author: Leo Ji
Last Updated: December 2024
Security Review: Required before each release