Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

feat(query): implements "iam policy allows for data exfiltration" - terraform/aws & cloudformation/aws#7631

Merged
cx-artur-ribeiro merged 12 commits intomasterfrom
AST-40730--FN_IAM_Policy_Allows_For_Data_Exfiltration--terraform/aws--cloudformation/aws
Aug 13, 2025
Merged

feat(query): implements "iam policy allows for data exfiltration" - terraform/aws & cloudformation/aws#7631
cx-artur-ribeiro merged 12 commits intomasterfrom
AST-40730--FN_IAM_Policy_Allows_For_Data_Exfiltration--terraform/aws--cloudformation/aws

Conversation

@cx-andre-pereira
Copy link
Contributor

@cx-andre-pereira cx-andre-pereira commented Aug 5, 2025

Reason for Proposed Changes

  • Currently , we don’t have support for the verification of policy actions that allow for data exfiltration.
  • This new query for Terraform and CloudFormation, "IAM Policy Allows For Data Exfiltration" will implement the missing verification.
  • To ensure data exfiltration is not possible, a given list of illegal actions (["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:

  • Whereas the other resources follow this structure:

I submit this contribution under the Apache-2.0 license.

@github-actions github-actions bot added feature New feature query New query feature cloudformation CloudFormation query terraform Terraform query aws PR related with AWS Cloud labels Aug 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2025

kics-logo

KICS version: v2.1.11

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 1
Files parsed placeholder 1
Files failed to scan placeholder 0
Total executed queries placeholder 47
Queries failed to execute placeholder 0
Execution time placeholder 0

@gitguardian
Copy link

gitguardian bot commented Aug 6, 2025

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
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
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. 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


🦉 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.

@cx-andre-pereira cx-andre-pereira marked this pull request as ready for review August 6, 2025 13:54
@cx-andre-pereira cx-andre-pereira requested a review from a team as a code owner August 6, 2025 13:54
…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
Copy link
Contributor

@cx-eduardo-semanas cx-eduardo-semanas left a comment

Choose a reason for hiding this comment

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

LGTM

…xfiltration--terraform/aws--cloudformation/aws
@cx-artur-ribeiro cx-artur-ribeiro merged commit aae5aa2 into master Aug 13, 2025
34 of 35 checks passed
@cx-artur-ribeiro cx-artur-ribeiro deleted the AST-40730--FN_IAM_Policy_Allows_For_Data_Exfiltration--terraform/aws--cloudformation/aws branch August 13, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws PR related with AWS Cloud cloudformation CloudFormation query feature New feature query New query feature terraform Terraform query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants