fix(query): resolve false positive on Hardcoded AWS Access Key In Lambda#8005
Open
cx-prathmesh-borle wants to merge 1 commit intoCheckmarx:masterfrom
Open
Conversation
6b96dbc to
df64232
Compare
df64232 to
e5e19cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7074
Reason for Proposed Changes
2564172f-c92b-4261-9acd-464aed511696(Hardcoded AWS Access Key In Lambda) produces false positives on CloudFormation templates because the Rego logic uses overly broad regex patterns that match ANY 20-character uppercase alphanumeric string ([A-Z0-9]{20}) or ANY 40-character base64-like string ([A-Za-z0-9/+=]{40}), regardless of the variable name;foo: "12345678901234567890"orDATA_HASH: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"to be flagged as HIGH severity findings even though the variable names are not sensitive;(A3T[A-Z0-9]|AKIA|ASIA)[A-Z0-9]{16}which reliably detects AWS access key IDs by their distinctive prefixes (AKIAfor permanent keys,ASIAfor temporary STS keys);Proposed Changes
query.rego:(A3T[A-Z0-9]|AKIA|ASIA)[A-Z0-9]{16}to detect AWS access key IDs by their distinctive prefix (no variable name check needed);^[A-Za-z0-9/+=]{40}$(anchored to match exactly 40 characters) gated behind a case-insensitive variable name pattern(?i)(access.?key|secret.?key|aws.?(key|secret|token|credential)|credential|secret.?access)to only flag 40-character values when the variable name suggests it contains credentials;searchKeyin the original formatResources.<name>.Properties.Environment.Variables(without specific variable names) to maintain backward compatibility with existing scan results and suppression rules;searchLinefor accurate line number resolution showing the exact variable that triggered the finding;common_libimport to support thebuild_search_linefunction;negative3.yaml- YAML format with non-sensitive variable names (foo,DATA_HASH) that should NOT be flagged;negative4.json- JSON format with the same non-sensitive patterns;positive1-4) to use realistic AWS credential variable names and values;positive_expected_result.jsonwith correct line numbers for each test case;Note
searchKeyformat is preserved unchanged to ensure existing scan results remain valid and users do not need to update suppression lists;aws_access_keyfield (lower FP risk, no change needed);I submit this contribution under the Apache-2.0 license.