fix(terraform): fix false positive for Kubernetes labels with prefixed keys (slash)#7973
Open
cx-ori-bendet wants to merge 1 commit intomasterfrom
Open
fix(terraform): fix false positive for Kubernetes labels with prefixed keys (slash)#7973cx-ori-bendet wants to merge 1 commit intomasterfrom
cx-ori-bendet wants to merge 1 commit intomasterfrom
Conversation
Labels with a DNS-subdomain-prefixed key (e.g. "gateway.istio.io/defaults-for-class")
were incorrectly flagged as invalid. The slash in the key causes KICS's HCL parser to
produce a nested object instead of a string value; calling regex.match on a non-string
returns false, triggering the false positive.
Add is_string() guard before the regex check so non-string values are skipped.
Also fix a typo in the result messages ("metada" -> "metadata") and add a negative
test case covering prefixed label keys.
Fixes #7938
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
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.








Summary
gateway.istio.io/defaults-for-class) were incorrectly flagged as Metadata Label Is Invalid/in the label key causes the KICS HCL parser to produce a nested object instead of a flat string value; callingregex.matchon a non-string returnsfalse, triggering the== falsecondition as a false positiveis_string(labels[key])guard before the regex so non-string values (parser artefacts) are silently skipped"metada"→"metadata""gateway.istio.io/defaults-for-class" = "something"to the negative test fixture to cover this case going forwardFixes #7938
Test plan
"gateway.istio.io/defaults-for-class" = "something"— should produce no findingapp = "g**dy.l+bel") — should still produce a findinggo test ./test/... -run TestQueriesto verify all query tests passI submit this contribution under the Apache-2.0 license.
🤖 Generated with Claude Code