Skip to content
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

Improve sequential string detection #207

Merged
merged 1 commit into from
Jul 9, 2019
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
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