Skip to content

fix(query): exclude private CIDRs from AWS small-public-network query#8065

Open
arpitjain099 wants to merge 1 commit into
Checkmarx:masterfrom
arpitjain099:fix/small-public-network-private-cidr-fp
Open

fix(query): exclude private CIDRs from AWS small-public-network query#8065
arpitjain099 wants to merge 1 commit into
Checkmarx:masterfrom
arpitjain099:fix/small-public-network-private-cidr-fp

Conversation

@arpitjain099

Copy link
Copy Markdown

Closes #8032

Reason for Proposed Changes

  • The Terraform query aws/sensitive_port_is_exposed_to_small_public_network only looked at the CIDR suffix (/25-/29 for IPv4, /121-/125 for IPv6) to decide a range was a "small public network". It never checked whether the range was actually public.
  • Because of that, private RFC1918 ranges such as 10.0.0.0/25, 192.168.0.0/26 and 172.16.0.0/27, as well as IPv6 ULA ranges like fd00::/121, were reported as small public networks. That is a false positive: exposing a sensitive port to a small private subnet is not the risk this query is meant to catch, and bug(terraform): sensitive port Is exposed to small public network is too broad #8032 reports the rule as too broad for exactly this reason.

Proposed Changes

  • isSmallPublicNetwork now requires the CIDR to be small AND not private. The private check reuses the existing common_lib.isPrivateIP helper (RFC1918 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and IPv6 ULA fc00::/8, fd00::/8), which is the same helper the sibling sensitive_port_is_exposed_to_wide_private_network query already uses, so the public/private boundary stays consistent across the two queries.
  • Genuinely public small ranges still flag. The positive fixtures were updated to use public small CIDRs (203.0.113.0/25, 198.51.100.0/26, 8.8.8.0/27, public IPv6 GUA, etc.); they previously used private RFC1918/ULA ranges, which is the false positive itself, so they no longer belong in the positive set.
  • Added negative fixtures with private /25-/27 and ULA /121 ranges on a sensitive port and TCP, across all four resource shapes (aws_security_group, aws_vpc_security_group_ingress_rule, aws_security_group_rule, and the terraform-aws-modules/security-group/aws module), so the false positive is locked in.

Tests run locally with go test ./test/ -run 'TestQueries/terraform/aws/sensitive_port_is_exposed_to_small_public_network', plus TestQueriesContent and TestQueriesMetadata, all green. I also confirmed the new negative cases fail against the pre-fix query, so they are a real regression guard rather than vacuous.

Note: #8032 mentions the Azure twin azure/sensitive_port_is_exposed_to_small_public_network has the same issue. I scoped this PR to AWS only to keep the review focused; I am happy to follow up with the matching Azure fix in a separate PR.

I submit this contribution under the Apache-2.0 license.

The Terraform query aws/sensitive_port_is_exposed_to_small_public_network
flagged any ingress CIDR whose suffix was /25-/29 (or /121-/125 for IPv6)
without checking whether the range is actually public. As a result private
RFC1918 ranges such as 10.0.0.0/25, 192.168.0.0/26 and 172.16.0.0/27 (and
IPv6 ULA fd00::/121) were reported as small public networks, a false positive.

isSmallPublicNetwork now also requires the CIDR not to be private, reusing the
existing common_lib.isPrivateIP helper (the same helper the wide_private_network
twin query relies on). Genuinely public small ranges still flag.

The positive fixtures were updated to use public small CIDRs (they previously
used private ranges, which is exactly the false positive) and negative cases
were added with private /25-/27 and ULA /121 ranges on a sensitive port to lock
in the fix.

Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
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.

bug(terraform): sensitive port Is exposed to small public network is too broad

1 participant