Skip to content

apply full hardened headers to global 500 handlers - #1205

Closed
nandinigoyaldev wants to merge 1 commit into
devanshi14malhotra:mainfrom
nandinigoyaldev:nandini
Closed

nandinigoyaldev wants to merge 1 commit into
devanshi14malhotra:mainfrom
nandinigoyaldev:nandini

Conversation

@nandinigoyaldev

@nandinigoyaldev nandinigoyaldev commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

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

@netlify

netlify Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for bibliodrift-dm failed. Why did it fail? →

Name Link
🔨 Latest commit a6f7f6c
🔍 Latest deploy log https://app.netlify.com/projects/bibliodrift-dm/deploys/6a2234ef3743520007e3bf3c

@nandinigoyaldev nandinigoyaldev closed this by deleting the head repository Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant