Skip to content

Commit c3d5cbb

Browse files
committed
Remove reactive engine from AppSec sinatra instrumentation
1 parent 5252362 commit c3d5cbb

File tree

4 files changed

+19
-159
lines changed

4 files changed

+19
-159
lines changed

lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
require_relative '../../../instrumentation/gateway'
4-
require_relative '../../../reactive/engine'
5-
require_relative '../reactive/routed'
64
require_relative '../../../event'
75

86
module Datadog
@@ -50,31 +48,27 @@ def watch_request_dispatch(gateway = Instrumentation.gateway)
5048

5149
def watch_request_routed(gateway = Instrumentation.gateway)
5250
gateway.watch('sinatra.request.routed', :appsec) do |stack, (gateway_request, gateway_route_params)|
53-
event = nil
5451
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
7652

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
7872

7973
stack.call(gateway_request.request)
8074
end

lib/datadog/appsec/contrib/sinatra/reactive/routed.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

sig/datadog/appsec/contrib/sinatra/reactive/routed.rbs

Lines changed: 0 additions & 17 deletions
This file was deleted.

spec/datadog/appsec/contrib/sinatra/reactive/routed_spec.rb

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)