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.

Subtle Crypto not available in Firefox

See original GitHub issue

Current behavior

Subtle Crypto (window.crypto.subtle) is undefined in Firefox 84.

First noticed my CI tests in Firefox were failing, then reproduced locally by updating my local Firefox (and Cypress) to the latest.

Desired behavior

Subtle crypto to be available in Firefox Cypress tests.

Test code to reproduce

it('Subtle crypto unavailable', function () {
    cy.visit('./cypress/integration/index.html').then(function (win) {
        expect(win.crypto).to.have.property('subtle')
    })
})

Versions

Failing CI Versions

Firefox 84 Linux Ubuntu - 18.04 Cypress - 4.12.1

Last known working CI Versions

Firefox 83 Linux Ubuntu - 18.04 Cypress - 4.12.1

Failing Local Versions

Firefox 84 Mac OS X - 10.14.6 Cypress - 6.2.1

Last known working local version

Firefox 78 Mac OS X - 10.14.6 Cypress - 6.2.1

Note

Subtle crypto is supposed to be available at localhost, as it’s considered a secure context.

From MDN’s docs on secure contexts:

Locally-delivered resources such as those with http://127.0.0.1 URLs, http://localhost and http://*.localhost URLs (e.g. http://dev.whatever.localhost/), and file:// URLs are also considered to have been delivered securely.

But it also has this note, which seems to be the culprit for the breaking change in Firefox 84, but I’m not really sure why:

Note: Firefox 84 and later support http://localhost and http://*.localhost URLs as trustworthy origins (earlier versions did not, because localhost was not guaranteed to map to a local/loopback address).

I have access to subtle crypto in Firefox 84 when serving my site from a webpack dev server at localhost, just not within Cypress for some reason.

I figure it has something to do with Cypress’ browser environment being incompatible with Firefox 84:

Cypress launches the browser in a way that’s different from a regular browser environment. But it launches in a way that we believe makes testing more reliable and accessible.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ShuPinkcommented, Jun 8, 2022

I’m also having this issue with Firefox 100, Ubuntu 20.04, Cypress 10.0.2 on localhost.

Both Electron and Chrome work normally. I can access subtle on Firefox from localhost outside of Cypress.

I tried to polyfill using @peculiar/webcrypto but wasn’t able to get it working.

1reaction
jennifer-shehanecommented, Jan 20, 2021

@j-berman We have docker images where some different browser versions are provided, but we don’t have a ‘matrix’ of browser versions to run against. https://github.com/cypress-io/cypress-docker-images

We proxy a lot of requests through Cypress, so yeah, I imagine there’s something we’re not taking into account in this situation.

Reproducible example

index.html

<html>
  <body>
    <h1>Hello world</h1>
    <script>
      console.log(window.crypto)
    </script>
  </body>
</html>

spec.js

it('Subtle crypto unavailable', () => {
  cy.visit('index.html').then((win) => {
    // Fails in Firefox 84
    expect(win.crypto).to.have.property('subtle')
  })
})

Firefox 81

Screen Shot 2021-01-20 at 3 58 26 PM

Firefox 84

Screen Shot 2021-01-20 at 4 00 34 PM
Read more comments on GitHub >

github_iconTop Results From Across the Web

Crypto.subtle - Web APIs - MDN Web Docs
Chrome Edge subtle Full support. Chrome37. Toggle history Full support. Edge12. Togg... Secure context required Full support. Chrome60. Toggle history Full support. Edge79. Togg...
Read more >
How to use SubtleCrypto in chrome (window.crypto.subtle is ...
According to the spec (via Github issues) a la this Google page for WebCrypto: crypto.subtle is supposed to be undefined in insecure ......
Read more >
Web Cryptography | Can I use... Support tables for HTML5 ...
Firefox for Android. 107 : Supported ... getRandomValues() method, but not actual cryptography functionality under crypto.subtle . 1 Support in IE11 is ...
Read more >
WebCrypto
Note: In the spec, crypto.subtle is supposed to be undefined in insecure ... by Firefox; use "raw" EC keys as a workaround; Chromium...
Read more >
Web Crypto API
Chrome Edge Internet Explorer Op... Crypto Chrome Full support 11 Edge Full support 12 IE Full support 11 Op... getRandomValues() Chrome Full support 11 Edge...
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