Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Yelp/detect-secrets into feature/…
Browse files Browse the repository at this point in the history
…adding-alphanumerical-filter
  • Loading branch information
Aaron Loo committed Mar 31, 2021
2 parents e819add + c86ca85 commit f8fbf83
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ For baselines older than version 0.9, just recreate it.
**Scanning Staged Files Only:**

```bash
$ detect-secret-hook --baseline .secrets.baseline $(git diff --staged --name-only)
$ detect-secrets-hook --baseline .secrets.baseline $(git diff --staged --name-only)
```

**Scanning All Tracked Files:**
Expand Down
2 changes: 1 addition & 1 deletion detect_secrets/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def set_debug_level(self, debug_level: int) -> None:
)


log = get_logger()
log = get_logger('detect-secrets')
12 changes: 12 additions & 0 deletions detect_secrets/filters/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,15 @@ def is_not_alphanumeric_string(secret: str) -> bool:
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/.
"""
return bool(_get_swagger_regex().search(filename))


@lru_cache(maxsize=1)
def _get_swagger_regex() -> Pattern:
return re.compile(r'.*swagger.*')
1 change: 1 addition & 0 deletions detect_secrets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def clear(self) -> None:
'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 @@ -55,6 +55,7 @@ the `detect_secrets.filters` namespace.
| `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`. |
| `heuristic.is_swagger_file` | Ignores swagger files and paths, like swagger-ui.html or /swagger/. |
| `heuristic.is_templated_secret` | Ignores secrets like `secret = <key>`, `secret = {{key}}` and `secret = ${key}`. |
| `regex.should_exclude_line` | Powers the [`--exclude-lines` functionality](../README.md#--exclude-lines). |
| `regex.should_exclude_file` | Powers the [`--exclude-files` functionality](../README.md#--exclude-files). |
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pycodestyle==2.3.1
pyflakes==1.6.0
pyparsing==2.4.7
pytest==6.1.2
PyYAML==5.3.1
PyYAML==5.4
requests==2.25.0
responses==0.12.1
six==1.15.0
Expand All @@ -37,6 +37,6 @@ tox-pip-extensions==1.6.0
typed-ast==1.4.1
typing-extensions==3.7.4.3
unidiff==0.6.0
urllib3==1.26.2
urllib3==1.26.3
virtualenv==20.2.1
zipp==3.4.0
14 changes: 14 additions & 0 deletions tests/filters/heuristic_filter_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest

from detect_secrets import filters
Expand Down Expand Up @@ -141,3 +143,15 @@ def test_is_lock_file():
)
def test_is_not_alphanumeric_string(secret, result):
assert filters.heuristic.is_not_alphanumeric_string(secret) is result


@pytest.mark.parametrize(
'filename, result',
(
('{sep}path{sep}swagger-ui.html', True),
('{sep}path{sep}swagger{sep}config.yml', True),
('{sep}path{sep}non{sep}swager{sep}files', False),
),
)
def test_is_swagger_file(filename, result):
assert filters.heuristic.is_swagger_file(filename.format(sep=os.path.sep)) is result

0 comments on commit f8fbf83

Please sign in to comment.