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

#559: Refactor AWS Access Key Regex To Minimize False Positives #571

Merged
merged 1 commit into from
Jun 27, 2022

Conversation

jpdakran
Copy link
Member

Problem:

  • The AWS plugin is producing false positives for example:
    "aws:cdk:path": "VaDataVaultCdkPoc/rBucketKeyCdk/Resource"
  • The regex for the real secret is correct since all aws secret access keys follow the format wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
  • However, there is no restriction on the variable name other than that it must prefix with aws followed by any characters

Solution:

  • The solution here is to add another restriction in addition to the aws prefix which is adding that there must be some form of secret keyword like key|pwd|pw|password|pass|token in the variable name
  • This will allow us to constrain the subset of results filtering out some false postiives ensuring the variable name is prefixed with aws, must contain a secret keyword, and the secret regex must match the standard aws format.
  • Please Note: I also increased the allowed variable name length. The reasoning behind this is a user can potentially set this to something longer than the original 20 characters. Also multiple other aws resource identifier names are longer than 20 characters.
  • Some tests needed to be updated since one test case aws_secret_access_key = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' was not picked up by the AWS detector since the variable name was too long. This in my opinion should be detected. It is detected as an AWS Access Key and detected as a Base64 High Entropy String

@jpdakran jpdakran linked an issue Jun 23, 2022 that may be closed by this pull request
@jpdakran
Copy link
Member Author

@AjkayAlan Looking for your feedback here.

Copy link

@AjkayAlan AjkayAlan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, and thanks for doing this!

I tested the two "aws:cdk:path" examples I called out in #559 which appear to be good with this regex. I also manually tested a few more examples which I would expect to be captured, which worked as expected, including "aws_secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"

detect_secrets/plugins/aws.py Show resolved Hide resolved
detect_secrets/plugins/aws.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False Positive: AWS Access Key for aws:cdk:path
3 participants