Class: Otto::Security::CSP::Report
- Inherits:
-
Struct
- Object
- Struct
- Otto::Security::CSP::Report
- Defined in:
- lib/otto/security/csp/report.rb,
lib/otto/security/csp/report.rb
Overview
Normalization behavior for Report. Reopened (rather than defined inside the Struct.new block) so the constants below are plain class constants, not constants-defined-in-a-block.
Constant Summary collapse
- FIELD_ALIASES =
Map from a normalized field to the list of raw keys (in priority order) that may hold its value across both wire formats. Legacy kebab-case keys are listed alongside their Reporting API camelCase equivalents.
{ document_uri: %w[document-uri documentURL], referrer: %w[referrer referer], blocked_uri: %w[blocked-uri blockedURL], violated_directive: %w[violated-directive violatedDirective], effective_directive: %w[effective-directive effectiveDirective], original_policy: %w[original-policy originalPolicy], disposition: %w[disposition], source_file: %w[source-file sourceFile], status_code: %w[status-code statusCode], script_sample: %w[script-sample sample], line_number: %w[line-number lineNumber], column_number: %w[column-number columnNumber], }.freeze
- NUMERIC_FIELDS =
Fields coerced to an Integer (or nil) rather than kept as whatever scalar the browser sent.
%i[status_code line_number column_number].freeze
Instance Attribute Summary collapse
-
#blocked_uri ⇒ Object
Returns the value of attribute blocked_uri.
-
#column_number ⇒ Object
Returns the value of attribute column_number.
-
#disposition ⇒ Object
Returns the value of attribute disposition.
-
#document_uri ⇒ Object
Returns the value of attribute document_uri.
-
#effective_directive ⇒ Object
Returns the value of attribute effective_directive.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#original_policy ⇒ Object
Returns the value of attribute original_policy.
-
#referrer ⇒ Object
Returns the value of attribute referrer.
-
#script_sample ⇒ Object
Returns the value of attribute script_sample.
-
#source_file ⇒ Object
Returns the value of attribute source_file.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
-
#violated_directive ⇒ Object
Returns the value of attribute violated_directive.
Class Method Summary collapse
-
.from_raw(raw) ⇒ Report?
Build a normalized Report from a single raw per-violation field hash.
Instance Attribute Details
#blocked_uri ⇒ Object
Returns the value of attribute blocked_uri
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def blocked_uri @blocked_uri end |
#column_number ⇒ Object
Returns the value of attribute column_number
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def column_number @column_number end |
#disposition ⇒ Object
Returns the value of attribute disposition
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def disposition @disposition end |
#document_uri ⇒ Object
Returns the value of attribute document_uri
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def document_uri @document_uri end |
#effective_directive ⇒ Object
Returns the value of attribute effective_directive
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def effective_directive @effective_directive end |
#line_number ⇒ Object
Returns the value of attribute line_number
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def line_number @line_number end |
#original_policy ⇒ Object
Returns the value of attribute original_policy
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def original_policy @original_policy end |
#referrer ⇒ Object
Returns the value of attribute referrer
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def referrer @referrer end |
#script_sample ⇒ Object
Returns the value of attribute script_sample
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def script_sample @script_sample end |
#source_file ⇒ Object
Returns the value of attribute source_file
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def source_file @source_file end |
#status_code ⇒ Object
Returns the value of attribute status_code
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def status_code @status_code end |
#violated_directive ⇒ Object
Returns the value of attribute violated_directive
40 41 42 |
# File 'lib/otto/security/csp/report.rb', line 40 def violated_directive @violated_directive end |
Class Method Details
.from_raw(raw) ⇒ Report?
Build a normalized Report from a single raw per-violation field hash.
Accepts either wire format’s field naming. violated_directive and
effective_directive are cross-filled from each other when only one is
present, because the two formats disagree on which they send (legacy
favors violated-directive; the Reporting API favors
effectiveDirective).
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/otto/security/csp/report.rb', line 94 def self.from_raw(raw) return nil unless raw.is_a?(Hash) attrs = FIELD_ALIASES.each_with_object({}) do |(field, keys), acc| value = first_present(raw, keys) acc[field] = NUMERIC_FIELDS.include?(field) ? coerce_int(value) : value end cross_fill_directives!(attrs) new(**attrs) end |