18
19
20
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
46
47
48
49
|
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 18
def watch_user_id(gateway = Instrumentation.gateway)
gateway.watch('identity.set_user', :appsec) do |stack, user|
context = Datadog::AppSec.active_context
if user.id.nil? && user.login.nil?
Datadog.logger.debug { 'AppSec: skipping WAF check because no user information was provided' }
next stack.call(user)
end
persistent_data = {}
persistent_data['usr.id'] = user.id if user.id
persistent_data['usr.login'] = user.login if user.login
result = context.run_waf(persistent_data, {}, Datadog.configuration.appsec.waf_timeout)
if result.match?
Datadog::AppSec::Event.tag_and_keep!(context, result)
context.events << {
waf_result: result,
trace: context.trace,
span: context.span,
user: user,
actions: result.actions
}
Datadog::AppSec::ActionsHandler.handle(result.actions)
end
stack.call(user)
end
end
|