question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: CSP should allow simultaneous `Content-Security-Policy-Report-Only` and `Content-Security-Policy-Report-Only`

See original GitHub issue

Currently an option exists to allow only reporting of violations:

options.reportOnly is a boolean, defaulting to false. If true, the Content-Security-Policy-Report-Only header will be set instead.

But according to https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#testing_your_policy it should be allowed to include both a Content-Security-Policy and Content-Security-Policy-Report-Only header.

Usage scenario Let’s say you have a current CSP policy, but want to evaluate a new, future policy. This means you want to continue using the one you already enforce, but at the same time evaluate the new one. Read more at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only

I think this in turn should remove options.reportOnly in a new major release. Users would instead get full functionality via:

app.use(
  helmet.contentSecurityPolicy({
    policy: {
      directives: {
        "script-src": ["'self'", "example.com"],
      },
    },
    reportPolicy: {
      directives: { // or reportPolicy
        "script-src": ["'self'", "example.com", "lolcat.com"],
      },
    },
  })
);

Unfortunately this means the top-level properties needs to be moved into a policy and reportPolicy property. This is to allow options such as options.useDefaults to be set per header.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thernstigcommented, Apr 3, 2022

@EvanHahn documentation it makes perfect sense, and I do think the workaround is good as-is. Thanks for a great project.

1reaction
EvanHahncommented, Apr 1, 2022

After some consideration, I don’t think I’m going to add this to Helmet for three reasons:

  1. I don’t want to increase Helmet’s surface area if I can help it.
  2. I don’t think this is a very common use case. I’m sure you’re not the only one to want this, but this isn’t a common feature request.
  3. The workaround is, in my opinion, straightforward.

We’d have to document the new feature anyway. Why not just document the workaround instead? I’ve added a note to the documentation (see 7848f5aae059810e05147c5f4d4ae94a52f950c2) to make this more obvious for people in the future.

I’m going to close this issue because I think it’s resolved, but let me know if you disagree.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content-Security-Policy-Report-Only - HTTP - MDN Web Docs
The HTTP Content-Security-Policy-Report-Only response header allows web developers to experiment with policies by monitoring (but not ...
Read more >
Content Security Policy Level 2 - W3C
A server MAY send different Content-Security-Policy-Report-Only header field values with different representations of the same resource or with ...
Read more >
Using Content Security Policy (CSP) to Secure Web Applications
Before you go live with your CSP directives, you can use the Content-Security-Policy-Report-Only header instead of Content-Security-Policy . In ...
Read more >
Content Security Policy - All you need to know
To enable this feature, set the Content-Security-Policy-Report-Only directive by adding it as a response header for your site. Response header:
Read more >
HTTP headers | Content-Security-Policy-Report-Only
The HTTP Content-Security-Policy-Report-Only response header allows the web developers to test the policies by keeping an eye on their ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found