Class: Brut::FrontEnd::Handlers::CspReportingHandler

Inherits:
Brut::FrontEnd::Handler show all
Defined in:
lib/brut/front_end/handlers/csp_reporting_handler.rb

Overview

Receives content security policy violations and logs them. This is set up in Brut::Framework::MCP, however CSP reporting is configured in RouteHooks::CSPNoInlineStylesOrScripts::ReportOnly.

Instance Method Summary collapse

Methods inherited from Brut::FrontEnd::Handler

#before_handle, #handle!

Methods included from Brut::Framework::Errors

#abstract_method!, #bug!

Methods included from Brut::FrontEnd::HandlingResults

#http_status, #redirect_to

Constructor Details

#initialize(body:) ⇒ CspReportingHandler

Returns a new instance of CspReportingHandler.



4
5
6
# File 'lib/brut/front_end/handlers/csp_reporting_handler.rb', line 4

def initialize(body:)
  @body = body
end

Instance Method Details

#handleObject



7
8
9
10
11
12
13
14
15
# File 'lib/brut/front_end/handlers/csp_reporting_handler.rb', line 7

def handle
  begin
    parsed = JSON.parse(@body.read)
    Brut.container.instrumentation.add_attributes(parsed.merge(prefix: "brut.csp-reporting"))
  rescue => ex
    Brut.container.instrumentation.record_exception(ex)
  end
  http_status(200)
end