Commit cbb51c8
committed
fix(security): restrict CORS to specific allowed origins
Fixes #4
SECURITY VULNERABILITY:
Previous configuration allowed ANY origin to make authenticated
requests, enabling CSRF attacks from malicious websites.
Changes:
- Replace allow_origins=["*"] with environment-based configuration
- Add ALLOWED_ORIGINS environment variable (comma-separated list)
- Restrict allow_methods to specific HTTP methods (GET, POST, PUT, DELETE, OPTIONS)
- Restrict allow_headers to required headers (Authorization, Content-Type)
- Default to http://localhost:3000 for local development
Configuration:
- Development: ALLOWED_ORIGINS=http://localhost:3000
- Production: ALLOWED_ORIGINS=https://app.vercel.app,https://custom-domain.com
Testing:
✅ Verified localhost:3000 receives CORS headers
✅ Verified unauthorized origins are blocked
✅ Backend health check confirms proper CORS restrictions
Files modified:
- backend/main.py: Updated CORS middleware configuration
- .env.example: Added ALLOWED_ORIGINS documentation
- backend/.env.example: Added ALLOWED_ORIGINS with example
Impact: Prevents cross-site request forgery attacks in production1 parent f9fc137 commit cbb51c8
3 files changed
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
45 | 47 | | |
46 | | - | |
47 | | - | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
0 commit comments