Module: Datadog::AppSec::Contrib::Rails::Reactive::Action

Defined in:
lib/datadog/appsec/contrib/rails/reactive/action.rb

Overview

Dispatch data from a Rails request to the WAF context

Class Method Summary collapse

Class Method Details

.publish(op, gateway_request) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/datadog/appsec/contrib/rails/reactive/action.rb', line 18

def self.publish(op, gateway_request)
  catch(:block) do
    # params have been parsed from the request body
    op.publish('rails.request.body', gateway_request.parsed_body)
    op.publish('rails.request.route_params', gateway_request.route_params)

    nil
  end
end

.subscribe(op, waf_context) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datadog/appsec/contrib/rails/reactive/action.rb', line 28

def self.subscribe(op, waf_context)
  op.subscribe(*ADDRESSES) do |*values|
    Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
    body = values[0]
    path_params = values[1]

    persistent_data = {
      'server.request.body' => body,
      'server.request.path_params' => path_params,
    }

    waf_timeout = Datadog.configuration.appsec.waf_timeout
    result = waf_context.run(persistent_data, {}, waf_timeout)

    next if result.status != :match

    yield result
    throw(:block, true) unless result.actions.empty?
  end
end