module Airbrake::Filters::KeysFilter

def call(notice)

Other tags:
    See: FilterChain -

Returns:
  • (void) -

Parameters:
  • notice (Notice) -- the notice to be filtered
def call(notice)
  unless @valid_patterns
    eval_proc_patterns!
    validate_patterns
  end
  FILTERABLE_KEYS.each { |key| filter_hash(notice[key]) }
  FILTERABLE_CONTEXT_KEYS.each { |key| filter_context_key(notice, key) }
  return unless notice[:context][:url]
  filter_url(notice)
end

def eval_proc_patterns!

def eval_proc_patterns!
  return unless @patterns.any? { |pattern| pattern.is_a?(Proc) }
  @patterns = @patterns.flat_map do |pattern|
    next(pattern) unless pattern.respond_to?(:call)
    pattern.call
  end
end

def filter_context_key(notice, key)

def filter_context_key(notice, key)
  return unless notice[:context][key]
  return if notice[:context][key] == FILTERED
  return filter_hash(notice[:context][key]) unless should_filter?(key)
  notice[:context][key] = FILTERED
end

def filter_hash(hash)

def filter_hash(hash)
  hash.each_key do |key|
    if should_filter?(key.to_s)
      hash[key] = FILTERED
    elsif hash[key].is_a?(Hash)
      filter_hash(hash[key])
    end
  end
end

def filter_url(notice)

def filter_url(notice)
  begin
    url = URI(notice[:context][:url])
  rescue URI::InvalidURIError
    return
  end
  return unless url.query
  notice[:context][:url] = filter_url_params(url)
end

def filter_url_params(url)

def filter_url_params(url)
  url.query = Hash[URI.decode_www_form(url.query)].map do |key, val|
    # Ruby < 2.2 raises InvalidComponentError if the query contains
    # invalid characters, so be sure to escape individual components.
    if should_filter?(key)
      "#{URI.encode_www_form_component(key)}=[Filtered]"
    else
      "#{URI.encode_www_form_component(key)}=#{URI.encode_www_form_component(val)}"
    end
  end.join('&')
  url.to_s
end

def initialize(logger, patterns)

Parameters:
  • patterns (Array) --
  • logger (Logger, #error) --
def initialize(logger, patterns)
  @logger = logger
  @patterns = patterns
  @valid_patterns = false
end

def should_filter?(_key)

Raises:
  • (NotImplementedError) - if called directly
def should_filter?(_key)
  raise NotImplementedError, 'method must be implemented in the included class'
end

def validate_patterns

def validate_patterns
  @valid_patterns = @patterns.all? do |pattern|
    VALID_PATTERN_CLASSES.any? { |c| pattern.is_a?(c) }
  end
  return if @valid_patterns
  @logger.error(
    "#{LOG_LABEL} one of the patterns in #{self.class} is invalid. " \
    "Known patterns: #{@patterns}"
  )
end