Skip to content

Commit

Permalink
check Azure Storage Key for surrounding quotes (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruebel authored Nov 26, 2023
1 parent 3a502a2 commit d58c355
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions detect_secrets/core/plugins/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
from abc import abstractproperty
from functools import lru_cache
from types import ModuleType
from typing import Any
Expand Down Expand Up @@ -62,5 +61,5 @@ def _is_valid_plugin(attribute: Any) -> bool:
inspect.isclass(attribute)
and issubclass(attribute, BasePlugin)
# Heuristic to determine abstract classes
and not isinstance(attribute.secret_type, abstractproperty)
and 'secret_type' not in attribute.__abstractmethods__
)
2 changes: 1 addition & 1 deletion detect_secrets/plugins/azure_storage_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ class AzureStorageKeyDetector(RegexBasedDetector):
denylist = [
# Account Key (AccountKey=xxxxxxxxx)
re.compile(
r'(?:[A-Za-z0-9+\/]{86,1000}==)$',
r'(?:["\']?[A-Za-z0-9+\/]{86,1000}==["\']?)$',
),
]
13 changes: 7 additions & 6 deletions detect_secrets/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from __future__ import annotations

import re
from abc import ABCMeta
from abc import ABC
from abc import abstractmethod
from abc import abstractproperty
from typing import Any
from typing import Dict
from typing import Generator
Expand All @@ -27,8 +26,9 @@
from detect_secrets.util.inject import call_function_with_arguments


class BasePlugin(metaclass=ABCMeta):
@abstractproperty
class BasePlugin(ABC):
@property
@abstractmethod
def secret_type(self) -> str:
"""
Unique, user-facing description to identify this type of secret. This should be overloaded
Expand Down Expand Up @@ -149,7 +149,7 @@ def __eq__(self, other: Any) -> bool:
return self.json() == other.json()


class RegexBasedDetector(BasePlugin, metaclass=ABCMeta):
class RegexBasedDetector(BasePlugin):
"""Parent class for regular-expression based detectors.
To create a new regex-based detector, subclass this and set `secret_type` with a
Expand All @@ -164,7 +164,8 @@ class FooDetector(RegexBasedDetector):
)
"""

@abstractproperty
@property
@abstractmethod
def denylist(self) -> Iterable[Pattern]:
raise NotImplementedError

Expand Down
8 changes: 8 additions & 0 deletions tests/plugins/azure_storage_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class TestAzureStorageKeyDetector:
'AccountKey=lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ==', # noqa: E501
True,
),
(
'AccountKey="lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ=="', # noqa: E501
True,
),
(
"AccountKey='lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ=='", # noqa: E501
True,
),
(
'lJzRc1YdHaAA2KCNJJ1tkYwF/+mKK6Ygw0NGe170Xu592euJv2wYUtBlV8z+qnlcNQSnIYVTkLWntUO1F8j8rQ==', # noqa: E501
True,
Expand Down

0 comments on commit d58c355

Please sign in to comment.