Skip to content

Commit efb5bdc

Browse files
author
Yuval Michaeli
committed
fix(azure_storage_key): broaden account key pattern to catch flexible variable names
- Changed account_key context pattern from literal 'AccountKey' to regex 'account[_]?k(?:ey)?\b' (case-insensitive) to match variable names like STORAGE_ACCOUNT_K, STORAGE_ACCOUNT_KEY, account_key, AccountKey, etc. - Narrowed denylist base64 range from {86,1000} to {86,88} to match actual Azure Storage key length (64 bytes = 86 base64 chars + '==') - Updated early-exit optimization to use regex-based check instead of literal string match - Added unit test for STORAGE_ACCOUNT_K=<secret> pattern
1 parent 4443971 commit efb5bdc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

detect_secrets/plugins/azure_storage_key.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class AzureStorageKeyDetector(RegexBasedDetector):
1818
"""Scans for Azure Storage Account access keys."""
1919
secret_type = 'Azure Storage Account access key'
2020

21-
account_key = 'AccountKey'
21+
account_key = r'account[_]?k(?:ey)?\b'
22+
account_key_check = re.compile(r'account[_]?k(?:ey)?\b', re.IGNORECASE)
2223
azure = 'azure'
2324

2425
max_line_length = 4000
@@ -28,12 +29,12 @@ class AzureStorageKeyDetector(RegexBasedDetector):
2829
denylist = [
2930
# Account Key (AccountKey=xxxxxxxxx)
3031
re.compile(
31-
r'(?:["\']?[A-Za-z0-9+\/]{86,1000}==["\']?)',
32+
r'(?:["\']?[A-Za-z0-9+\/]{86,88}==["\']?)',
3233
),
3334
]
3435

3536
context_keys = [
36-
r'{account_key}=\s*{secret}',
37+
r'(?i){account_key}[\s=]+{secret}',
3738

3839
# maximum 2 lines secret distance under azure mention (case-insensitive)
3940
r'(?i)\b{azure}(.*\n){{0,2}}.*{secret}',
@@ -89,7 +90,7 @@ def context_keys_exists(self, result: PotentialSecret, string: str) -> bool:
8990
azure=self.azure,
9091
), re.MULTILINE,
9192
)
92-
if regex.pattern.startswith(self.account_key) and self.account_key not in string:
93+
if self.account_key in regex.pattern and not self.account_key_check.search(string):
9394
continue
9495
if self.azure in regex.pattern.lower() and self.azure not in string.lower():
9596
continue

tests/plugins/azure_storage_key_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ class TestAzureStorageKeyDetector:
215215
""",
216216
False,
217217
),
218+
# Flexible account key variable names
219+
(
220+
'STORAGE_ACCOUNT_K=X1y2Z3w4V5u6T7s8R9q0P1o2N3m4L5k6J7h8G9f0E1d2C3b4A5B6C7D8E9F0G1H2I3J4K5L6M7N8O9P0Q1R2S3==', # noqa: E501
221+
True,
222+
),
218223
(
219224
'CosmosKey=lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ==',
220225
False,

0 commit comments

Comments
 (0)