feat: add security headers to all responses#305
Open
allamiro wants to merge 1 commit into
Open
Conversation
X-Frame-Options: DENY, X-Content-Type-Options: nosniff and Referrer-Policy: no-referrer via DefaultHeaders middleware, registered outermost so even short-circuited responses (auth middleware 401s) carry them. CSP is left out for now since the index page relies on inline script injection.
4c4b0f2 to
9428184
Compare
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.
Fixes #279.
Change
Adds
DefaultHeadersmiddleware setting on every response:X-Frame-Options: DENYX-Content-Type-Options: nosniffReferrer-Policy: no-referrerThe middleware is registered last (= outermost in actix's reverse wrap order), which matters: responses short-circuited by the auth middleware would otherwise bypass it — verified during testing.
Content-Security-Policyis deliberately left out for now:embed_in_indexinjects an inline<script>into the index page, so a meaningful CSP needs frontend changes first (nonce or postMessage approach). Can be tracked separately.Testing
cargo test: 9/9 passSummary by cubic
Add default security headers to all HTTP responses using
actix_webDefaultHeaders. Middleware is registered outermost so short-circuited responses also include them; CSP is deferred due to an inline script in the index.DefaultHeaderslast to cover auth 401s and other short-circuits.Written for commit 4c4b0f2. Summary will update on new commits.