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

fix: Allow scripts and styles to load cross-origin, e.g. from Google Translate #215

Merged
merged 2 commits into from
Nov 3, 2020

Conversation

palant
Copy link
Collaborator

@palant palant commented Jul 4, 2020

I noticed that neither scripts nor styles of my websites were loading when somebody attempted to translate an article via Google Translate. That's due to enableFingerprint = true configuration option - it doesn't merely enable fingerprinting but also Subresource Integrity. Turns out, cross-origin requests with integrity attribute are blocked by default, otherwise these could be misused to leak information.

The solution consists of two parts:

  1. Add crossorigin="anonymous" attribute to the requests in question (done here).
  2. Add Access-Control-Allow-Origin: * header to JS/CSS requests - has to be done in server configuration.

The second part probably needs documenting. The other option would be to separate fingerprinting (useful by itself to avoid using outdated scripts/styles) and Subresource Integrity in the configuration.

@reuixiy
Copy link
Owner

reuixiy commented Jul 5, 2020

Thanks!

The other option would be to separate fingerprinting (useful by itself to avoid using outdated scripts/styles) and Subresource Integrity in the configuration.

Like this. It's a nice enhancement.

@palant
Copy link
Collaborator Author

palant commented Jul 5, 2020

Like this. It's a nice enhancement.

Not something I can implement however. I'm stuck on Hugo 0.68.3 for a while, so the current theme version is unusable for me.

…rinting

BREAKING CHANGE: enableFingerprint config parameter no longer enables Subresource Integrity. If you need it, you have to specify enableSRI parameter as well
@palant
Copy link
Collaborator Author

palant commented Nov 3, 2020

I’m finally on the current MemE version again, so I can test this. The additional commit introduces a new enableSRI setting, so Subresource Integrity can now be turned on or off separately from fingerprinting. I only change the English-language config, you’ll need to adjust the Chinese one.

@palant palant requested a review from reuixiy November 3, 2020 13:52
Copy link
Owner

@reuixiy reuixiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@palant palant merged commit b9869e7 into master Nov 3, 2020
@palant palant deleted the cross-origin-integrity branch November 3, 2020 15:31
@palant
Copy link
Collaborator Author

palant commented Nov 3, 2020

Merged, but the Chinese config change still needs to happen.

@reuixiy
Copy link
Owner

reuixiy commented Nov 3, 2020

Yes! I'm about to push a commit... Guess I should do it firstly next time, before the approval on GitHub CLI.

Anyway, thanks again!

ulmefors pushed a commit to ulmefors/hugo-theme-meme that referenced this pull request Jan 22, 2024
…rinting (reuixiy#215)

This allows scripts and styles to load cross-origin, e.g. when the page is viewed from Google Translate.

BREAKING CHANGE: enableFingerprint config parameter no longer enables Subresource Integrity. If you need it, you have to specify enableSRI parameter as well
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

Successfully merging this pull request may close these issues.

None yet

2 participants