Sha256: 3114d553cc52a06d551f22e1ee21d8d145c709435bedf5366a578abc7dd0e46a

Contents?: true

Size: 1.19 KB

Versions: 17

Compression:

Stored size: 1.19 KB

Contents

require 'honeybadger/util/sanitizer'

module Honeybadger
  module Util
    # Internal: Constructs/sanitizes request data for notices
    module RequestPayload
      # Internal: Default values to use for request data.
      DEFAULTS = {
        url: nil,
        component: nil,
        action: nil,
        params: {}.freeze,
        session: {}.freeze,
        cgi_data: {}.freeze
      }.freeze

      # Internal: Allowed keys.
      KEYS = DEFAULTS.keys.freeze

      # Internal: The cgi_data key where the raw Cookie header is stored.
      HTTP_COOKIE_KEY = 'HTTP_COOKIE'.freeze

      def self.build(opts = {})
        sanitizer = opts.fetch(:sanitizer) { Sanitizer.new }

        payload = DEFAULTS.dup
        KEYS.each do |key|
          next unless opts[key]
          payload[key] = sanitizer.sanitize(opts[key])
        end

        payload[:session] = opts[:session][:data] if opts[:session] && opts[:session][:data]
        payload[:url] = sanitizer.filter_url(payload[:url]) if payload[:url]
        if payload[:cgi_data][HTTP_COOKIE_KEY]
          payload[:cgi_data][HTTP_COOKIE_KEY] = sanitizer.filter_cookies(payload[:cgi_data][HTTP_COOKIE_KEY])
        end

        payload
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
honeybadger-3.2.0 lib/honeybadger/util/request_payload.rb
honeybadger-3.2.0.beta1 lib/honeybadger/util/request_payload.rb
honeybadger-3.1.2 lib/honeybadger/util/request_payload.rb
honeybadger-3.1.1 lib/honeybadger/util/request_payload.rb
honeybadger-3.1.0 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.2 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.1 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.0 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.0.beta6 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.0.beta5 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.0.beta4 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.0.beta3 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.0.beta2 lib/honeybadger/util/request_payload.rb
honeybadger-2.7.2 lib/honeybadger/util/request_payload.rb
honeybadger-3.0.0.beta1 lib/honeybadger/util/request_payload.rb
honeybadger-2.7.1 lib/honeybadger/util/request_payload.rb
honeybadger-2.7.0 lib/honeybadger/util/request_payload.rb