21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/datadog/appsec/contrib/rails/gateway/watcher.rb', line 21
def watch_request_action(gateway = Instrumentation.gateway)
gateway.watch('rails.request.action', :appsec) do |stack, gateway_request|
context = gateway_request.env[AppSec::Ext::CONTEXT_KEY]
persistent_data = {
'server.request.body' => gateway_request.parsed_body,
'server.request.path_params' => gateway_request.route_params
}
result = context.run_waf(persistent_data, {}, Datadog.configuration.appsec.waf_timeout)
if result.match? || !result.derivatives.empty?
context.events.push(
AppSec::SecurityEvent.new(result, trace: context.trace, span: context.span)
)
end
if result.match?
AppSec::Event.tag_and_keep!(context, result)
AppSec::ActionsHandler.handle(result.actions)
end
stack.call(gateway_request.request)
end
end
|