Skip to content

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

@fabiommmoreira

Description

@fabiommmoreira

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,
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions