-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
User Story
As a security-conscious developer,
I want to replace the wildcard CORS origin in backend/app/main.py with environment-specific allowed origins
so that the API is protected against cross-site request forgery attacks in production environments.
Background
The current CORS configuration in backend/app/main.py uses a permissive wildcard (origins = ["*"]), which:
- Creates security risks by allowing unrestricted cross-origin requests in production
- Violates security best practices for APIs exposed to public traffic
- Exposes the backend to potential CSRF attacks when combined with cookie/auth token usage
The codebase uses Docker Compose for environment management, making it feasible to implement environment-specific allowlists (e.g., only permitting http://localhost:3000 in development while restricting to production domains in live environments).
Acceptance Criteria
- Modify
backend/app/main.pyto:- Load allowed origins from environment variable
CORS_ALLOWED_ORIGINS(comma-separated values) - Default to empty list if environment variable not set
- Replace hardcoded
origins = ["*"]with origins derived from environment variable
- Load allowed origins from environment variable
- Update
docker-compose.ymlto:- Set
CORS_ALLOWED_ORIGINS=http://localhost:3000for backend service in development - Include placeholder comments for staging/production configurations
- Set
- Validation steps:
- In development environment, frontend at
http://localhost:3000can successfully fetch from backend API - Requests from non-allowlisted domains (test via
curl -H "Origin: http://malicious.com" -I http://localhost:80) return403 Forbidden - Environment variable changes persist after container rebuilds
- In development environment, frontend at