Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Document needed changes in Content-Security-Policy / possibly update script for better CSP support #106

Open
tbroyer opened this issue Jul 12, 2017 · 5 comments

Comments

@tbroyer
Copy link

tbroyer commented Jul 12, 2017

I've setup a CSP on my blog, which by default blocks the script.

Changes I had to make to make it work:

  • add https://widget.battleforthenet.com to script-src
  • add https://widget.battleforthenet.com to child-src
  • add 'sha256-2V9nAQ7jmNi+KiCY0h7ybeJqEOY6KbSS7uPieMa6VVc=' (or unsafe-inline) to style-src;
    however that means that if you change the content of the stylesheet, it'll be blocked; and unsafe-inline grants too much rights for other stylesheets.
    How about using an external stylesheet instead (like Twitter does) so the style-src can simply whitelist https://widget.battleforthenet.com and you're free to make last-minute changes to the stylesheet?

Did I miss something?

(note that I've only checked that this displays the popup and it can be dismissed, not that the form can be submitted)

@mikemorris
Copy link
Contributor

mikemorris commented Jul 12, 2017

An external stylesheet as in hosting at a separate (cookie-less?) domain for static assets, or a different subdomain? Good idea for future iterations here, but not gonna happen today 😄

@tbroyer
Copy link
Author

tbroyer commented Jul 12, 2017

Yeah sure, of course I was late; and indeed this also serves as a suggestion for next time (we all hope it won't be needed, yet we all know it will…).

To answer your question: hosting the CSS at the same origin as the script and iframe would be (have been) OK; no need for a different subdomain. The changes required on a CSP would be “whitelist https://widget.battleforthenet.com on script-src, style-src, and child-src” (maybe a bit more to ensure the form works too)

I suppose @mikewest or @ScottHelme could help find the best settings 😉

@emma-sg
Copy link
Contributor

emma-sg commented Jul 13, 2017

In the future, hashes could be calculated and automatically added with the build process.

@mikemorris mikemorris added the ci label Oct 16, 2017
@AfroThundr3007730
Copy link

Ok, so after adding https://widget.battleforthenet.com to script-src and child-src in my CSP, I was still getting the following in the console:

17:34:31.487 Content Security Policy: The page’s settings blocked the loading of a resource at self (“default-src https://www.example.com https://cdn.example.com https://widget.battleforthenet.com”). Source: #_bftn_wrapper { position: fixed; left: ....

So the style for the iframe was still being blocked, most likely because I don't allow unsafe-inline in the policy. I got around this by adding the relevant code to my css directly:

#_bftn_wrapper {
	position: fixed;
	left: 0px;
	top: 0px;
	width: 100%;
	height: 100%;
	z-index: 20000;
	-webkit-overflow-scrolling: touch;
	overflow-y: auto;
}

#_bftn_iframe {
	width: 100%;
	height: 100%;
}

Note: Adding 'sha256-2V9nAQ7jmNi+KiCY0h7ybeJqEOY6KbSS7uPieMa6VVc=' to script-src fixes the issue for Chrome, but not Firefox. The above CSS allows the widget to function correctly despite the CSP error in the console.

@rubbingalcoholic
Copy link
Member

rubbingalcoholic commented Dec 12, 2017 via email

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

No branches or pull requests

5 participants