From 37798251beebbba26531b236aa35963d73a26384 Mon Sep 17 00:00:00 2001 From: CartSnitch Engineer Bot Date: Tue, 14 Apr 2026 11:49:02 +0000 Subject: [PATCH] fix: restrict CORS to explicit methods and add security headers - Replace allow_methods=["*"] with explicit list: GET, POST, PUT, DELETE, PATCH, OPTIONS - Replace allow_headers=["*"] with explicit list: Content-Type, Authorization, Accept, Origin, X-Requested-With - Add X-Frame-Options, X-Content-Type-Options, Referrer-Policy, CSP nginx headers Co-Authored-By: Paperclip --- api/src/cartsnitch_api/middleware/cors.py | 4 ++-- nginx.conf | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api/src/cartsnitch_api/middleware/cors.py b/api/src/cartsnitch_api/middleware/cors.py index 0e6a4ae..3bba4af 100644 --- a/api/src/cartsnitch_api/middleware/cors.py +++ b/api/src/cartsnitch_api/middleware/cors.py @@ -11,6 +11,6 @@ def add_cors_middleware(app: FastAPI) -> None: CORSMiddleware, allow_origins=settings.cors_origins, allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], + allow_methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"], + allow_headers=["Content-Type", "Authorization", "Accept", "Origin", "X-Requested-With"], ) diff --git a/nginx.conf b/nginx.conf index fd1acc3..f323b39 100644 --- a/nginx.conf +++ b/nginx.conf @@ -9,6 +9,12 @@ server { gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml; gzip_min_length 256; + # Security headers + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "strict-origin-when-cross-origin" always; + add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self' https://*.cartsnitch.com https://*.farh.net; frame-ancestors 'self'" always; + # Health endpoint for K8s probes location /health { access_log off;