Skip to content

Commit 455fe92

Browse files
committed
[processor/redactionprocessor] fix mask when multiple patterns exist
1 parent 220b111 commit 455fe92

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

.chloggen/redact-multi.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: redactionprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Fix mask when multiple patterns exist"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [27646]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

processor/redactionprocessor/processor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,18 @@ func (s *redaction) processAttrs(_ context.Context, attributes pcommon.Map) {
113113

114114
// Mask any blocked values for the other attributes
115115
strVal := value.Str()
116+
var matched bool
116117
for _, compiledRE := range s.blockRegexList {
117118
match := compiledRE.MatchString(strVal)
118119
if match {
119-
toBlock = append(toBlock, k)
120+
if !matched {
121+
matched = true
122+
toBlock = append(toBlock, k)
123+
}
120124

121125
maskedValue := compiledRE.ReplaceAllString(strVal, "****")
122126
value.SetStr(maskedValue)
127+
strVal = maskedValue
123128
}
124129
}
125130
return true

processor/redactionprocessor/processor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func TestMultipleBlockValues(t *testing.T) {
290290
"mystery": pcommon.NewValueStr("mystery 52000"),
291291
}
292292
masked := map[string]pcommon.Value{
293-
"name": pcommon.NewValueStr("placeholder 4111111111111111"),
293+
"name": pcommon.NewValueStr("placeholder 4111111111111111 52000"),
294294
}
295295
redacted := map[string]pcommon.Value{
296296
"credit_card": pcommon.NewValueStr("4111111111111111"),
@@ -324,7 +324,7 @@ func TestMultipleBlockValues(t *testing.T) {
324324
assert.Equal(t, int64(len(blockedKeys)), maskedValueCount.Int())
325325
nameValue, _ := attr.Get("name")
326326
mysteryValue, _ := attr.Get("mystery")
327-
assert.Equal(t, "placeholder ****", nameValue.Str())
327+
assert.Equal(t, "placeholder **** ****", nameValue.Str())
328328
assert.Equal(t, "mystery ****", mysteryValue.Str())
329329
}
330330

0 commit comments

Comments
 (0)