|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require_relative '../../../instrumentation/gateway'
|
4 |
| -require_relative '../../../reactive/engine' |
5 |
| -require_relative '../reactive/routed' |
6 | 4 | require_relative '../../../event'
|
7 | 5 |
|
8 | 6 | module Datadog
|
@@ -50,31 +48,27 @@ def watch_request_dispatch(gateway = Instrumentation.gateway)
|
50 | 48 |
|
51 | 49 | def watch_request_routed(gateway = Instrumentation.gateway)
|
52 | 50 | gateway.watch('sinatra.request.routed', :appsec) do |stack, (gateway_request, gateway_route_params)|
|
53 |
| - event = nil |
54 | 51 | context = gateway_request.env[Datadog::AppSec::Ext::CONTEXT_KEY]
|
55 |
| - engine = AppSec::Reactive::Engine.new |
56 |
| - |
57 |
| - Sinatra::Reactive::Routed.subscribe(engine, context) do |result| |
58 |
| - if result.match? |
59 |
| - # TODO: should this hash be an Event instance instead? |
60 |
| - event = { |
61 |
| - waf_result: result, |
62 |
| - trace: context.trace, |
63 |
| - span: context.span, |
64 |
| - request: gateway_request, |
65 |
| - actions: result.actions |
66 |
| - } |
67 |
| - |
68 |
| - # We want to keep the trace in case of security event |
69 |
| - context.trace.keep! if context.trace |
70 |
| - Datadog::AppSec::Event.tag_and_keep!(context, result) |
71 |
| - context.events << event |
72 |
| - |
73 |
| - Datadog::AppSec::ActionsHandler.handle(result.actions) |
74 |
| - end |
75 |
| - end |
76 | 52 |
|
77 |
| - Sinatra::Reactive::Routed.publish(engine, [gateway_request, gateway_route_params]) |
| 53 | + persistent_data = { |
| 54 | + 'server.request.path_params' => gateway_route_params.params |
| 55 | + } |
| 56 | + |
| 57 | + result = context.run_waf(persistent_data, {}, Datadog.configuration.appsec.waf_timeout) |
| 58 | + |
| 59 | + if result.match? |
| 60 | + Datadog::AppSec::Event.tag_and_keep!(context, result) |
| 61 | + |
| 62 | + context.events << { |
| 63 | + waf_result: result, |
| 64 | + trace: context.trace, |
| 65 | + span: context.span, |
| 66 | + request: gateway_request, |
| 67 | + actions: result.actions |
| 68 | + } |
| 69 | + |
| 70 | + Datadog::AppSec::ActionsHandler.handle(result.actions) |
| 71 | + end |
78 | 72 |
|
79 | 73 | stack.call(gateway_request.request)
|
80 | 74 | end
|
|
0 commit comments