Sha256: 9be919f94123d1df8a6385cc55ffebfeb49e707df33390bd1de4dec66271f9b1

Contents?: true

Size: 1.94 KB

Versions: 21

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

module Datadog
  module AppSec
    module Contrib
      module Sinatra
        module Reactive
          # Dispatch data from a Sinatra request to the WAF context
          module Routed
            ADDRESSES = [
              'sinatra.request.route_params',
            ].freeze
            private_constant :ADDRESSES

            def self.publish(op, data)
              _request, route_params = data

              catch(:block) do
                op.publish('sinatra.request.route_params', route_params.params)

                nil
              end
            end

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

                waf_args = {
                  'server.request.path_params' => path_params,
                }

                waf_timeout = Datadog.configuration.appsec.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}" }

                  yield result
                  throw(:block, true) unless result.actions.empty?
                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
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
datadog-2.4.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.3.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.2.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.23.3 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.23.2 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.1.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.0.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.23.1 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.0.0.beta2 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.22.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.0.0.beta1 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.21.1 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.21.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.20.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.19.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.18.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.17.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.16.2 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.16.1 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
ddtrace-1.16.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb