Skip to content

Commit

Permalink
Added IGNORED_SEQUENTIAL_STRINGS to high_entropy_strings.py and adjus…
Browse files Browse the repository at this point in the history
…ted tests to pass
  • Loading branch information
KevinHock committed Jul 31, 2018
1 parent 451cd46 commit 15f3523
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
from detect_secrets.plugins.core.yaml_file_parser import YamlFileParser


IGNORED_SEQUENTIAL_STRINGS = (
'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/', # upper/lower, numbers +/
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ+/', # numbers, upper/lower +/
'ABCDEFABCDEF0123456789ABCDEFABCDEF', # Hex
'ABCDEFGHIJKLMNOPQRSTUVWXYZ=/',
)
YAML_EXTENSIONS = (
'.yaml',
'.yml',
Expand Down Expand Up @@ -75,12 +81,16 @@ 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.
"""

output = {}

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):
secret = PotentialSecret(self.secret_type, filename, line_num, result)
output[secret] = secret
Expand Down
1 change: 1 addition & 0 deletions test_data/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ credentials:
some_value_here: not_a_secret
other_value_here: 1234567890a
nested:
value: AKIAabcdefghijklmnop
value: abcdefghijklmnop
list_of_keys:
- 123
Expand Down
2 changes: 1 addition & 1 deletion test_data/short_files/last_line.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
secrets_for_no_one_to_find =
hunter2
password123
0123456789a
BEEF0123456789a
2 changes: 1 addition & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_old_baseline_ignored_with_update_flag(
2:secrets_for_no_one_to_find =
3: hunter2
4: password123
5: 0123456789a
5: BEEF0123456789a
""")[1:-1],
),
],
Expand Down
3 changes: 1 addition & 2 deletions tests/plugins/high_entropy_strings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ def test_yaml_file(self):
with open('test_data/config.yaml') as f:
secrets = plugin.analyze(f, 'test_data/config.yaml')

assert len(secrets.values()) == 2
assert len(secrets.values()) == 1
for secret in secrets.values():
location = str(secret).splitlines()[1]
assert location in (
'Location: test_data/config.yaml:3',
'Location: test_data/config.yaml:5',
)

def test_entropy_lower_limit(self):
Expand Down

0 comments on commit 15f3523

Please sign in to comment.