Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/raven/processor/sanitizedata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Processor::SanitizeData < Processor
STRING_MASK = '********'
INT_MASK = 0
DEFAULT_FIELDS = %w(authorization password passwd secret ssn social(.*)?sec)
VALUES_RE = /^\d{16}$/
CREDIT_CARD_RE = /^(?:\d[ -]*?){13,16}$/

def process(value)
value.inject(value) { |memo,(k,v)| memo[k] = sanitize(k,v); memo }
Expand All @@ -17,9 +17,9 @@ def sanitize(k,v)
elsif v.is_a?(String) && (json = parse_json_or_nil(v))
#if this string is actually a json obj, convert and sanitize
json.is_a?(Hash) ? process(json).to_json : v
elsif v.is_a?(Integer) && (VALUES_RE.match(v.to_s) || fields_re.match(k.to_s))
elsif v.is_a?(Integer) && (CREDIT_CARD_RE.match(v.to_s) || fields_re.match(k.to_s))
INT_MASK
elsif v.is_a?(String) && (VALUES_RE.match(v.to_s) || fields_re.match(k.to_s))
elsif v.is_a?(String) && (CREDIT_CARD_RE.match(v.to_s) || fields_re.match(k.to_s))
STRING_MASK
else
v
Expand Down
3 changes: 3 additions & 0 deletions spec/raven/processors/sanitizedata_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@
it 'should filter credit card values' do
data = {
'ccnumba' => '4242424242424242',
'ccnumba_13' => '4242424242424',
'ccnumba-dash' => '4242-4242-4242-4242',
'ccnumba_int' => 4242424242424242,
}

result = @processor.process(data)
expect(result["ccnumba"]).to eq(Raven::Processor::SanitizeData::STRING_MASK)
expect(result["ccnumba_13"]).to eq(Raven::Processor::SanitizeData::STRING_MASK)
expect(result["ccnumba_int"]).to eq(Raven::Processor::SanitizeData::INT_MASK)
end

Expand Down