You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The FastAPI application created in QueryWeaver/api/app_factory.py installs several middlewares (ProxyHeadersMiddleware, SessionMiddleware, custom SecurityMiddleware) but never sets an HTTP Strict-Transport-Security (HSTS) response header. Consequently, every HTTPS response is delivered without Strict-Transport-Security, leaving clients vulnerable to downgrade and man-in-the-middle attacks.
🔍 Evidence
Repo-wide search shows zero occurrences of "Strict-Transport-Security" → no code path sets the header.
api/app_factory.py (around lines 70-170)
The create_app() function builds the FastAPI instance and attaches middleware, but none inject an HSTS header.
All API routes (/graphs, /database, /tokens, OAuth flows) and the React SPA fall through this middleware stack, so the omission affects the entire service.
💡 Suggested Minimal Fix
Add a lightweight middleware that injects the HSTS header for HTTPS requests (detected via request.url.scheme or X-Forwarded-Proto) and allow disabling via env-var for local HTTP development.
diff --git a/QueryWeaver/api/app_factory.py b/QueryWeaver/api/app_factory.py
@@
-from starlette.middleware.base import BaseHTTPMiddleware+from starlette.middleware.base import BaseHTTPMiddleware
@@
class SecurityMiddleware(BaseHTTPMiddleware):
@@
+class HSTSMiddleware(BaseHTTPMiddleware):+ """Add Strict-Transport-Security header to HTTPS responses."""++ def __init__(self, app, enabled: bool = True, header_value: str | None = None):+ super().__init__(app)+ self.enabled = enabled+ self.header_value = (+ header_value or "max-age=31536000; includeSubDomains; preload"+ )++ async def dispatch(self, request: Request, call_next):+ response = await call_next(request)++ if not self.enabled:+ return response++ scheme = request.headers.get("x-forwarded-proto", request.url.scheme)+ if scheme == "https" and "strict-transport-security" not in response.headers:+ response.headers["Strict-Transport-Security"] = self.header_value++ return response
@@
- app.add_middleware(ProxyHeadersMiddleware, trusted_hosts="*")+ app.add_middleware(ProxyHeadersMiddleware, trusted_hosts="*")++ # --- Security: Enforce HSTS on HTTPS deployments ---+ hsts_enabled = os.getenv("ENABLE_HSTS", "true").lower() in ("1", "true", "yes")+ app.add_middleware(HSTSMiddleware, enabled=hsts_enabled)
⚠️ Risk Assessment
Low risk: Adds only response headers; no changes to request processing or core business logic.
Requires proxy/load-balancer to forward X-Forwarded-Proto for correct HTTPS detection. Document this requirement.
Local/plain-HTTP development can disable via ENABLE_HSTS=false.
✅ Test Recommendations
Unit/ASGI Test: Using TestClient, send a request with header x-forwarded-proto: https; assert Strict-Transport-Security equals max-age=31536000; includeSubDomains; preload.
Repeat with x-forwarded-proto: http (or no header) – header should be absent when not HTTPS or when ENABLE_HSTS=false.
Integration/Staging: Deploy behind the real proxy, curl any endpoint over HTTPS and verify header presence.
🎯 Confidence
High (0.86) – Direct inspection confirmed no HSTS header in codebase, and fix is straightforward.
HSTS is already live on staging — api/app_factory.py sets Strict-Transport-Security: max-age=31536000; includeSubDomains; preload on every response, and tests/test_hsts_header.py pins it. This issue is done and can be closed.
The remaining security headers (X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy, Content-Security-Policy) are still outstanding and are covered by #431.
⚠️ Note for whoever lands #431: app/src/pages/Index.tsx fetches https://api.github.com/repos/FalkorDB/QueryWeaver for the star count, so a bare connect-src 'self' will break the UI in production only. It needs connect-src 'self' https://api.github.com.
Activity
overcut-ai commentedon Jan 24, 2026
Completed Working on "Automated Ticket Triage "
✅ Workflow completed successfully.
👉 View complete log
overcut-ai commentedon Jan 24, 2026
Completed Working on "Auto Root Cause Analysis"
✅ Workflow completed successfully.
👉 View complete log
overcut-ai commentedon Jan 24, 2026
🛠 Root Cause Analysis & Fix Proposal
📌 Summary of Root Cause
The FastAPI application created in
QueryWeaver/api/app_factory.pyinstalls several middlewares (ProxyHeadersMiddleware,SessionMiddleware, customSecurityMiddleware) but never sets anHTTP Strict-Transport-Security(HSTS) response header. Consequently, every HTTPS response is delivered withoutStrict-Transport-Security, leaving clients vulnerable to downgrade and man-in-the-middle attacks.🔍 Evidence
"Strict-Transport-Security"→ no code path sets the header.api/app_factory.py(around lines 70-170)create_app()function builds the FastAPI instance and attaches middleware, but none inject an HSTS header.All API routes (
/graphs,/database,/tokens, OAuth flows) and the React SPA fall through this middleware stack, so the omission affects the entire service.💡 Suggested Minimal Fix
Add a lightweight middleware that injects the HSTS header for HTTPS requests (detected via
request.url.schemeorX-Forwarded-Proto) and allow disabling via env-var for local HTTP development.X-Forwarded-Protofor correct HTTPS detection. Document this requirement.ENABLE_HSTS=false.✅ Test Recommendations
TestClient, send a request with headerx-forwarded-proto: https; assertStrict-Transport-Securityequalsmax-age=31536000; includeSubDomains; preload.x-forwarded-proto: http(or no header) – header should be absent when not HTTPS or whenENABLE_HSTS=false.🎯 Confidence
High (
0.86) – Direct inspection confirmed no HSTS header in codebase, and fix is straightforward.Labels applied:
rca-proposed,conf-highAnchel123 commentedon Aug 24, 2026
HSTS is already live on
staging—api/app_factory.pysetsStrict-Transport-Security: max-age=31536000; includeSubDomains; preloadon every response, andtests/test_hsts_header.pypins it. This issue is done and can be closed.The remaining security headers (
X-Content-Type-Options,X-Frame-Options,Referrer-Policy,Permissions-Policy,Content-Security-Policy) are still outstanding and are covered by #431.app/src/pages/Index.tsxfetcheshttps://api.github.com/repos/FalkorDB/QueryWeaverfor the star count, so a bareconnect-src 'self'will break the UI in production only. It needsconnect-src 'self' https://api.github.com.