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

report-only headers don't work with SSR #97

Open
fabiommmoreira opened this issue Aug 9, 2023 · 0 comments
Open

report-only headers don't work with SSR #97

fabiommmoreira opened this issue Aug 9, 2023 · 0 comments

Comments

@fabiommmoreira
Copy link

Hey! I'm using the package in a repo that uses getServerSideProps. Following the strict CSP configuration, every getServerSideProps is wrapped with gsspWithNonce, and it works fine, setting the correct Content-Security-Policy header.

However, if reportOnly is set to true, it ends up setting an empty Content-Security-Policy-Report-Only header.
After some debugging, I've found out that although the headers are correctly set in the middleware, they get overridden with an empty value on the document getIinitialProps because getCspInitialProps uses a getter that contains a bug:

Screenshot 2023-08-09 at 11 54 11

Notice that the directives returned from the report-only block should use the report-only header, i.e.:

if (cspContentReportOnly) {
  return {
    directives: fromCspContent(cspContentReportOnly),
    reportOnly: true,
  };
}
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

No branches or pull requests

1 participant