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 blocks event browser resources from loading #1346

Closed
UsAndRufus opened this issue Jun 17, 2022 · 9 comments
Closed

CSP blocks event browser resources from loading #1346

UsAndRufus opened this issue Jun 17, 2022 · 9 comments

Comments

@UsAndRufus
Copy link

UsAndRufus commented Jun 17, 2022

Context

We have quite a strict CSP for security reasons. We enable it in dev too to make sure we don't deploy code that doesn't work due to CSP issues. Part of this CSP configuration is using nonced: true on all inline JavaScript. This seems pretty standard for modern frontend security.

The issue is that the RES Browser uses an un-nonced inline JavsaScript tag. This means the app doesn't load.

Screenshot 2022-06-17 at 14 33 28

We have other apps with significant frontend JS (eg BetterErrors) work fine. I'm not sure what they're doing differently.

Workaround

My workaround is to build a simple event view using our admin tools for now.

Potential Solution

I think the issue would be fixed if the main entrypoint to Elm wasn't inlined but rather was pulled from the server like the other JS files. Rails seems to have no issue with the other sources listed in the page as I believe everything served from the host is considered fine.

Screenshot 2022-06-17 at 14 36 47

IE it's that second script tag that is the issue

Environment

We are on Rails 7.x, recently upgraded from Rails 6.x so our app is very 6-ish.

CSP Policy

From when run locally, hence the references to localhost and .test

Content-Security-Policy: base-uri 'none'; default-src 'none'; frame-src 'self' https:; frame-ancestors 'self' https: http:; font-src 'self' https://*.typekit.net https://fonts.gstatic.com; img-src 'self' https: data: https://provenance.test; manifest-src 'self' https://provenance.test; media-src 'self' https: https://provenance.test; object-src 'none'; style-src 'self' https: https://provenance.test 'nonce-GdEBfK4Gs0N3yzPuwonxPw=='; script-src 'self' https://provenance.test https://www.google-analytics.com https://www.googletagmanager.com https://code.jquery.com https://cdnjs.cloudflare.com https://maxcdn.bootstrapcdn.com 'nonce-GdEBfK4Gs0N3yzPuwonxPw=='; child-src 'none'; worker-src 'none'; connect-src 'self' https: https://provenance.test https://upload.filestackapi.com http://provenance.test http://provenance.test:3000 http://localhost:8545 http://localhost:5001 https://ipfs.infura.io:5001 https://ipfs-cluster.provenance.org https://kovan.infura.io https://mainnet.infura.io wss://localhost:3035 https://localhost:3035

Changelog

Edit 14:30
Worked out the issue was the nonce rather than source list, updated issue accordingly.

@mostlyobvious
Copy link
Member

mostlyobvious commented Jun 20, 2022

I think the issue would be fixed if the main entrypoint to Elm wasn't inlined

That has changed in current 2.4.0 and follow-up 2.4.1 release:

Currently the script tags look like this, as seen on https://ecommerce.arkademy.dev/res:

<!DOCTYPE html>
<html>
  <head>
    <title>RubyEventStore::Browser</title>
    <meta
      name="ruby-event-store-browser-settings"
      content='{"rootUrl":"https://ecommerce.arkademy.dev/res","apiUrl":"https://ecommerce.arkademy.dev/res/api","resVersion":"2.4.1"}'
    />
  </head>
  <body>
    <script type="text/javascript" src="/res/ruby_event_store_browser.js"></script>
    <script type="text/javascript" src="/res/bootstrap.js"></script>
  </body>
</html>

Would that still be an issue?

@mostlyobvious
Copy link
Member

For reference: #1062

@UsAndRufus
Copy link
Author

Brilliant, thanks! I'll upgrade

@UsAndRufus
Copy link
Author

Apologies for not checking my Gem version, should have been first port of call. The upgrade sort of works! The JS is allowed and loads the events, but CSS is blocked because it's all inline and we have a strict style-src in our CSP (included above).

Screenshot 2022-06-21 at 12 01 58

Screenshot 2022-06-21 at 12 02 09

It's not the end of the world though, I can browse the events still. Just takes me back to 1999 😅

@mostlyobvious
Copy link
Member

I'll look into CSS issue (coming from https://github.com/rtfeldman/elm-css)

@mostlyobvious
Copy link
Member

rtfeldman/elm-css#569

mostlyobvious added a commit that referenced this issue Jun 21, 2022
#1346

That should highlight issues quicker.
mostlyobvious added a commit that referenced this issue Jun 22, 2022
Typed CSS is nice and also not needing to think about CSS output was
nice. However it's a dead end with Content-Security-Policy. Our aim with
Browser is to be as compatible with various apps as possible so it was
limiting Browser adoption too much.

rtfeldman/elm-css#569 (comment)
rtfeldman/elm-css#570 (comment)
https://arkency.slack.com/files/U025BA51D/F03LJ1UPZQV/audio_clip__2022-06-22_01_11_39_.m4a

Previous idea with nonce that did not work out:
https://arkency.slack.com/archives/C7B95EW3V/p1655828630714969

Related:
https: //github.com//issues/1346

Co-authored-by: Szymon Fiedler <[email protected]>
@mostlyobvious
Copy link
Member

Elm-css and nonces turned out to be a dead end. I've brought back external stylesheet and that would definitely work with inline-styles disabled via CSP.

@mostlyobvious
Copy link
Member

Fixed and released in v2.5.0

@UsAndRufus
Copy link
Author

Thanks so much!

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

2 participants