move away from express helmet #924
Closed
+720
−52
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.
resolves #920
Issue:
Express Helmet applies security headers globally, which causes HTML-specific headers like Content-Security-Policy and X-Download-Options to be applied to non-HTML routes.
Solution:
This PR replaces Express Helmet with a custom implementation that better distinguishes between general security headers, HTML-specific headers, and CORS-related configurations.
The new helmet function is inspired by
helmetandhttp-helmet.There are two layers currently, one is the tool itself, and one is a wrapper around the tool with defined configurations.
The new helmet tool
htmlflag is enabled.Cross-Origin-Resource-Policydefaults to'same-origin', but will default to'cross-origin'if thecorsflag is enabled.The wrapper around helmet
This is the function to be used for handling the projects security headers.
I added function overloads to clearly indicate that nonce is only required for html content type.
The tool will probably be extracted into another package if this proof of concept is accepted, but I thought it'd be a good idea to have the interface reviewed here first.
Test Plan
Checklist
Screenshots