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

Update high_entropy_strings.py #200

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, charset: str, limit: float) -> None:

# We require quoted strings to reduce noise.
# NOTE: We need this to be a capturing group, so back-reference can work.
self.regex = re.compile(r'([\'"])([{}]+)(\1)'.format(re.escape(charset)))
self.regex = re.compile(r'([\'"]?)([{}]+)(\1)'.format(re.escape(charset)))

def analyze_string(self, string: str) -> Generator[str, None, None]:
for result in self.regex.findall(string):
Expand Down
4 changes: 4 additions & 0 deletions tests/core/secrets_collection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ 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:10',
'Location: test_data/config.ini:10',
'Location: test_data/config.ini:21',
'Location: test_data/config.ini:22',
'Location: test_data/config.ini:32',
'Location: test_data/config.ini:32',
'Location: test_data/config.ini:33',
]

@staticmethod
Expand All @@ -102,6 +105,7 @@ def test_file_based_success_yaml():
'Location: test_data/config.yaml:3',
'Location: test_data/config.yaml:5',
'Location: test_data/config.yaml:13',
'Location: test_data/config.yaml:18',
]

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/core/usage/filters_usage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_local_file_success(scheme, parser):
])
secrets.scan_file('test_data/config.env')

assert not secrets
assert secrets

@staticmethod
def test_module_success(parser):
Expand Down
2 changes: 1 addition & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_failed_high_entropy_string():
],
}):
assert scan_adhoc_string('bangbangintotheroom').splitlines() == [
'Base64HighEntropyString: False (3.326)',
'Base64HighEntropyString: False',
]

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/high_entropy_strings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TestHighEntropyString:
("'{secret}'", True),

# Non-quoted string
('{secret}', False),
('{secret}', True),
),
)
def test_basic(plugin, non_secret, secret, format, should_be_caught):
Expand Down
Loading