fix(#45): Add HTTP security headers (CSP, HSTS, X-Frame-Options, X-Content-Type-Options)#181
Merged
Conversation
…ns, X-Content-Type-Options) - Add SecurityHeadersMiddleware to inject CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy on all responses - Enable Strict-Transport-Security only when ENV_VERSION=PROD - Add security headers to nginx production config (quantara.conf) - Add security headers to nginx dev config (quantara_dev.conf) - Add unit tests for middleware registration, header presence, and HSTS environment gating Closes Quantarq#45
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds HTTP security headers to FastAPI responses (via ASGI middleware) and nginx configs as defense-in-depth against XSS, clickjacking, MIME-sniffing, and protocol-downgrade attacks.
Changes
FastAPI middleware (
quantara/web_app/api/middleware.py)SecurityHeadersMiddlewareASGI middleware that injects:Content-Security-Policy: restricts sources to self, stellar.org, and FreighterX-Frame-Options: DENY: prevents clickjackingX-Content-Type-Options: nosniff: prevents MIME-sniffingReferrer-Policy: strict-origin-when-cross-origin: controls referrer infoStrict-Transport-Security(only whenENV_VERSION=PROD): enforces HTTPSNginx configs
quantara/frontend/quantara.conf: Added security headeradd_headerdirectivesquantara/frontend/quantara_dev.conf: Added security headeradd_headerdirectives with shorter HSTS (1 day) for devTests
quantara/web_app/tests/test_security_headers.py: Tests for middleware registration, header presence, and HSTS environment gatingCloses #45