File tree 6 files changed +23
-4
lines changed
6 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,14 @@ def is_lock_file(filename: str) -> bool:
197
197
}
198
198
199
199
200
+ def is_not_alphanumeric_string (secret : str ) -> bool :
201
+ """
202
+ This assumes that secrets should have at least ONE letter in them.
203
+ This helps avoid clear false positives, like `*****`.
204
+ """
205
+ return not bool (set (string .ascii_letters ) & set (secret ))
206
+
207
+
200
208
def is_swagger_file (filename : str ) -> bool :
201
209
"""
202
210
Filters swagger files and paths, like swagger-ui.html or /swagger/.
Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ def clear(self) -> None:
119
119
'detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign' ,
120
120
'detect_secrets.filters.heuristic.is_indirect_reference' ,
121
121
'detect_secrets.filters.heuristic.is_lock_file' ,
122
+ 'detect_secrets.filters.heuristic.is_not_alphanumeric_string' ,
122
123
'detect_secrets.filters.heuristic.is_swagger_file' ,
123
124
}
124
125
}
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ the `detect_secrets.filters` namespace.
51
51
| ` heuristic.is_likely_id_string ` | Ignores secret values prefixed with ` id ` . |
52
52
| ` heuristic.is_lock_file ` | Ignores common lock files. |
53
53
| ` heuristic.is_non_text_file ` | Ignores non-text files (e.g. archives, images). |
54
+ | ` heuristic.is_not_alphanumeric_string ` | Ignores secrets that do not have a single alphanumeric character in it. |
54
55
| ` heuristic.is_potential_uuid ` | Ignores uuid looking secret values. |
55
56
| ` heuristic.is_prefixed_with_dollar_sign ` | Primarily for ` KeywordDetector ` , filters secrets like ` secret = $variableName; ` . |
56
57
| ` heuristic.is_sequential_string ` | Ignores secrets like ` abcdefg ` . |
Original file line number Diff line number Diff line change 18
18
value3
19
19
; This is another comment
20
20
21
- keyB = 456789123
22
- 567891234
21
+ keyB = 456789123a
22
+ 567891234b
23
23
24
24
keyC =
25
25
Original file line number Diff line number Diff line change @@ -81,9 +81,7 @@ def test_file_based_success_config():
81
81
82
82
assert [str (secret ).splitlines ()[1 ] for _ , secret in secrets ] == [
83
83
'Location: test_data/config.ini:2' ,
84
- 'Location: test_data/config.ini:6' ,
85
84
'Location: test_data/config.ini:10' ,
86
- 'Location: test_data/config.ini:15' ,
87
85
'Location: test_data/config.ini:21' ,
88
86
'Location: test_data/config.ini:22' ,
89
87
'Location: test_data/config.ini:32' ,
Original file line number Diff line number Diff line change @@ -134,6 +134,17 @@ def test_is_lock_file():
134
134
assert not filters .heuristic .is_lock_file ('Gemfilealock' )
135
135
136
136
137
+ @pytest .mark .parametrize (
138
+ 'secret, result' ,
139
+ (
140
+ ('*****' , True ),
141
+ ('a&b23?!' , False ),
142
+ ),
143
+ )
144
+ def test_is_not_alphanumeric_string (secret , result ):
145
+ assert filters .heuristic .is_not_alphanumeric_string (secret ) is result
146
+
147
+
137
148
@pytest .mark .parametrize (
138
149
'filename, result' ,
139
150
(
You can’t perform that action at this time.
0 commit comments