Repository navigation
apply full hardened headers to global 500 handlers - #1205
Closed
nandinigoyaldev wants to merge 1 commit into
Closed
nandinigoyaldev wants to merge 1 commit into
nandinigoyaldev wants to merge 1 commit into
Conversation
❌ Deploy Preview for bibliodrift-dm failed. Why did it fail? →
|
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.
Global 500 error handlers in backend/app.py were returning JSON responses with only a couple security headers set manually. This caused the full hardened security header set (including Content-Security-Policy, Strict-Transport-Security, etc.) to be missing/incomplete on 500 responses.
This PR ensures the full hardened header set produced by _apply_security_headers() is applied to 500 responses returned by:
@app.errorhandler(Exception)
@app.errorhandler(SQLAlchemyError)
What Changed
backend/app.py
Updated both global 500 handlers to call _apply_security_headers(response) before returning.
Removed the previous partial manual header setting to avoid divergence.
tests/test_security_headers_500.py
Added assertions that 500 responses produced by forced Exception and forced SQLAlchemyError contain the full hardened header set.
Testing
Added pytest coverage verifying these headers exist on 500 responses.
Run locally (if pytest is installed):
cd BiblioDrift && python3 -m pytest -q
Security Impact
Consistent defense-in-depth: browsers receive the same CSP/HSTS/etc. policies even when the server returns an error response.
Author: @goyaljiiiiii
Closes issue: #1204