Skip to content

Commit b2cf4e7

Browse files
yuvalmichYuval Michaeli
andauthored
fix(azure_storage_key): broaden azure storage account key pattern (#292)
Co-authored-by: Yuval Michaeli <ymichaeli@paloaltonetworks.com>
1 parent 4443971 commit b2cf4e7

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=]{{1,20}}{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)