22
23
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
|
# File 'lib/datadog/appsec/contrib/rails/gateway/watcher.rb', line 22
def watch_request_action(gateway = Instrumentation.gateway)
gateway.watch('rails.request.action', :appsec) do |stack, gateway_request|
event = nil
context = gateway_request.env[Datadog::AppSec::Ext::CONTEXT_KEY]
engine = AppSec::Reactive::Engine.new
Rails::Reactive::Action.subscribe(engine, context) do |result|
if result.status == :match
event = {
waf_result: result,
trace: context.trace,
span: context.span,
request: gateway_request,
actions: result.actions
}
context.trace.keep! if context.trace
Datadog::AppSec::Event.tag_and_keep!(context, result)
context.waf_runner.events << event
end
end
block = Rails::Reactive::Action.publish(engine, gateway_request)
next [nil, [[:block, event]]] if block
stack.call(gateway_request.request)
end
end
|