Skip to content

Commit e819add

Browse files
author
Aaron Loo
committed
adding filters.heuristic.is_not_alphanumeric_string
1 parent a735e2e commit e819add

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

detect_secrets/filters/heuristic.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,11 @@ def is_lock_file(filename: str) -> bool:
195195
'Podfile.lock',
196196
'yarn.lock',
197197
}
198+
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))

detect_secrets/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def clear(self) -> None:
119119
'detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign',
120120
'detect_secrets.filters.heuristic.is_indirect_reference',
121121
'detect_secrets.filters.heuristic.is_lock_file',
122+
'detect_secrets.filters.heuristic.is_not_alphanumeric_string',
122123
}
123124
}
124125

docs/filters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ the `detect_secrets.filters` namespace.
5151
| `heuristic.is_likely_id_string` | Ignores secret values prefixed with `id`. |
5252
| `heuristic.is_lock_file` | Ignores common lock files. |
5353
| `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. |
5455
| `heuristic.is_potential_uuid` | Ignores uuid looking secret values. |
5556
| `heuristic.is_prefixed_with_dollar_sign` | Primarily for `KeywordDetector`, filters secrets like `secret = $variableName;`. |
5657
| `heuristic.is_sequential_string` | Ignores secrets like `abcdefg`. |

tests/filters/heuristic_filter_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,14 @@ def test_is_lock_file():
130130

131131
# assert non-regex
132132
assert not filters.heuristic.is_lock_file('Gemfilealock')
133+
134+
135+
@pytest.mark.parametrize(
136+
'secret, result',
137+
(
138+
('*****', True),
139+
('a&b23?!', False),
140+
),
141+
)
142+
def test_is_not_alphanumeric_string(secret, result):
143+
assert filters.heuristic.is_not_alphanumeric_string(secret) is result

0 commit comments

Comments
 (0)