I'd like to implement a Content Security Policy (CSP) that's as strict as possible. According to this intro on CSP, inline styles are bad (emphasis mine):
Inline style is treated in the same way: both the style attribute and style tags should be consolidated into external stylesheets to protect against a variety of surprisingly clever data exfiltration methods that CSS enables.
If you really, absolutely must have inline script and style, you can enable it by adding 'unsafe-inline' as an allowed source in a script-src or style-src directive. But please don’t.
The default form_tag
method inserts a hidden field for UTF-8 (I was actually looking for the authenticity token but cannot find it in my markup):
<div style="display:none"><input type="hidden" value="✓" name="utf8"></div>
which – because of display:none
– gets reported in Firefox 32 as a violation of the following CSP:
$ curl -I http://localhost:3000 | grep Content-Security | fold
Content-Security-Policy-Report-Only: default-src https: 'self'; connect-src http
s: 'self'; font-src https: data:; frame-src https: 'self'; img-src https: 'self'
data:; media-src https: 'self'; object-src https: 'self'; script-src https: 'se
lf'; style-src https: 'self';
I'd like to disallow inline CSS styles in my CSP but Rails by default prevents that. What can I do?