Module: Datadog::AppSec::Contrib::Rack::Reactive::RequestBody

Defined in:
lib/datadog/appsec/contrib/rack/reactive/request_body.rb

Overview

Dispatch data from a Rack request to the WAF context

Class Method Summary collapse

Class Method Details

.publish(op, gateway_request) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/datadog/appsec/contrib/rack/reactive/request_body.rb', line 15

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

    nil
  end
end

.subscribe(op, waf_context) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/datadog/appsec/contrib/rack/reactive/request_body.rb', line 24

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

    waf_args = {
      'server.request.body' => body,
    }

    waf_timeout = Datadog.configuration.appsec.waf_timeout
    result = waf_context.run(waf_args, waf_timeout)

    Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout

    case result.status
    when :match
      Datadog.logger.debug { "WAF: #{result.inspect}" }

      yield result
      throw(:block, true) unless result.actions.empty?
    when :ok
      Datadog.logger.debug { "WAF OK: #{result.inspect}" }
    when :invalid_call
      Datadog.logger.debug { "WAF CALL ERROR: #{result.inspect}" }
    when :invalid_rule, :invalid_flow, :no_rule
      Datadog.logger.debug { "WAF RULE ERROR: #{result.inspect}" }
    else
      Datadog.logger.debug { "WAF UNKNOWN: #{result.status.inspect} #{result.inspect}" }
    end
  end
end