Skip to content

Commit

Permalink
RUBY-2315 Replace references to whitelist and blacklist where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Klein committed Oct 26, 2019
1 parent 9729d18 commit e308936
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions lib/new_relic/agent/attribute_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def initialize(config)
@high_security = config[:high_security]

setup_key_cache
cache_prefix_blacklist
cache_prefix_denylist
end

# Note the key_cache is a global cache, accessible by multiple threads,
Expand Down Expand Up @@ -222,16 +222,16 @@ def high_security?
# arguments for Sidekiq and Resque in the common case, since none of
# these attributes are captured by default.
#
def cache_prefix_blacklist
@prefix_blacklist = {}
@prefix_blacklist[:'request.parameters'] = true unless might_allow_prefix_uncached?(:'request.parameters')
@prefix_blacklist[:'job.sidekiq.args'] = true unless might_allow_prefix_uncached?(:'job.sidekiq.args')
@prefix_blacklist[:'job.resque.args'] = true unless might_allow_prefix_uncached?(:'job.resque.args')
def cache_prefix_denylist
@prefix_denylist = {}
@prefix_denylist[:'request.parameters'] = true unless might_allow_prefix_uncached?(:'request.parameters')
@prefix_denylist[:'job.sidekiq.args'] = true unless might_allow_prefix_uncached?(:'job.sidekiq.args')
@prefix_denylist[:'job.resque.args'] = true unless might_allow_prefix_uncached?(:'job.resque.args')
end

# Note that the given prefix *must* be a Symbol
def might_allow_prefix?(prefix)
!@prefix_blacklist.include?(prefix)
!@prefix_denylist.include?(prefix)
end

def might_allow_prefix_uncached?(prefix)
Expand Down
4 changes: 2 additions & 2 deletions lib/new_relic/agent/datastores/mongo/event_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module EventFormatter
OBFUSCATE_KEYS = [ 'filter', 'query', 'pipeline' ].freeze

# Keys that will get completely removed from the statement.
BLACKLISTED_KEYS = [ 'deletes', 'documents', 'updates' ].freeze
DENYLISTED_KEYS = [ 'deletes', 'documents', 'updates' ].freeze

def self.format(command_name, database_name, command)
return nil unless NewRelic::Agent.config[:'mongo.capture_queries']
Expand All @@ -25,7 +25,7 @@ def self.format(command_name, database_name, command)
}

command.each do |key, value|
next if BLACKLISTED_KEYS.include?(key)
next if DENYLISTED_KEYS.include?(key)
if OBFUSCATE_KEYS.include?(key)
obfuscated = obfuscate(value)
result[key] = obfuscated if obfuscated
Expand Down
16 changes: 8 additions & 8 deletions lib/new_relic/agent/datastores/mongo/obfuscator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ module Datastores
module Mongo
module Obfuscator

WHITELIST = [:operation].freeze
ALLOWLIST = [:operation].freeze

def self.obfuscate_statement(source, whitelist = WHITELIST)
def self.obfuscate_statement(source, allowlist = ALLOWLIST)
if source.is_a? Hash
obfuscated = {}
source.each do |key, value|
if whitelist.include?(key)
if allowlist.include?(key)
obfuscated[key] = value
else
obfuscated[key] = obfuscate_value(value, whitelist)
obfuscated[key] = obfuscate_value(value, allowlist)
end
end
obfuscated
else
obfuscate_value(source, whitelist)
obfuscate_value(source, allowlist)
end
end

QUESTION_MARK = '?'.freeze

def self.obfuscate_value(value, whitelist = WHITELIST)
def self.obfuscate_value(value, allowlist = ALLOWLIST)
if value.is_a?(Hash)
obfuscate_statement(value, whitelist)
obfuscate_statement(value, allowlist)
elsif value.is_a?(Array)
value.map {|v| obfuscate_value(v, whitelist)}
value.map {|v| obfuscate_value(v, allowlist)}
else
QUESTION_MARK
end
Expand Down
2 changes: 1 addition & 1 deletion test/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def assert_metrics_recorded(expected)
#
# If you want to *allow* unexpected metrics matching certain patterns, use
# the :ignore_filter option. This will allow you to specify a Regex that
# whitelists broad swathes of metric territory (e.g. 'Supportability/').
# allowlists broad swathes of metric territory (e.g. 'Supportability/').
#
def assert_metrics_recorded_exclusive(expected, options={})
expected = _normalize_metric_expectations(expected)
Expand Down
6 changes: 3 additions & 3 deletions test/environments/lib/environments/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Environments
class Runner
include Multiverse::Color

BLACKLIST = {
DENYLIST = {
"2.4.2" => ["rails60"],
"2.3.5" => ["rails60"],
"2.2.1" => ["rails50", "rails60"],
Expand Down Expand Up @@ -66,9 +66,9 @@ def tests_to_run
version = RUBY_VERSION
version = "jruby-#{JRUBY_VERSION[0..2]}" if defined?(JRUBY_VERSION)

BLACKLIST.each do |check_version, blacklisted|
DENYLIST.each do |check_version, denylisted|
if version.start_with?(check_version)
dirs.reject! {|d| blacklisted.include?(File.basename(d)) }
dirs.reject! {|d| denylisted.include?(File.basename(d)) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/new_relic/agent/datastores/mongo/obfuscator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_obfuscator_removes_values_from_statement
assert_equal expected, obfuscated
end

def test_obfuscate_selector_values_skips_whitelisted_keys
def test_obfuscate_selector_values_skips_allowed_keys
selector = {
:benign => 'bland data',
:operation => :find,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StatementFormatterTest < Minitest::Test
:limit => -1,
:order => :ascending,

:ignored => "we're whitelisted!",
:ignored => "we're allowed!",
:documents => [ { "name" => "soterios johnson",
:_id => "BSON::ObjectId()" } ] }.freeze

Expand All @@ -34,7 +34,7 @@ def test_doesnt_modify_incoming_statement
refute_same DOC_STATEMENT, formatted
end

def test_statement_formatter_removes_unwhitelisted_keys
def test_statement_formatter_removes_disallowed_keys
formatted = StatementFormatter.format(DOC_STATEMENT, :find)
assert_equal_unordered(formatted.keys, StatementFormatter::PLAINTEXT_KEYS)
end
Expand Down

0 comments on commit e308936

Please sign in to comment.