Skip to content

Commit

Permalink
Skip sequential strings in the right spot
Browse files Browse the repository at this point in the history
Made an is_sequential_string function
Prefixed existing sequential secrets with BEEF
  • Loading branch information
KevinHock committed Aug 1, 2018
1 parent 87f86b1 commit 1cb5e89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
14 changes: 9 additions & 5 deletions detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def calculate_shannon_entropy(self, data):

return entropy

def is_sequential_string(self, string):
uppercased_string = string.upper()
for sequential_string in IGNORED_SEQUENTIAL_STRINGS:
if uppercased_string in sequential_string:
return True
return False

def analyze_string(self, string, line_num, filename):
"""Searches string for custom pattern, and captures all high entropy strings that
match self.regex, with a limit defined as self.entropy_limit.
Expand All @@ -92,12 +99,9 @@ def analyze_string(self, string, line_num, filename):
if WHITELIST_REGEX.search(string):
return output

uppercased_string = string.upper()
for sequential_string in IGNORED_SEQUENTIAL_STRINGS:
if uppercased_string in sequential_string:
return output

for result in self.secret_generator(string):
if self.is_sequential_string(result):
continue
secret = PotentialSecret(self.secret_type, filename, line_num, result)
output[secret] = secret

Expand Down
3 changes: 2 additions & 1 deletion test_data/short_files/first_line.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
secret = '0123456789a'
secret = 'BEEF0123456789a'
skipped_sequential_false_positive = '0123456789a'
print('second line')
var = 'third line'
2 changes: 1 addition & 1 deletion tests/core/baseline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_single_non_tracked_git_file_should_work(self):
'detect_secrets.core.baseline.os.path.isfile',
return_value=True,
), mock_open(
'Super hidden value "0123456789a"',
'Super hidden value "BEEF0123456789a"',
'detect_secrets.core.secrets_collection.codecs.open',
):
results = self.get_results('will_be_mocked')
Expand Down
7 changes: 4 additions & 3 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ def test_old_baseline_ignored_with_update_flag(
(
'test_data/short_files/first_line.py',
textwrap.dedent("""
1:secret = '0123456789a'
2:print('second line')
3:var = 'third line'
1:secret = 'BEEF0123456789a'
2:skipped_sequential_false_positive = '0123456789a'
3:print('second line')
4:var = 'third line'
""")[1:-1],
),
(
Expand Down

0 comments on commit 1cb5e89

Please sign in to comment.