Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support adding CSP nonce with content-security-policy-report-only header #48969

Closed

Conversation

danieltott
Copy link
Contributor

Checklist:

Description:

Currently, renderToHTMLOrFlight in app-render pulls out a nonce value from a content-security-policy header for use in generating script tags:

const csp = req.headers['content-security-policy']

This is missing the ability to use a content-security-policy-report-only header. Many times this is a required step to enabling a CSP - by shipping a CSP with report-only and collecting reports before actually blocking resources.

Changes:

  • Added ability to check content-security-policy-report-only header in renderToHTMLOrFlight()
  • Added test to verify nonce is correctly applied when content-security-policy-report-only header exists

@danieltott danieltott force-pushed the danieltott-csp-report-only branch from 62116ba to 6d3f587 Compare August 18, 2023 20:39
@danieltott danieltott requested a review from ztanner as a code owner August 18, 2023 20:39
@danieltott
Copy link
Contributor Author

@shuding if you have time to review this one, it would be very excellent to get this one merged along with #54059

@christianvuerings
Copy link
Contributor

@timneutkens @ijjk @shuding @leerob could either one of you take a look at this PR? It blocks us from launching CSP on our website.

Also created an updated #59071 which fixes the merge conflicts in this PR

ztanner added a commit that referenced this pull request Dec 1, 2023
…eader (#59071)

**Note**: this is a 1-to-1 copy of #48969 by @danieltott with all the
merge conflicts fixed.

## Checklist

* Fixes #48966
* Tests added to
`test/production/app-dir/subresource-integrity/subresource-integrity.test.ts`

## Description

Currently `renderToHTMLOrFlight` in app-render pulls out a nonce value
from a `content-security-policy` header for use in generating script
tags:


https://github.com/vercel/next.js/blob/e7c9d3c051e6027cf187e0d70565417d6037e37c/packages/next/src/server/app-render/app-render.tsx#L1204

That misses the ability to use a [content-security-policy-report-only
header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only).
Many times this is a required step to enabling a CSP - by shipping a CSP
with report-only and collecting reports before actually blocking
resources.

## Changes

* Added ability to check `content-security-policy-report-only` header in
`renderToHTMLOrFlight()`
* Added test to verify `nonce` is correctly applied when
`content-security-policy-report-only` header exists

Co-authored-by: Dan Ott <[email protected]>
Co-authored-by: Zack Tanner <[email protected]>
@ztanner
Copy link
Member

ztanner commented Dec 1, 2023

Closed in favor of #59071 -- applied you as a co-author on the PR, thank you!

@ztanner ztanner closed this Dec 1, 2023
@danieltott danieltott deleted the danieltott-csp-report-only branch December 1, 2023 13:52
@danieltott
Copy link
Contributor Author

Thanks @ztanner 🙌

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content Security Policy nonce support doesn't support content-security-policy-report-only
4 participants