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

CSP errors after I change the s3 alias host #27446

Closed
eallion opened this issue Oct 17, 2023 · 5 comments · May be fixed by mastodon/documentation#1586
Closed

CSP errors after I change the s3 alias host #27446

eallion opened this issue Oct 17, 2023 · 5 comments · May be fixed by mastodon/documentation#1586
Labels
area/web interface Related to the Mastodon web interface bug Something isn't working status/to triage This issue needs to be triaged

Comments

@eallion
Copy link

eallion commented Oct 17, 2023

Steps to reproduce the problem

After I changed the s3 alias host, Chrome Console showed these errors.
However, the instance works fine in Firefox and Chrome WITHOUT login. The Android app works fine. Apps like Elk also work fine.

Refused to connect to '<URL>' because it violates the following Content Security Policy directive: "connect-src 'self' data: blob: <URL> <URL> <URL>".

StrategyHandler.js:163 Refused to connect to 'https://e5n.cc.eallion.com/cache/accounts/avatars/111/140/916/386/657/713/original/b9cb07a6d7536eb2.webp' because it violates the following Content Security Policy directive: "connect-src 'self' data: blob: https://e5n.cc https://files.e5n.cc wss://e5n.cc".
  • Instance: e5n.cc
  • Old s3 alias host: files.e5n.cc (Cloudflare R2)
  • New s3 alias host: e5n.cc.eallion.com (Tencent COS & CDN)

Snipaste_2023-10-17_18-30-30

Snipaste_2023-10-17_18-30-53

Expected behaviour

Show media

Actual behaviour

CSP errors

Detailed description

No response

Mastodon instance

e5n.cc

Mastodon version

v4.2.1

Browser name and version

Chrome 118.0.5993.71

Operating system

Win11

Technical details

No response

@eallion eallion added area/web interface Related to the Mastodon web interface bug Something isn't working status/to triage This issue needs to be triaged labels Oct 17, 2023
@ClearlyClaire
Copy link
Contributor

This looks like the service worker (sw.js) is cached with the old CSP value. It is cached for up to 7 days in the default configuration.

@eallion
Copy link
Author

eallion commented Oct 18, 2023

I've traced it this far, but I don't know how to fix it.

@ClearlyClaire
Copy link
Contributor

If you have a CDN in front of e5n.cc itself, you need to clear its cache. Then on the user side, you need to refresh browser cache. The issue should then disappear.

@eallion eallion closed this as completed Oct 19, 2023
@thijskh
Copy link
Contributor

thijskh commented Jan 20, 2025

We've seen this issue (twice) and had a hard time finding out what caused it. We had this when we moved from local storage to an S3-based storage platform, and again when this platform changed domain names.

It seems to be this scenario:

  • You change the hostname where your assets are hosted.
  • The CSP needs to be updated for this, which you do.
  • However, it seems the web workers are cached for a long time including the CSP header, so assets are blocked for all users that have used the site before.
  • The cache timeout seems to be up to a week, so changing the assets URL would lead to broken image for a week for our users.

We've not found a way for us as Mastodon admins to force these web workers to upgrade (their CSP info), nor for end users to force refresh them. Other than using a private window.

Our conclusion is that when we change assets hosts, we need to add the new host at least 1 week before a planned migration to the CSP header so users can 'learn' the value.

@thijskh
Copy link
Contributor

thijskh commented Jan 20, 2025

Duplicate in #28842

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/web interface Related to the Mastodon web interface bug Something isn't working status/to triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants