Class: Otto::Security::CSP::Writer::Result
- Inherits:
-
Object
- Object
- Otto::Security::CSP::Writer::Result
- Defined in:
- lib/otto/security/csp/writer.rb
Overview
Outcome of an apply call.
applied? is the single source of truth for “did a header get
written”. policy is the emitted policy on success, or the pre-existing
policy when a :backstop deferred to one. skip_reason is one of
:disabled, :blank_nonce, :non_html, :existing_csp when skipped,
else nil. extra_directives carries the request-scoped extras that
were ACTUALLY folded into the policy — entries dropped during the
append (absent directive) are excluded — or nil when none landed.
Constant Summary collapse
- SKIP_REASONS =
Recognized skip reasons, in the order Otto::Security::CSP::Writer.apply evaluates them.
%i[disabled blank_nonce non_html existing_csp].freeze
Instance Attribute Summary collapse
-
#extra_directives ⇒ Object
readonly
Returns the value of attribute extra_directives.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#skip_reason ⇒ Object
readonly
Returns the value of attribute skip_reason.
Class Method Summary collapse
-
.applied(policy, mode:, extra_directives: nil) ⇒ Object
Build an “applied” result for a written policy.
-
.skipped(reason, mode:, policy: nil) ⇒ Object
Build a “skipped” result.
Instance Method Summary collapse
-
#applied? ⇒ Boolean
True when a CSP header was written.
-
#initialize(applied:, mode:, policy: nil, skip_reason: nil, extra_directives: nil) ⇒ Result
constructor
A new instance of Result.
-
#skipped? ⇒ Boolean
True when no header was written.
Constructor Details
#initialize(applied:, mode:, policy: nil, skip_reason: nil, extra_directives: nil) ⇒ Result
Returns a new instance of Result.
69 70 71 72 73 74 75 |
# File 'lib/otto/security/csp/writer.rb', line 69 def initialize(applied:, mode:, policy: nil, skip_reason: nil, extra_directives: nil) @applied = applied @mode = mode @policy = policy @skip_reason = skip_reason @extra_directives = extra_directives end |
Instance Attribute Details
#extra_directives ⇒ Object (readonly)
Returns the value of attribute extra_directives.
67 68 69 |
# File 'lib/otto/security/csp/writer.rb', line 67 def extra_directives @extra_directives end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
67 68 69 |
# File 'lib/otto/security/csp/writer.rb', line 67 def mode @mode end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
67 68 69 |
# File 'lib/otto/security/csp/writer.rb', line 67 def policy @policy end |
#skip_reason ⇒ Object (readonly)
Returns the value of attribute skip_reason.
67 68 69 |
# File 'lib/otto/security/csp/writer.rb', line 67 def skip_reason @skip_reason end |
Class Method Details
.applied(policy, mode:, extra_directives: nil) ⇒ Object
Build an “applied” result for a written policy.
78 79 80 |
# File 'lib/otto/security/csp/writer.rb', line 78 def self.applied(policy, mode:, extra_directives: nil) new(applied: true, mode: mode, policy: policy, extra_directives: extra_directives) end |
.skipped(reason, mode:, policy: nil) ⇒ Object
Build a “skipped” result. policy carries the pre-existing policy for
the :existing_csp case (observability), nil otherwise.
84 85 86 |
# File 'lib/otto/security/csp/writer.rb', line 84 def self.skipped(reason, mode:, policy: nil) new(applied: false, mode: mode, skip_reason: reason, policy: policy) end |
Instance Method Details
#applied? ⇒ Boolean
Returns true when a CSP header was written.
89 90 91 |
# File 'lib/otto/security/csp/writer.rb', line 89 def applied? @applied end |
#skipped? ⇒ Boolean
Returns true when no header was written.
94 95 96 |
# File 'lib/otto/security/csp/writer.rb', line 94 def skipped? !@applied end |