This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
forked from Yelp/detect-secrets
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Heuristic, false positive filters that are shared across all plugin types. | ||
This abstraction allows for development of later ML work, or further | ||
heuristical determinations (e.g. word filter, entropy comparator). | ||
""" | ||
import string | ||
|
||
|
||
def is_false_positive(secret): | ||
for func in [ | ||
is_sequential_string, | ||
]: | ||
if func(secret): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def is_sequential_string(secret): | ||
""" | ||
Returns true if string is sequential. | ||
""" | ||
sequences = ( | ||
( | ||
string.ascii_uppercase + | ||
string.ascii_uppercase + | ||
string.digits + | ||
string.ascii_uppercase + | ||
string.ascii_uppercase + | ||
'+/' | ||
), | ||
|
||
# Capturing any number sequences | ||
'0123456789' * 2, | ||
|
||
string.hexdigits.upper() + string.hexdigits.upper(), | ||
string.ascii_uppercase + '=/', | ||
) | ||
|
||
uppercase = secret.upper() | ||
for sequential_string in sequences: | ||
if uppercase in sequential_string: | ||
return True | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import absolute_import | ||
|
||
import pytest | ||
|
||
from detect_secrets.plugins.common import filters | ||
|
||
|
||
class TestIsSequentialString: | ||
# TODO: More tests should be had. | ||
|
||
@pytest.mark.parametrize( | ||
'secret', | ||
( | ||
'ABCDEF', | ||
# Number sequences | ||
'0123456789', | ||
'1234567890', | ||
), | ||
) | ||
def test_success(self, secret): | ||
assert filters.is_sequential_string(secret) | ||
|
||
@pytest.mark.parametrize( | ||
'secret', | ||
( | ||
'BEEF1234', | ||
), | ||
) | ||
def test_failure(self, secret): | ||
assert not filters.is_sequential_string(secret) |