feat(security): add Content-Security-Policy and security headers via Helmet#74
Open
rishab11250 wants to merge 1 commit into
Open
feat(security): add Content-Security-Policy and security headers via Helmet#74rishab11250 wants to merge 1 commit into
rishab11250 wants to merge 1 commit into
Conversation
…Helmet Add comprehensive security headers via the Helmet middleware, including a strict Content-Security-Policy with per-request nonces for inline scripts. Security headers set on every response: - Content-Security-Policy (nonce-based, blocks injected scripts) - X-Frame-Options: SAMEORIGIN (clickjacking prevention) - X-Content-Type-Options: nosniff - Strict-Transport-Security - Referrer-Policy: no-referrer Inline event handlers (onclick) converted to addEventListener for CSP compliance. Closes codepvg#59
2980187 to
ed44677
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.
Description
Add comprehensive security headers via the Helmet middleware, including a
strict Content-Security-Policy with per-request nonces for inline scripts.
This provides defense-in-depth against XSS — even if sanitization fails,
injected scripts are blocked by the browser.
Fixes #59
Changes Made
nonces, plus X-Frame-Options, X-Content-Type-Options, Referrer-Policy,
Strict-Transport-Security, and more. Added nonce injection middleware
that replaces
__NONCE__placeholders in HTML files with a freshcryptographic nonce per request.
nonce="__NONCE__"to inlinescript tag. Converted inline
onclickhandlers toaddEventListener.helmetdependency.CSP Directives
default-src 'self'script-src 'self' 'nonce-<random>'— inline scripts need noncestyle-src 'self' 'unsafe-inline' https://fonts.googleapis.comfont-src 'self' https://fonts.gstatic.comimg-src 'self' data:object-src 'none'— no pluginsframe-ancestors 'none'— clickjacking protectionscript-src-attr 'none'— blocks inline event handlersType of Change
Testing
Checklist