Skip to content

fix(query): support for array's and some minor fixes #7844

Merged
cx-andre-pereira merged 4 commits into
masterfrom
AST-114868_QA_sns_topic_is_publicly_accessible-Terraform/aws
Nov 13, 2025
Merged

fix(query): support for array's and some minor fixes #7844
cx-andre-pereira merged 4 commits into
masterfrom
AST-114868_QA_sns_topic_is_publicly_accessible-Terraform/aws

Conversation

@cx-andre-pereira

@cx-andre-pereira cx-andre-pereira commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

Reason for Proposed Changes

  • The terraform query "SNS Topic Is Publicly Accessible" was recently changed to account for restrictive condition blocks to prevent False Positives. #7758

  • While analyzing the query i realized support for array's was lacking and samples like the 3 newly added ones would cause an error. I also noticed some other areas that could be improved.

Proposed Changes

  • I noticed some needless sprintf() statements. One was removed and the other 2 were adjusted to properly inform the index of the array entry being flagged, finally note that 'Statement.Policy.AWS' is supposed to be 'Statement.Principal.AWS' since "Policy" is not a valid field, the target here was "Principal".

  • The searchKey and serachLine values on the case of "topic_policy_statements" could also be improved. Ideally i would point to the specific "module[x1].topic_policy_statements[x2].principals[x3].identifiers[x4]" entry, but the KICS engine only allowed me to point as far as "principals" as seen in the implementation. This is still a big improvement over simply pointing to the "topic_policy_statements" block like before.

  • Finally some major adjustments were done to account for arrays with 2+ elements for the "aws_sns_topic" resource's policy, and the "terraform-aws-modules/sns/aws" module's "topic_policy" and "topic_policy_statements". All the fields were arrays but the query did not work for arrays with more than a single element. For the case of "topic_policy" and "policy", since they are represented as a single string, the index is specified through the key expected and actual values
    to properly flag and inform users for each invalid entry; while the search keys point to the "policy" field.

I submit this contribution under the Apache-2.0 license.

@github-actions github-actions Bot added the query New query feature label Nov 12, 2025
@github-actions

Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.13

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

@github-actions github-actions Bot added terraform Terraform query aws PR related with AWS Cloud labels Nov 12, 2025
@cx-andre-pereira cx-andre-pereira marked this pull request as ready for review November 12, 2025 15:23
@cx-andre-pereira cx-andre-pereira requested a review from a team as a code owner November 12, 2025 15:23

@cx-artur-ribeiro cx-artur-ribeiro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@cx-andre-pereira cx-andre-pereira merged commit d9a50fa into master Nov 13, 2025
28 checks passed
@cx-andre-pereira cx-andre-pereira deleted the AST-114868_QA_sns_topic_is_publicly_accessible-Terraform/aws branch November 13, 2025 16:16
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 query New query feature terraform Terraform query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants