summaryrefslogtreecommitdiff
path: root/app/controllers/csp_reports_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/csp_reports_controller.rb')
-rw-r--r--app/controllers/csp_reports_controller.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/app/controllers/csp_reports_controller.rb b/app/controllers/csp_reports_controller.rb
index 08cbc98..a8f8edb 100644
--- a/app/controllers/csp_reports_controller.rb
+++ b/app/controllers/csp_reports_controller.rb
@@ -3,8 +3,20 @@ class CspReportsController < ApplicationController
3 skip_before_action :verify_authenticity_token 3 skip_before_action :verify_authenticity_token
4 4
5 def create 5 def create
6 report = request.body.read(8192) 6 request.body.rewind if request.body.respond_to?(:rewind)
7 Rails.logger.warn("CSP violation: #{report}") if report.present? 7 raw = request.body.read(8192)
8 raw = request.raw_post if raw.blank?
9
10 report = (JSON.parse(raw)["csp-report"] rescue nil)
11
12 if report
13 directive = report["effective-directive"] || report["violated-directive"]
14 at = (URI.parse(report["document-uri"]).path rescue "unparsed")
15 Rails.logger.warn("CSP violation: #{directive} blocked=#{report['blocked-uri']} at=#{at}")
16 else
17 Rails.logger.warn("CSP violation: unparseable report (#{raw.to_s.bytesize} bytes)")
18 end
19
8 head :no_content 20 head :no_content
9 end 21 end
10end 22end