Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5135fc

Browse files
committed
Added IGNORED_SEQUENTIAL_STRINGS to high_entropy_strings.py and adjusted tests to pass
1 parent 451cd46 commit b5135fc

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

detect_secrets/plugins/high_entropy_strings.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
from detect_secrets.plugins.core.yaml_file_parser import YamlFileParser
1818

1919

20+
IGNORED_SEQUENTIAL_STRINGS = (
21+
(
22+
string.ascii_uppercase +
23+
string.ascii_uppercase +
24+
string.digits +
25+
string.ascii_uppercase +
26+
string.ascii_uppercase +
27+
'+/'
28+
),
29+
string.hexdigits.upper() + string.hexdigits.upper(),
30+
string.ascii_uppercase + '=/',
31+
)
2032
YAML_EXTENSIONS = (
2133
'.yaml',
2234
'.yml',
@@ -75,12 +87,16 @@ def analyze_string(self, string, line_num, filename):
7587
"""Searches string for custom pattern, and captures all high entropy strings that
7688
match self.regex, with a limit defined as self.entropy_limit.
7789
"""
78-
7990
output = {}
8091

8192
if WHITELIST_REGEX.search(string):
8293
return output
8394

95+
uppercased_string = string.upper()
96+
for sequential_string in IGNORED_SEQUENTIAL_STRINGS:
97+
if uppercased_string in sequential_string:
98+
return output
99+
84100
for result in self.secret_generator(string):
85101
secret = PotentialSecret(self.secret_type, filename, line_num, result)
86102
output[secret] = secret

test_data/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ credentials:
22
some_value_here: not_a_secret
33
other_value_here: 1234567890a
44
nested:
5+
value: AKIAabcdefghijklmnop
56
value: abcdefghijklmnop
67
list_of_keys:
78
- 123

test_data/short_files/last_line.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
secrets_for_no_one_to_find =
33
hunter2
44
password123
5-
0123456789a
5+
BEEF0123456789a

tests/main_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_old_baseline_ignored_with_update_flag(
172172
2:secrets_for_no_one_to_find =
173173
3: hunter2
174174
4: password123
175-
5: 0123456789a
175+
5: BEEF0123456789a
176176
""")[1:-1],
177177
),
178178
],

tests/plugins/high_entropy_strings_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,11 @@ def test_yaml_file(self):
148148
with open('test_data/config.yaml') as f:
149149
secrets = plugin.analyze(f, 'test_data/config.yaml')
150150

151-
assert len(secrets.values()) == 2
151+
assert len(secrets.values()) == 1
152152
for secret in secrets.values():
153153
location = str(secret).splitlines()[1]
154154
assert location in (
155155
'Location: test_data/config.yaml:3',
156-
'Location: test_data/config.yaml:5',
157156
)
158157

159158
def test_entropy_lower_limit(self):

0 commit comments

Comments
 (0)