Module: Datadog::AppSec::Monitor::Gateway::Watcher
- Defined in:
- lib/datadog/appsec/monitor/gateway/watcher.rb
Overview
Watcher for Apssec internal events
Constant Summary collapse
- ARBITRARY_VALUE =
'invalid'
- EVENT_LOGIN_SUCCESS =
'users.login.success'
- EVENT_LOGIN_FAILURE =
'users.login.failure'
- WATCHED_LOGIN_EVENTS =
[EVENT_LOGIN_SUCCESS, EVENT_LOGIN_FAILURE].freeze
Class Method Summary collapse
- .watch ⇒ Object
- .watch_user_id(gateway = Instrumentation.gateway) ⇒ Object
- .watch_user_login(gateway = Instrumentation.gateway) ⇒ Object
Class Method Details
.watch ⇒ Object
19 20 21 22 23 24 |
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 19 def watch gateway = Instrumentation.gateway watch_user_id(gateway) watch_user_login(gateway) end |
.watch_user_id(gateway = Instrumentation.gateway) ⇒ Object
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 52 53 54 55 |
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 26 def watch_user_id(gateway = Instrumentation.gateway) gateway.watch('identity.set_user', :appsec) do |stack, user| context = AppSec.active_context if user.id.nil? && user.login.nil? && user.session_id.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 persistent_data['usr.session_id'] = user.session_id if user.session_id result = context.run_waf(persistent_data, {}, Datadog.configuration.appsec.waf_timeout) if result.match? || result.derivatives.any? 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(user) end end |
.watch_user_login(gateway = Instrumentation.gateway) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/datadog/appsec/monitor/gateway/watcher.rb', line 57 def watch_user_login(gateway = Instrumentation.gateway) gateway.watch('appsec.events.user_lifecycle', :appsec) do |stack, kind| context = AppSec.active_context next stack.call(kind) unless WATCHED_LOGIN_EVENTS.include?(kind) persistent_data = {"server.business_logic.#{kind}" => ARBITRARY_VALUE} result = context.run_waf(persistent_data, {}, Datadog.configuration.appsec.waf_timeout) if result.match? || result.derivatives.any? 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(kind) end end |