Sha256: 05a52c544bac03f8c61ef142002650b051c0882dd53f07dc095d4876c30286d7

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module Datadog
  module AppSec
    module Monitor
      module Reactive
        # Dispatch data from Datadog::Kit::Identity.set_user to the WAF context
        module SetUser
          ADDRESSES = [
            'usr.id',
          ].freeze
          private_constant :ADDRESSES

          def self.publish(op, user)
            catch(:block) do
              op.publish('usr.id', user.id)

              nil
            end
          end

          def self.subscribe(op, waf_context)
            op.subscribe(*ADDRESSES) do |*values|
              Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }

              user_id = values[0]

              waf_args = {
                'usr.id' => user_id,
              }

              waf_timeout = Datadog::AppSec.settings.waf_timeout
              result = waf_context.run(waf_args, waf_timeout)

              Datadog.logger.debug { "WAF TIMEOUT: #{result.inspect}" } if result.timeout

              case result.status
              when :match
                Datadog.logger.debug { "WAF: #{result.inspect}" }

                block = result.actions.include?('block')

                yield [result, block]

                throw(:block, [result, true]) if block
              when :ok
                Datadog.logger.debug { "WAF OK: #{result.inspect}" }
              when :invalid_call
                Datadog.logger.debug { "WAF CALL ERROR: #{result.inspect}" }
              when :invalid_rule, :invalid_flow, :no_rule
                Datadog.logger.debug { "WAF RULE ERROR: #{result.inspect}" }
              else
                Datadog.logger.debug { "WAF UNKNOWN: #{result.status.inspect} #{result.inspect}" }
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ddtrace-1.12.1 lib/datadog/appsec/monitor/reactive/set_user.rb
ddtrace-1.12.0 lib/datadog/appsec/monitor/reactive/set_user.rb
ddtrace-1.11.1 lib/datadog/appsec/monitor/reactive/set_user.rb
ddtrace-1.11.0 lib/datadog/appsec/monitor/reactive/set_user.rb
ddtrace-1.11.0.beta1 lib/datadog/appsec/monitor/reactive/set_user.rb
ddtrace-1.10.1 lib/datadog/appsec/monitor/reactive/set_user.rb
ddtrace-1.10.0 lib/datadog/appsec/monitor/reactive/set_user.rb