fix: prevent obfuscation false positives on common words and substrings - #114
fix: prevent obfuscation false positives on common words and substrings#114trevorwilliams2025 wants to merge 2 commits into
Conversation
|
Skipping CI for Draft Pull Request. |
|
@trevorwilliams2025: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
| ) | ||
|
|
||
| func isLetter(b byte) bool { | ||
| return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') |
There was a problem hiding this comment.
what about cases like service-foo, that would be replaced to obfuscated-foo?
There was a problem hiding this comment.
Replying to @janboll's comment on isLetter (line 23):
what about cases like
service-foo, that would be replaced toobfuscated-foo?
This is handled by two layers of protection:
-
genericSkipWords—serviceis in the skip list (protected.go:38), so it's never replaced in free text even if discovered as an ARM resource name. -
End-to-end test —
TestAzureResourceObfuscatorContentshas a case called "common word resource name does not corrupt hyphenated compounds" (azure_resources_test.go:733-741) that proves exactly this:- Input: ARM path discovers
serviceas a resource name, then free text containsservice-foo is ready - Output:
service-foo is ready— unchanged
- Input: ARM path discovers
Replying to @janboll's comment on replaceNotInsideWord (line 28):
this needs more documentation or individual unit test to better understand how it's functioning
The function has been renamed to replaceStandalone and now has:
- Detailed doc comment explaining boundary rules with examples (azure_resources.go:27-35)
- Dedicated
TestReplaceStandalonewith 12 cases covering spaces, equals signs, string boundaries, letter neighbors, hyphens, digits, and edge cases (azure_resources_test.go:271-399)
|
|
||
| // replaceNotInsideWord is like strings.ReplaceAll but skips matches embedded | ||
| // inside a larger alphabetic token (e.g. "Proxy1" inside "MyProxy1Handler"). | ||
| func replaceNotInsideWord(s, old, repl string) (uint, string) { |
There was a problem hiding this comment.
this needs more documentation or individual unit test to better understand how it's functioning
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: trevorwilliams2025 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary
paths were being blindly replaced in all free text via strings.ReplaceAll, corrupting
unrelated strings (e.g. "containerd.service" → "containerd.obfuscated-resource-name")
inside "coredns"
Fix
so replacements respect word boundaries (underscores and digits are word characters;
dots and hyphens are boundaries)
replaceNotInsideWord— skips matches embedded inside larger alphabetic tokens(e.g. "Proxy1" inside "MyProxy1Handler")
isGenericWord— skips single-case alphabetic strings ("service", "GPU") that aretoo common to safely replace in free text
Test plan
hyphenated names, multiple occurrences, embedded-in-token protection
go build ./...andgo test ./pkg/obfuscator/...pass