@@ -21,6 +21,10 @@ class AzureStorageKeyDetector(RegexBasedDetector):
21
21
account_key = 'AccountKey'
22
22
azure = 'azure'
23
23
24
+ max_line_length = 4000
25
+ max_part_length = 2000
26
+ integrity_regex = re .compile (r'integrity[:=]' )
27
+
24
28
denylist = [
25
29
# Account Key (AccountKey=xxxxxxxxx)
26
30
re .compile (
@@ -66,6 +70,9 @@ def analyze_context_keys(
66
70
return [result for result in results if self .context_keys_exists (result , context_text )]
67
71
68
72
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
69
76
if result .secret_value :
70
77
for secret_regex in self .context_keys :
71
78
regex = re .compile (
@@ -84,10 +91,11 @@ def context_keys_exists(self, result: PotentialSecret, string: str) -> bool:
84
91
return True
85
92
return False
86
93
87
- @staticmethod
88
- def contains_integrity (secret_val : str , string : str ) -> bool :
94
+ def contains_integrity (self , secret_val : str , string : str ) -> bool :
89
95
# we want to ignore cases of lock files which contains hashes
90
-
91
- regex = re .compile (r'integrity[:=]' )
92
96
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