Skip to content

Commit

Permalink
Improve sequential string detection
Browse files Browse the repository at this point in the history
* Ensure that we catch all base64 strings correctly
* Add an explicit check for alphanumeric sequences
* Add some more tests for sequential string detection
  • Loading branch information
Victor Zhou committed Jul 8, 2019
1 parent 13575ed commit 4310fa9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
16 changes: 15 additions & 1 deletion detect_secrets/plugins/common/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,31 @@ def is_sequential_string(secret):
Returns true if string is sequential.
"""
sequences = (
# base64 letters first
(
string.ascii_uppercase +
string.ascii_uppercase +
string.digits +
'+/'
),

# base64 numbers first
(
string.digits +
string.ascii_uppercase +
string.ascii_uppercase +
'+/'
),

# We don't have a specific sequence for alphabetical
# sequences, since those will happen to be caught by the
# base64 checks.

# alphanumeric sequences
(string.digits + string.ascii_uppercase) * 2,

# Capturing any number sequences
'0123456789' * 2,
string.digits * 2,

string.hexdigits.upper() + string.hexdigits.upper(),
string.ascii_uppercase + '=/',
Expand Down
14 changes: 14 additions & 0 deletions tests/plugins/common/filters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@ class TestIsSequentialString:
@pytest.mark.parametrize(
'secret',
(
# ascii sequence
'ABCDEF',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
# Number sequences
'0123456789',
'1234567890',
# alphanumeric sequences
'abcdefghijklmnopqrstuvwxyz0123456789',
'0123456789abcdefghijklmnopqrstuvwxyz',
# Hex sequences
'0123456789abcdef',
'abcdef0123456789',
# base64 sequences
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/',
),
)
def test_success(self, secret):
Expand Down

0 comments on commit 4310fa9

Please sign in to comment.