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

Failed to find a valid digest in the 'integrity' attribute #26

Open
EvgenyOrekhov opened this issue May 23, 2020 · 6 comments
Open

Failed to find a valid digest in the 'integrity' attribute #26

EvgenyOrekhov opened this issue May 23, 2020 · 6 comments

Comments

@EvgenyOrekhov
Copy link
Contributor

Steps to reproduce:

  1. Go to https://evgenyorekhov.github.io/holiday.css/src/index.html
  2. Click on the Drop-in bookmarklet
  3. Select a different CSS framework from the Drop-in switcher

Expected result: selected framework's styles should be applied to the page

Actual result: styles are not applied, there is the following error in the browser console

Failed to find a valid digest in the 'integrity' attribute for resource
'https://dohliam.github.io/dropin-minimal-css/min/awsm.min.css'
with computed SHA-256 integrity
'giTWrXju6B1GUPSb1nHYBfCZzd73kLweWPjVOBzNxAA='.
The resource has been blocked.

image

@dohliam
Copy link
Owner

dohliam commented May 23, 2020

@EvgenyOrekhov It looks like this error is caused by the integrity check in the CSS link to normalize.min.css on that page:

<link
            rel="stylesheet"
            href="https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/0.6.0/modern-normalize.min.css"
            integrity="sha256-a9JO7L1jGkja9va1xGMWEJspCfU/b9Vn5u/O5MdnKhw="
            crossorigin="anonymous"
        />

As far as I understand, this basically checks that the loaded minified Normalize CSS file has not been changed. However, the bookmarklet does change the CSS (it replaces it), so the integrity test fails.

There are probably a few ways to fix this -- you could of course remove the integrity check or (if that's not possible), move the call to Normalize CSS down in the list of linked stylesheets (the switcher just tries to replace the first linked stylesheet).

Hope that helps!

@EvgenyOrekhov
Copy link
Contributor Author

If the switcher was inserting a new <link> element instead of replacing an existing one, I think it would solve the issue. What do you think?

It's just more and more websites are starting to use integrity checks.

@dohliam
Copy link
Owner

dohliam commented May 23, 2020

Yes, it did do something like that at first, but I quickly discovered that this leads to unexpected results because it effectively layers the new stylesheet on top of the old one (often this results in no effect at all, actually -- particularly if the first stylesheet has lots of !important statements). So this is an imperfect solution but it does work most of the time.

@EvgenyOrekhov
Copy link
Contributor Author

So what is the switcher trying to emulate? I mean, if it tries to emulate how the page would look if you included one of the themes along with your existing styles, then the switcher should not mess with existing styles at all. If the switcher is supposed to emulate how the page would look if you included only one of the themes, then the switcher should remove all existing styles first. The way it works now, is a mix of both. That is unexpected.

@dohliam
Copy link
Owner

dohliam commented May 25, 2020

Yes, it might be a good idea to try recursively removing all styles before adding the switcher. This might break a lot of pages though, so it would probably need a lot of testing on various sites and with all the different stylesheets. On the other hand, it might allow some pages to work with the switcher that currently don't (like Github itself).

@lemmi
Copy link

lemmi commented Sep 12, 2022

I ran in a similar issue. Removing the integrity attribute with css_link.integrity="" the styles are loaded correctly.
I also tried delete css_link.integrity and css_link.integrity=undefined, but those didn't seem to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants