Skip to content

adding filters.heuristic.is_not_alphanumeric_string #428

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

Merged
merged 3 commits into from
Mar 31, 2021
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
8 changes: 8 additions & 0 deletions detect_secrets/filters/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ def is_lock_file(filename: str) -> bool:
}


def is_not_alphanumeric_string(secret: str) -> bool:
"""
This assumes that secrets should have at least ONE letter in them.
This helps avoid clear false positives, like `*****`.
"""
return not bool(set(string.ascii_letters) & set(secret))


def is_swagger_file(filename: str) -> bool:
"""
Filters swagger files and paths, like swagger-ui.html or /swagger/.
Expand Down
1 change: 1 addition & 0 deletions detect_secrets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def clear(self) -> None:
'detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign',
'detect_secrets.filters.heuristic.is_indirect_reference',
'detect_secrets.filters.heuristic.is_lock_file',
'detect_secrets.filters.heuristic.is_not_alphanumeric_string',
'detect_secrets.filters.heuristic.is_swagger_file',
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ the `detect_secrets.filters` namespace.
| `heuristic.is_likely_id_string` | Ignores secret values prefixed with `id`. |
| `heuristic.is_lock_file` | Ignores common lock files. |
| `heuristic.is_non_text_file` | Ignores non-text files (e.g. archives, images). |
| `heuristic.is_not_alphanumeric_string` | Ignores secrets that do not have a single alphanumeric character in it. |
| `heuristic.is_potential_uuid` | Ignores uuid looking secret values. |
| `heuristic.is_prefixed_with_dollar_sign` | Primarily for `KeywordDetector`, filters secrets like `secret = $variableName;`. |
| `heuristic.is_sequential_string` | Ignores secrets like `abcdefg`. |
Expand Down
4 changes: 2 additions & 2 deletions test_data/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ keyA =
value3
; This is another comment

keyB = 456789123
567891234
keyB = 456789123a
567891234b

keyC =

Expand Down
2 changes: 0 additions & 2 deletions tests/core/secrets_collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def test_file_based_success_config():

assert [str(secret).splitlines()[1] for _, secret in secrets] == [
'Location: test_data/config.ini:2',
'Location: test_data/config.ini:6',
'Location: test_data/config.ini:10',
'Location: test_data/config.ini:15',
'Location: test_data/config.ini:21',
'Location: test_data/config.ini:22',
'Location: test_data/config.ini:32',
Expand Down
11 changes: 11 additions & 0 deletions tests/filters/heuristic_filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ def test_is_lock_file():
assert not filters.heuristic.is_lock_file('Gemfilealock')


@pytest.mark.parametrize(
'secret, result',
(
('*****', True),
('a&b23?!', False),
),
)
def test_is_not_alphanumeric_string(secret, result):
assert filters.heuristic.is_not_alphanumeric_string(secret) is result


@pytest.mark.parametrize(
'filename, result',
(
Expand Down