Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view content security policy violation reports in rails app?

I used secure_headers gem https://github.com/twitter/secureheaders and i configure the csp as

config.csp = {
:enforce => true,
:default_src => 'http://* inline',
:report_uri => "/report",
:connect_src => 'self',
:style_src => 'self inline',
:script_src => 'self inline eval',
:font_src => 'self'
}

but still i can't view the reports in my http://localhost:3000/report and page is not redirecting

like image 579
EMR Avatar asked Sep 03 '13 07:09

EMR


People also ask

How do I view Content-Security-Policy?

Conduct a find (Ctrl-F on Windows, Cmd-F on Mac) and search for the term “Content-Security-Policy”. If “Content-Security-Policy” is found, the CSP will be the code that comes after that term.

What is CSP unsafe eval?

'unsafe-eval' allows the application to use the eval() JavaScript function. This reduces the protection against certain types of DOM-based XSS bugs, but makes it easier to adopt CSP. If your application doesn't use eval() , you can remove this keyword and have a safer policy.

How do I fix the Content-Security-Policy of your site blocks the use of eval in JavaScript?

The Content Security Policy (CSP) prevents the evaluation of arbitrary strings as JavaScript to make it more difficult for an attacker to inject unauthorized code on your site. To solve this issue, avoid using eval() , new Function() , setTimeout([string], ...) and setInterval([string], ...) for evaluating strings.

Can I use report URI?

report-uri is technically deprecated, but the replacement (report-to) isn't supported by most browsers. You can either support both, or wait till report-to is more widely supported by all browsers.


2 Answers

EDIT:

https://report-uri.io/ offers CSP reporting capabilities. They give you a report-uri, and they manage the incoming reports!


Currently the gem does not have any built-in support for aggregating/viewing the reports. This question got me thinking so I filed https://github.com/twitter/secureheaders/issues/71

Please add your thoughts. I don't think it is a trivial task to build something meaningful, but I'm beginning to see how valuable it could be. There's also a good amount of low hanging fruit that might be good enough for the time being.

like image 164
oreoshake Avatar answered Sep 28 '22 02:09

oreoshake


The Secure Headers Gem does not provide a reporting endpoint for CSP violations. It is something you would have to build yourself or use a solution that provides both out of the box.

I posted an overview of the different ways of deploying a Content Security Policy with Ruby on Rails, including SecureHeaders Gem and Templarbit (which includes a reporting endpoint): https://www.templarbit.com/blog/2018/03/14/content-security-policy-with-ruby-on-rails

like image 26
Bjoern Zinssmeister Avatar answered Sep 28 '22 00:09

Bjoern Zinssmeister