Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New AWS regex #397

Merged
merged 3 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions detect_secrets/plugins/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ class AWSKeyDetector(RegexBasedDetector):

denylist = (
re.compile(r'AKIA[0-9A-Z]{16}'),
re.compile(r'aws.{0,20}?[\'\"]([0-9a-zA-Z/+]{40})[\'\"]'),
pablosnt marked this conversation as resolved.
Show resolved Hide resolved
pablosnt marked this conversation as resolved.
Show resolved Hide resolved
)

def verify( # type: ignore[override] # noqa: F821
self,
secret: str,
context: CodeSnippet,
) -> VerifiedResult:
if not self.denylist[0].match(secret):
pablosnt marked this conversation as resolved.
Show resolved Hide resolved
pablosnt marked this conversation as resolved.
Show resolved Hide resolved
return VerifiedResult.UNVERIFIED
secret_access_key_candidates = get_secret_access_keys(context)
if not secret_access_key_candidates:
return VerifiedResult.UNVERIFIED
Expand Down
17 changes: 17 additions & 0 deletions tests/plugins/aws_key_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ def setup(self):
'AKIAZZZ',
False,
),
(
'aws_access_key = "{}"'.format(EXAMPLE_SECRET),
True,
),
(
'aws_access_key = "{}"'.format(EXAMPLE_SECRET + 'a'),
False,
),
(
'aws_access_key = "{}"'.format(EXAMPLE_SECRET[0:39]),
False,
),
],
)
def test_analyze(self, line, should_flag):
Expand All @@ -48,6 +60,11 @@ def test_verify_no_secret(self):
get_code_snippet([], 1),
) == VerifiedResult.UNVERIFIED

assert logic.verify(
EXAMPLE_SECRET,
get_code_snippet([], 1),
) == VerifiedResult.UNVERIFIED

def test_verify_valid_secret(self):
with mock.patch(
'detect_secrets.plugins.aws.verify_aws_secret_access_key',
Expand Down