-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix(proxy): omit CSP report only header #7936
Conversation
Thanks for taking the time to open a PR!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdemjanenko There are some linting errors in the spec file.
You mention:
This fixes a lot of unsafe-inline script-src warnings that I have seen when running cypress.
Can you describe this in more detail? Do you have a screenshot or example of the errors that typically show?
Here is the console warning that shows up (and logged to our CSP reporting service): As for the Linting warnings:
I also noticed that some tests failed because of a 1 character shift in the CLI output
Do we know why this happens? How can we make this more stable? |
This comment has been minimized.
This comment has been minimized.
8c3c406
to
d612288
Compare
This comment has been minimized.
This comment has been minimized.
Since Cypress omits the blocking CSP header, it should also omit the report-only CSP header. This fixes a lot of `unsafe-inline` script-src warnings that I have seen when running cypress.
1a2d480
to
5c90f53
Compare
Dismissing my initial review as addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdemjanenko I see why you want to disable Content-Security-Policy-Report-Only
- Cypress rewrites JS, so it causes many hash mismatches to throw warnings (due to the require-sri-for
)
However, there are many other CSP directives, all of which can also be used with Report-Only
: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
In light of this, I do not think the correct approach is to completely strip the Content-Security-Policy-Report-Only
header. Many of the warnings it throws are still useful to developers within Cypress.
You may have seen how we treat the Feature-Policy
header - only the document-domain
directive adversely affects Cypress, so we just strip out that single directive if it exists, without removing the other Feature-Policy
directives:
cypress/packages/proxy/lib/http/response-middleware.ts
Lines 246 to 267 in d6f159b
// https://github.com/cypress-io/cypress/issues/6480 | |
const MaybeStripDocumentDomainFeaturePolicy: ResponseMiddleware = function () { | |
const { 'feature-policy': featurePolicy } = this.incomingRes.headers | |
if (featurePolicy) { | |
const directives = parseFeaturePolicy(<string>featurePolicy) | |
if (directives['document-domain']) { | |
delete directives['document-domain'] | |
const policy = stringifyFeaturePolicy(directives) | |
if (policy) { | |
this.res.set('feature-policy', policy) | |
} else { | |
this.res.removeHeader('feature-policy') | |
} | |
} | |
} | |
this.next() | |
} |
So what do you think about using a similar approach for Content-Security-Policy-Report-Only
? Instead of stripping the entire header, you could only strip the specific directives that conflict with Cypress.
The decision that gets made for Personally, I don't find much value in watching CSP reports come in from Cypress, especially because Cypress' internals do a bunch of rewriting. |
That's a good point, if we decide to only strip certain CSP directives, it should apply to both headers equally.
Yeah, it would be ideal if we could eliminate the warnings caused by rewriting, while keeping the rest. Are the |
Yes, |
Ok, you are probably seeing cypress/packages/proxy/lib/http/util/inject.ts Lines 1 to 25 in cf1432e
In light of this, the best solution IMO is to always add a I think this will get rid of these Cypress-only warnings while letting us retain the behavior of CSP, which helps accomplish the goal of making Cypress tests closer to matching the "real world". What do you think? |
Slightly better idea: we could always add |
I like the nonce idea best. Adding |
Converting this to a draft since it's not ready for review. @sdemjanenko if you pick this back up again, please feel free to tag me with any questions/when you are ready for review. |
@flotwig I'm actually pretty annoyed by this. Given your responses indicating the desire for new functionality, I assumed you and your team would be taking that on. I think this commit is independent of that work. This commit just brings the same behavior to the report only header as already exists for the normal header. I would ask that you reconsider pulling in this change as is and then put that additional functionality on your roadmap for your team to do. |
I assumed the opposite 😄 Apologies for not communicating more clearly on that point.
Thanks for the reminder, I see what you mean now. With that context, I think this is fine to merge as-is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'll open an issue to track the discussion we had around more selectively supressing the CSP and CSP-Report headers.
Thanks for the quick response. I should have followed up earlier as well. I am looking forward to seeing this hit a production release. It will fix a lot of CSP report only noise that I see. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Since Cypress omits the blocking CSP header, it should also omit the
report-only CSP header. This fixes a lot of
unsafe-inline
script-srcwarnings that I have seen when running cypress.
A test has been added to checked that this header is removed.