feat(query): implements "iam policy allows for data exfiltration" - terraform/aws & cloudformation/aws#7631
Merged
cx-artur-ribeiro merged 12 commits intomasterfrom Aug 13, 2025
Conversation
Contributor
…xfiltration--terraform/aws--cloudformation/aws
…xfiltration--terraform/aws--cloudformation/aws
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 4266022 | Triggered | Generic Password | e0c6ec8 | assets/queries/cloudFormation/aws/amplify_branch_basic_auth_config_password_exposed/test/negative7.yaml | View secret |
| 9419039 | Triggered | Username Password | ef2901a | assets/queries/cloudFormation/aws/amplify_app_basic_auth_config_password_exposed/test/positive6.json | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
…0730--FN_IAM_Policy_Allows_For_Data_Exfiltration--terraform/aws--cloudformation/aws
…terraform/aws--cloudformation/aws' of https://github.com/Checkmarx/kics into AST-40730--FN_IAM_Policy_Allows_For_Data_Exfiltration--terraform/aws--cloudformation/aws
…xfiltration--terraform/aws--cloudformation/aws
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.
Reason for Proposed Changes
["s3:GetObject", "ssm:GetParameter", "ssm:GetParameters", "ssm:GetParametersByPath", "secretsmanager:GetSecretValue","*","s3:*"]) will be used to ensure if any given list of actions in an "Action" field is allowed. "Action " fields will be allowed in case they do not contain any action belonging to said list.Proposed Changes
For the Terraform query, resources of type "aws_iam_policy" are scanned for and if any in-line "policy" field contains an illegal action, it will be flagged x amount of times for x number of "illegal" actions found. Since it is impossible to point to a specific action this was the approach taken (pointing several times to the same line if warranted), and a "searchValue" was included which will state the specific action that trigger the flag to facilitate flag reasoning for users.
On the CloudFormation side many more resource types have to be accounted for, those being :
The list of illegal actions is the same. Here the process is similar to the terraform analog but more precise "searchKey" / "searchLine" values are possible.
Each of the relevant resources has a "PolicyDocument" with a list of "Statement", the specific statement is pointed to by the "searchKey".
Lastly, for this implementation, the "AWS::IAM::Policy" resource stands out for not having a "Policies" array since it represents a single Policy itself. Given this a second CxPolicy exists to handle that specific case scenario where the path is akin to:
Resources[x1].Properties.PolicyDocument.Statement[x2]Whereas the other resources follow this structure:
Resources[x1].Properties.Policies[x2].PolicyDocument.Statement[x3]I submit this contribution under the Apache-2.0 license.