cypress: Cypress cannot test sites that implement SRI
Current behavior:
When running Cypress against a site that implements SRI hashes, resources on the page are immediately blocked by Chrome and the page will not load due to invalid hashes. Disabling chromeWebSecurity does nothing. The following error appears in the Chrome DevTools console.
Failed to find a valid digest in the 'integrity' attribute for resource 'https://{my-domain}/assets/vendor-cdn-c9965fdc08cb8e112642197db5d0fc54.js' with computed SHA-256 integrity '2/Ht5YqBxaylA4fn2318LzUh4tFwjZH4WlN0lsHme9M='. The resource has been blocked.
Desired behavior:
The page of an SRI enabled site can load and not be blocked by Chrome. Either Cypress dynamically corrects the hash when it tampers with the file, or the chromeWebSecurity option actually disables SRI checks in Chrome.
Steps to reproduce:
- Start a Cypress instance and configure to point to a site that implements SRI checking (e.g. https://github.com).
- Implement a basic step that verifies anything on the page.
- Observe the test fail, the error message in the Chrome DevTools console and resources being unable to load.
Versions
Cypress 3.1.0 Fedora 28 Chrome 68.0.3440.106
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 10
- Comments: 15 (7 by maintainers)
I ran into this issue, seemingly out of the blue. I added the following to a script a the top of the document, and it seems to work:
This is something that we will fix when #1467 is implemented.
There is a WIP PR for this: #5273
This fix is available starting in
4.6.0as an experiment which you can access by setting this config option in yourcypress.jsonor elsewhere:The fix is experimental, so there may be some situations where the this is not fixed.
If you’re still this issue while setting the
experimentalSourceRewritingto true in 4.6.0 - open a new issue with a reproducible example + screenshots, etc - filling out our issue template.Confirmed, we have the same problem.
The code for this is done in cypress-io/cypress#5273, but has yet to be released. We’ll update this issue and reference the changelog when it’s released.
Just added this in #5273. Once released, SRI
integrityattributes in script tags<script type="text/javascript">will be rewritten tocypress:stripped-integrityattributes.becomes the below which will cause integrity checking to be skipped.