cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.09k stars 3.19k forks source link

Integrity resources are being blocked #30657

Open DoctorOaken opened 1 day ago

DoctorOaken commented 1 day ago

Current behavior

We have been attempting to use this configuration

experimentalSourceRewriting: true

However when we run our automation we run into this error

Failed to find a valid digest in the 'integrity' attribute for resource 'https://www.xxxxxxxxx.com/js/script.js' with computed SHA-384 integrity 'HASH'. The resource has been blocked

Desired behavior

The resource loads and then the page loads.

Test code to reproduce

We cannot provide this directly, but is there a way we could demonstrate the test?

Cypress Version

13.15.1

Node version

22.9.0

Operating System

Windows 11 , reproducible in Ubunut 20.04 LTS

Debug Logs

No response

Other

We believe we are running into the same problem mentioned on this thread.

https://github.com/cypress-io/cypress/issues/29111 as well as this one https://github.com/cypress-io/cypress/issues/18315

We tried using these configurations

experimentalSourceRewriting: true and/or modifyObstructiveCode: false,

but we continued to run into the same integrity resource being blocked error.

Attached as a screenshot of the log of the test result. cypresserror

ryanthemanuel commented 1 day ago

Hi @DoctorOaken. Can you send your full cypress config (with anything sensitive filtered out)? I'm curious what other config values are being set. Also, how is that asset being loaded? Is it part of the HTML or being fetched some other way, etc.?

Forking Cypress Test Tiny makes sharing a reproducible example easier to share and easier for our engineers to replicate your issues. This method also keeps the reproduction as simple as possible, which helps us eliminate potential causes and noise from the investigation.

DoctorOaken commented 11 hours ago

Hello,

Thanks for your reply. We have put together a sample of the tests attached to this reply.

minimal_project.zip configurations

dan-reeves-volusion commented 11 hours ago

Hi @ryanthemanuel @DoctorOaken's coworker here,

The asset is just part of the HTML on page, it's a React script

Here's our fork for the test: https://github.com/dan-reeves-volusion/cypress-test-tiny

We get the integrity error with the config as it is there. After turning experimentalSourceRewriting to true, the script loads successfully, however navigating to the OrderFinished page after checkout breaks Cypress: The left panel resets to "Your tests are loading..." and the window becomes mostly unresponsive and cypress must be restarted.

Just a guess, but I think it has something to do with a window.top.location.replace(uri); call in the bundled JS of that React script: in /checkout/static/js/services/WindowService/index.ts#43 (bundled, not a real file on the server) Cypress handled it fine before the integrity attribute was present, but I'm guessing experimentalSourceRewriting has some trouble with it. Could be wrong though!