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

Add default CSP #127

Closed
wants to merge 1 commit into from
Closed

Add default CSP #127

wants to merge 1 commit into from

Conversation

fwenzel
Copy link

@fwenzel fwenzel commented Apr 22, 2017

What?

Add a default CSP that allows anything from the local domain, plus inline styles, data: URIs, and no framing. Plus, a referrer policy that will send a full Referer header to the local origin (thus, not mess with stats etc.), but truncate to strict origin when browsing across origins.

Why?

Including reasonable defaults here for both security and privacy will do the fediverse much good.

I am open to suggestions on what would be a better default. For instance, unsafe-inline for styles bugs me a little but if not, we are breaking emoji as currently implemented, for instance. Similar reasoning goes for data URIs.

Also note that this CSP won't work like this with multi-server / CDN deployments, but I reckon a person who can set up a CDN can figure out how to tweak the CSP.

Add a default CSP that allows anything from the local domain, plus inline styles, data: URIs, and no framing.
@dariusk
Copy link

dariusk commented Apr 24, 2017

I can't comment on the specific settings here but could we get something similar for the alternative Apache configuration?

@fwenzel
Copy link
Author

fwenzel commented Apr 24, 2017

Sure, though I don't use Apache.

@dariusk
Copy link

dariusk commented Apr 25, 2017

Looks like it should be set as so in httpd.conf or .htaccess for Apache:

Header set Content-Security-Policy "default-src 'none'; style-src 'self' 'unsafe-inline'; script-src 'self'; img-src 'self' data:; media-src 'self' data:; connect-src 'self' wss:https://example.com; font-src 'self'; frame-ancestors 'none'; manifest-src 'self';"
Header always set Referrer-Policy "strict-origin-when-cross-origin";

This is cobbled together from here and here, so I'm not sure if always ought to be set on both. (The alwaysmeans that it applies to all headers, even unsuccessful responses.)

@wxcafe
Copy link

wxcafe commented Apr 27, 2017

This looks good, but I believe it won't work if you have an instance silenced and you reject their media files : your users won't be able to load them. Should probably add img-src https: and media-src https:

@nolanlawson
Copy link
Contributor

FWIW we've been using this config on toot.cafe for the past week or so and it's been working well:

add_header Content-Security-Policy "style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; object-src 'self'; media-src 'self'; connect-src 'self' wss:https://toot.cafe; upgrade-insecure-requests";

One thing that's a bit unsatisfying is that we get a Mozilla Observatory score of A- because of script-src 'unsafe-inline', but apparently this is required or else Firefox shows an error in the console… Seems it would need a Mastodon code change to fix.

@wxcafe
Copy link

wxcafe commented Apr 28, 2017

As I said, yeah, okay, but if you silence a domain and reject their media files this won't work.

@fwenzel
Copy link
Author

fwenzel commented May 6, 2017

"script-src 'unsafe-inline'", don't do that. Why would you do that? That's pretty much the main reason why CSP (the standard) exists, to keep unsafe user-entered text from being executed as inline script.

@fwenzel
Copy link
Author

fwenzel commented May 6, 2017

I am closing this in favor of #204, we don't need two PRs.

@fwenzel fwenzel closed this May 6, 2017
@fwenzel fwenzel deleted the patch-1 branch May 6, 2017 19:40
This pull request was closed.
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.

4 participants