Class: Aikido::Zen::Context
- Inherits:
-
Object
- Object
- Aikido::Zen::Context
- Defined in:
- lib/aikido/zen/context.rb
Instance Attribute Summary collapse
- #request ⇒ Aikido::Zen::Request readonly
Class Method Summary collapse
-
.from_rack_env(env, config = Aikido::Zen.config) ⇒ Aikido::Zen::Context
Build a Context object for the current HTTP request based on the currently configured request builder.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Fetch some metadata stored in the Context.
-
#[]=(key, value) ⇒ void
Store some metadata in the Context so other Scanners can use it.
-
#initialize(request, settings: Aikido::Zen.runtime_settings) {|request| ... } ⇒ Context
constructor
A new instance of Context.
-
#payloads ⇒ Array<Aikido::Zen::Payload>
List of user inputs from all the different sources we recognize.
-
#protection_disabled? ⇒ Boolean
Whether attack protection for the currently requested endpoint was disabled on the Aikido dashboard, or if the source IP for this request is in the “Bypass List”.
-
#update_request(new_request) ⇒ void
Overrides the current request, and invalidates any memoized data obtained from it.
Constructor Details
#initialize(request, settings: Aikido::Zen.runtime_settings) {|request| ... } ⇒ Context
Returns a new instance of Context.
30 31 32 33 34 35 |
# File 'lib/aikido/zen/context.rb', line 30 def initialize(request, settings: Aikido::Zen.runtime_settings, &sources) @request = request @settings = settings @payload_sources = sources @metadata = {} end |
Instance Attribute Details
#request ⇒ Aikido::Zen::Request (readonly)
21 22 23 |
# File 'lib/aikido/zen/context.rb', line 21 def request @request end |
Class Method Details
.from_rack_env(env, config = Aikido::Zen.config) ⇒ Aikido::Zen::Context
Build a Context object for the current HTTP request based on the currently configured request builder.
16 17 18 |
# File 'lib/aikido/zen/context.rb', line 16 def self.from_rack_env(env, config = Aikido::Zen.config) config.request_builder.call(env) end |
Instance Method Details
#[](key) ⇒ Object?
Fetch some metadata stored in the Context.
41 42 43 |
# File 'lib/aikido/zen/context.rb', line 41 def [](key) @metadata[key] end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Store some metadata in the Context so other Scanners can use it.
50 51 52 |
# File 'lib/aikido/zen/context.rb', line 50 def []=(key, value) @metadata[key] = value end |
#payloads ⇒ Array<Aikido::Zen::Payload>
Returns list of user inputs from all the different sources we recognize.
68 69 70 71 72 |
# File 'lib/aikido/zen/context.rb', line 68 def payloads @payloads ||= payload_sources.flat_map do |source, data| extract_payloads_from(data, source) end end |
#protection_disabled? ⇒ Boolean
Returns whether attack protection for the currently requested endpoint was disabled on the Aikido dashboard, or if the source IP for this request is in the “Bypass List”.
77 78 79 80 81 82 |
# File 'lib/aikido/zen/context.rb', line 77 def protection_disabled? return false if request.nil? !@settings.endpoints[request.route].protected? || @settings.skip_protection_for_ips.include?(request.ip) end |
#update_request(new_request) ⇒ void
This method returns an undefined value.
Overrides the current request, and invalidates any memoized data obtained from it. This is useful for scenarios where setting the request in the middleware isn’t enough, such as Rails, where the router modifies it after the middleware has seen it.
61 62 63 64 |
# File 'lib/aikido/zen/context.rb', line 61 def update_request(new_request) @payloads = nil request.__setobj__(new_request) end |