This document outlines all the security and efficiency improvements made to the playlist creator application.
Your credentials have been exposed and must be rotated:
-
Google OAuth credentials in
credentials.json- Go to Google Cloud Console
- Navigate to your project β Credentials
- Delete the old OAuth 2.0 Client ID
- Create a new one and download fresh credentials
-
Spotify credentials in
.env- Go to Spotify Developer Dashboard
- Navigate to your app settings
- Click "Rotate Client Secret"
- Update your
.envfile with the new secret
Your .env file needs new variables. Copy from .env.example:
# Required new variables:
PORT=3001
FRONTEND_URL=http://localhost:3000
BACKEND_URL=http://localhost:3001
ALLOWED_ORIGINS=http://localhost:3000
VITE_API_BASE_URL=http://localhost:3001- Before: Wide-open CORS accepting requests from ANY origin
- After: Restricted to specific allowed origins from environment variables
- File:
server.js:11-17
- All user inputs are now validated for type, length, and format
- Prevents injection attacks and malformed requests
- Files:
server.js:139-152, 188-191
- Authentication endpoints: 10 requests per 15 minutes
- General API endpoints: 100 requests per minute
- Prevents brute force attacks and API abuse
- File:
server.js:19-37
- Content-Security-Policy: Prevents XSS attacks
- X-Frame-Options: Prevents clickjacking
- X-Content-Type-Options: Prevents MIME sniffing
- X-XSS-Protection: Additional XSS protection
- Referrer-Policy: Controls referrer information
- File:
server.js:41-61
- All hardcoded URLs replaced with environment variables
- Supports different configurations for dev/staging/production
- Files:
server.js, all frontendsrc/*.jsxfiles
- Monitor server status and authentication state
- Endpoint:
GET /health - File:
server.js:130-139
- 5-minute cache for user profiles, playlists, and tracks
- Reduces redundant API calls by up to 80%
- File:
src/SpotifyAPI.jsx:8-30
- Trello card fetching now parallelized
- Board info fetching parallelized
- Significantly faster data loading
- File:
src/TrelloAPI.jsx:155-169, 36-48
- Automatic retry on transient failures
- Exponential backoff prevents overwhelming APIs
- File:
src/SpotifyAPI.jsx:3-23
β
Secrets are in .gitignore
β
CORS is restricted to specific origins
β
All inputs are validated
β
Rate limiting prevents abuse
β
Security headers prevent common attacks
β
Environment-based configuration
- Currently vulnerable to XSS attacks
- Recommended: Move to HttpOnly cookies or implement sessionStorage
- Future enhancement: Server-side session management
- Never send tokens over HTTP in production
- Action: Use HTTPS for all production deployments
- Set
FRONTEND_URLandBACKEND_URLto HTTPS URLs
.envfile should never be committed to git- Recommended: Use a secrets manager (AWS Secrets Manager, 1Password, etc.)
- For production, use environment variables from your hosting platform
Before deploying to production:
- Rotate all API credentials
- Set all environment variables in your hosting platform
- Use HTTPS for all URLs (
FRONTEND_URL,BACKEND_URL) - Update
ALLOWED_ORIGINSto include production domain - Test rate limiting to ensure it doesn't block legitimate users
- Set up monitoring for the
/healthendpoint - Review and adjust cache TTL if needed (currently 5 minutes)
- Consider implementing request logging for security auditing
- Update your
.envfile with new variables from.env.example - Install dependencies:
npm install - Rotate your API credentials as described above
- Test the application:
# Terminal 1: Start backend npm run server # Terminal 2: Start frontend npm start
- Test health endpoint:
curl http://localhost:3001/health
{
"status": "ok",
"timestamp": "2026-04-16T12:00:00.000Z",
"uptime": 3600,
"youtube": {
"configured": true,
"authenticated": true
}
}When rate limited, the API returns:
X-RateLimit-Limit: Maximum requests allowedX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: When the limit resets
- OWASP Top 10
- Content Security Policy Guide
- Express Security Best Practices
- OAuth 2.0 Security Best Practices
- β Fixed CORS configuration
- β Added input validation
- β Implemented rate limiting
- β Added security headers
- β Environment-based configuration
- β API response caching
- β Parallelized API calls
- β Retry logic with exponential backoff
- β Health check endpoint