summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-19 01:50:13 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-19 01:50:13 +0200
commit8f970e1e573099ce95bae37f6b2fcb2ea73c1b21 (patch)
tree51b2899d798db7fad1e1b29d808ea62d1cc73294
parent69c062cc840c0da81b60a4c635a63743caae1bad (diff)
Add a 500er logger and a trip wire in admin/boom to test it
-rw-r--r--app/controllers/admin_controller.rb7
-rw-r--r--app/controllers/csp_reports_controller.rb16
-rw-r--r--config/routes.rb1
3 files changed, 22 insertions, 2 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 8bd99ac..d9cf1be 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -71,4 +71,11 @@ class AdminController < ApplicationController
71 end 71 end
72 end 72 end
73 end 73 end
74
75 # Deliberately raises, to verify the error-log tripwire end to end.
76 # Behind login_required like the rest of the controller; harmless --
77 # the visitor gets the ordinary 500 page.
78 def boom
79 raise "Deliberate test exception via admin/boom"
80 end
74end 81end
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
diff --git a/config/routes.rb b/config/routes.rb
index 3aa5c69..743b46e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -92,6 +92,7 @@ Cccms::Application.routes.draw do
92 match 'conventions' => 'admin#conventions', :as => :admin_conventions, :via => :get 92 match 'conventions' => 'admin#conventions', :as => :admin_conventions, :via => :get
93 match 'dashboard_search' => 'admin#dashboard_search', :as => :admin_dashboard_search, :via => :get 93 match 'dashboard_search' => 'admin#dashboard_search', :as => :admin_dashboard_search, :via => :get
94 match 'log' => 'node_actions#index', :as => :admin_log, :via => :get 94 match 'log' => 'node_actions#index', :as => :admin_log, :via => :get
95 match 'boom' => 'admin#boom', :as => :admin_boom, :via => :get
95 end 96 end
96 97
97 match '/logout' => 'sessions#destroy', :as => :logout, :via => :delete 98 match '/logout' => 'sessions#destroy', :as => :logout, :via => :delete