Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip sequential strings in the right spot #67

Merged
merged 1 commit into from
Aug 1, 2018
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
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