Skip to content

Commit 13d4a77

Browse files
authored
azure storage key optimize (#219)
1 parent f85144a commit 13d4a77

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

detect_secrets/plugins/azure_storage_key.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class AzureStorageKeyDetector(RegexBasedDetector):
2121
account_key = 'AccountKey'
2222
azure = 'azure'
2323

24+
max_line_length = 4000
25+
max_part_length = 2000
26+
integrity_regex = re.compile(r'integrity[:=]')
27+
2428
denylist = [
2529
# Account Key (AccountKey=xxxxxxxxx)
2630
re.compile(
@@ -66,6 +70,9 @@ def analyze_context_keys(
6670
return [result for result in results if self.context_keys_exists(result, context_text)]
6771

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

87-
@staticmethod
88-
def contains_integrity(secret_val: str, string: str) -> bool:
94+
def contains_integrity(self, secret_val: str, string: str) -> bool:
8995
# we want to ignore cases of lock files which contains hashes
90-
91-
regex = re.compile(r'integrity[:=]')
9296
context_parts = string.split('\n')
93-
return any(secret_val in part and regex.search(part) is not None for part in context_parts)
97+
return any(
98+
len(part) < self.max_part_length and
99+
secret_val in part and
100+
self.integrity_regex.search(part) is not None for part in context_parts
101+
)

0 commit comments

Comments
 (0)