Sha256: 4eba3c560468e4edd93196e76fe7a1241bb4b5532f154135ff95edcb57c35065

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 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]

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

                waf_timeout = Datadog.configuration.appsec.waf_timeout
                result = waf_context.run(persistent_data, {}, waf_timeout)

                next if result.status != :match

                yield result
                throw(:block, true) unless result.actions.empty?
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
datadog-2.8.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.7.1 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.7.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.6.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb
datadog-2.5.0 lib/datadog/appsec/contrib/sinatra/reactive/routed.rb