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

azure storage key optimize #219

Merged
merged 3 commits into from
Jul 10, 2024
Merged
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
18 changes: 13 additions & 5 deletions detect_secrets/plugins/azure_storage_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class AzureStorageKeyDetector(RegexBasedDetector):
account_key = 'AccountKey'
azure = 'azure'

max_line_length = 4000
max_part_length = 2000
integrity_regex = re.compile(r'integrity[:=]')

denylist = [
# Account Key (AccountKey=xxxxxxxxx)
re.compile(
Expand Down Expand Up @@ -66,6 +70,9 @@ def analyze_context_keys(
return [result for result in results if self.context_keys_exists(result, context_text)]

def context_keys_exists(self, result: PotentialSecret, string: str) -> bool:
if len(string) > self.max_line_length:
# for very long lines, we don't run the regex to avoid performance issues
return False
if result.secret_value:
for secret_regex in self.context_keys:
regex = re.compile(
Expand All @@ -84,10 +91,11 @@ def context_keys_exists(self, result: PotentialSecret, string: str) -> bool:
return True
return False

@staticmethod
def contains_integrity(secret_val: str, string: str) -> bool:
def contains_integrity(self, secret_val: str, string: str) -> bool:
# we want to ignore cases of lock files which contains hashes

regex = re.compile(r'integrity[:=]')
context_parts = string.split('\n')
return any(secret_val in part and regex.search(part) is not None for part in context_parts)
return any(
len(part) < self.max_part_length and
secret_val in part and
self.integrity_regex.search(part) is not None for part in context_parts
)
Loading