Skip to content
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

5.5.0 Regression: Cannot load script with integrity attribute #8983

Closed
Tanuel opened this issue Oct 27, 2020 · 6 comments · Fixed by #9018
Closed

5.5.0 Regression: Cannot load script with integrity attribute #8983

Tanuel opened this issue Oct 27, 2020 · 6 comments · Fixed by #9018
Assignees
Labels
type: regression A bug that didn't appear until a specific Cy version release v5.5.0 🐛 Issue present since 5.5.0

Comments

@Tanuel
Copy link

Tanuel commented Oct 27, 2020

Current behavior

When trying to load google recaptcha, it will load another script, but the integrity check will fail. This error happens since upgrading to 5.5.0
image

Desired behavior

captcha can be loaded correctly

Test code to reproduce

https://github.com/Tanuel/cypress-test-tiny

  • npm install
  • npm run test
    image

Versions

Error occured on: 5.5.0
Last working Version: 5.4.0

Let me know if you need more information

@mstreng-bhs
Copy link

Same problem after upgrading from 5.3.0 to 5.5.0

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Oct 28, 2020

Yes, I can recreate this from the provided repo https://github.com/Tanuel/cypress-test-tiny. This was introduced in 5.5.0. This was introduced in this PR: #8827. I git bisected to this commit where it started failing: 19fdf43

5.4.0

Screen Shot 2020-10-28 at 3 51 20 PM

5.5.0

Screen Shot 2020-10-28 at 3 50 27 PM

@jennifer-shehane jennifer-shehane added v5.5.0 🐛 Issue present since 5.5.0 type: regression A bug that didn't appear until a specific Cy version release labels Oct 28, 2020
@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label Oct 28, 2020
@sync-by-unito sync-by-unito bot changed the title Cannot load script with integrity attribute in 5.5.0 5.5.0 Regression: Cannot load script with integrity attribute Oct 28, 2020
@sergeyblohin
Copy link

I faced a similar problem.
When Cypress was updated from 5.4.0 to 5.5.0, my ReCaptcha was no longer displayed.
I found a workaround allowing me to display ReCaptcha on a page.
Perhaps somebody could use it.

We add the following line to cypress.json:

{
  "experimentalNetworkStubbing": true,
}

We add the following code to cypress/support/index.js:

before(() => {
  cy.server();
  cy.route2('**/recaptcha/api.js', {fixture: 'google/recaptcha/api.js'});
});

Add the following code to cypress/fixtures/google/recaptcha/api.js.txt:

/* PLEASE DO NOT COPY OR PASTE THIS CODE. */
(function () {
  var w = window, C = '___grecaptcha_cfg', cfg = w[C] = w[C] || {}, N = 'grecaptcha';
  var gr = w[N] = w[N] || {};
  gr.ready = gr.ready || function (f) {
    (cfg['fns'] = cfg['fns'] || []);
  };
  w['__recaptcha_api'] = 'https://www.google.com/recaptcha/api2/';
  (cfg['render'] = cfg['render'] || []).push('onload');
  w['__google_recaptcha_client'] = true;
  var d = document, po = d.createElement('script');
  po.type = 'text/javascript';
  po.async = true;
  po.src = 'https://www.gstatic.com/recaptcha/releases/T9w1ROdplctW2nVKvNJYXH8o/recaptcha__en.js';
  po.crossOrigin = 'anonymous';
  // po.integrity = 'sha384-3QFmGa9WBVUnmTTGehi+1Uin1pmBuS/I5R1Ce52Aiiuviet65v+bH12eR4+kUUcx';
  var e = d.querySelector('script[nonce]'), n = e && (e['nonce'] || e.getAttribute('nonce'));
  if(n) {
    po.setAttribute('nonce', n);
  }
  var s = d.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(po, s);
})();

Note that in api.js.txt I commented line 16.

You can now work with `integrity' in Cypress 5.5.0.

@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: investigating Someone from Cypress is looking into this stage: work in progress labels Oct 29, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Nov 9, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 9, 2020

The code for this is done in cypress-io/cypress#9018, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 9, 2020

Released in 5.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.6.0, please open a new issue.

1 similar comment
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 9, 2020

Released in 5.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.6.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Nov 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: regression A bug that didn't appear until a specific Cy version release v5.5.0 🐛 Issue present since 5.5.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants