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

Optimization Detective not working on non-HTTPS site #1904

Open
swissspidy opened this issue Mar 4, 2025 · 1 comment
Open

Optimization Detective not working on non-HTTPS site #1904

swissspidy opened this issue Mar 4, 2025 · 1 comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken

Comments

@swissspidy
Copy link
Member

Bug Description

The detection script uses crypto.subtle.digest, but the crypto API is only available in secure (HTTPS) contexts.

I noticed by accident as I was accessing my local site without HTTPS.

Then I got a JS error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'digest')

While most sites are using HTTPS nowadays anyway, I think this potential error should be caught to avoid errors.

It can then log to the console that detection is not possible or so.

Steps to reproduce

  1. Install on HTTPS site
  2. View site
  3. See unhandled JS error

Screenshots

Additional Context

  • PHP Version:
  • OS: [e.g. iOS]
  • Browser: [e.g. chrome, safari]
  • Plugin Version: [e.g. 22]
  • Device: [e.g. iPhone6]
@swissspidy swissspidy added the [Type] Bug An existing feature is broken label Mar 4, 2025
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2025 Mar 4, 2025
@swissspidy swissspidy added the [Plugin] Optimization Detective Issues for the Optimization Detective plugin label Mar 4, 2025
@westonruter
Copy link
Member

Interesting that this is not available on HTTP when crypto seems like it would be all the more important to have available if a secure connection isn't available.

I agree that detection should short-circuit with a warning (or maybe an error for visibility) when the API isn't available. If it is not available and the current page doesn't have HTTPS, then the message can advise that they use HTTPS. Note that not all HTTP sites are affected, namely localhost is an exception.

Alternatively, we could construct the sessionStorage keys using an alternate means than hashing. But maybe this isn't warranted.

@westonruter westonruter moved this from Not Started/Backlog 📆 to To Do 🔧 in WP Performance 2025 Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken
Projects
Status: To Do 🔧
Development

No branches or pull requests

2 participants