Module: Datadog::AppSec::Contrib::Rails::Patcher::ProcessActionPatch

Defined in:
lib/datadog/appsec/contrib/rails/patcher.rb

Overview

Hook into ActionController::Instrumentation#process_action, which encompasses action filters

Instance Method Summary collapse

Instance Method Details

#process_action(*args) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/datadog/appsec/contrib/rails/patcher.rb', line 72

def process_action(*args)
  env = request.env

  context = env['datadog.waf.context']

  return super unless context

  # TODO: handle exceptions, except for super

  gateway_request = Gateway::Request.new(request)
  request_return, request_response = Instrumentation.gateway.push('rails.request.action', gateway_request) do
    super
  end

  if request_response && request_response.any? { |action, _event| action == :block }
    @_response = AppSec::Response.negotiate(env).to_action_dispatch_response
    request_return = @_response.body
  end

  request_return
end