Sha256: 243a45cad24a32c72f616b5c02f3acfed02d085905665777956d6c6990c0232a

Contents?: true

Size: 1.6 KB

Versions: 9

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module NewRelic
  module Agent
    module ParameterFiltering
      extend self

      ACTION_DISPATCH_PARAMETER_FILTER = "action_dispatch.parameter_filter".freeze

      RAILS_FILTER_CLASS = if defined?(ActiveSupport::ParameterFilter)
         ActiveSupport::ParameterFilter
      elsif defined?(ActionDispatch::Http::ParameterFilter)
        ActionDispatch::Http::ParameterFilter
      else
        nil
      end

      def apply_filters(env, params)
        if filters = env[ACTION_DISPATCH_PARAMETER_FILTER]
          params = filter_using_rails(params, filters) 
        end
        params = filter_rack_file_data(env, params)
        params
      end

      def filter_using_rails(params, filters)
        return params if RAILS_FILTER_CLASS.nil?

        pre_filtered_params = filter_rails_request_parameters(params)
        RAILS_FILTER_CLASS.new(filters).filter(pre_filtered_params)
      end

      def filter_rack_file_data(env, params)
        content_type = env["CONTENT_TYPE"]
        multipart = content_type && content_type.start_with?("multipart")

        params.inject({}) do |memo, (k,v)|
          if multipart && v.is_a?(Hash) && v[:tempfile]
            memo[k] = "[FILE]"
          else
            memo[k] = v
          end
          memo
        end
      end

      def filter_rails_request_parameters(params)
        result = params.dup
        result.delete("controller")
        result.delete("action")
        result
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
newrelic_rpm-6.11.0.365 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.10.0.364 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.9.0.363 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.8.0.360 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.7.0.359 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.6.0.358 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.5.0.357 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.4.0.356 lib/new_relic/agent/parameter_filtering.rb
newrelic_rpm-6.3.0.355 lib/new_relic/agent/parameter_filtering.rb