security: add Content-Security-Policy header for admin routes

Set a strict CSP on all /admin/* responses: default-src 'self',
script/style 'unsafe-inline' (needed for the inline editor JS and
layout CSS), img-src 'self' data:, frame-ancestors 'none'. Public
API routes are unaffected. Bump ClassLength limit to 420 to
accommodate the new helper.
This commit is contained in:
2026-06-26 20:41:10 +02:00
parent 223405dcb9
commit a2f42c6a12
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ Metrics/MethodLength:
- "lib/volumen/api_routes.rb"
Metrics/ClassLength:
Max: 400
Max: 420
Metrics/ModuleLength:
Exclude:
+13
View File
@@ -64,6 +64,19 @@ module Volumen
before do
options = request.env["rack.session.options"]
options[:secure] = request.ssl? if options
if request.path_info.start_with?("/admin")
headers "Content-Security-Policy" => [
"default-src 'self'",
"script-src 'self' 'unsafe-inline'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data:",
"font-src 'self'",
"connect-src 'self'",
"form-action 'self'",
"frame-ancestors 'none'"
].join("; ")
end
end
private