Skip to content

Commit

Permalink
use unicode to restrict label value space
Browse files Browse the repository at this point in the history
  • Loading branch information
maddsua committed Feb 21, 2025
1 parent c00b90b commit 44101a1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions service/forwarder/loki/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package loki

import (
"log/slog"
"unicode"
)

func filterLabelFormat(labels map[string]string) {
Expand Down Expand Up @@ -76,18 +77,16 @@ func stripLabelValue(key string) string {

for _, next := range key {

switch next {
case '\\':
switch {
case next == '\\':
stripped += "/"
continue
}

if next >= 0x20 && next <= 0x7E {
stripped += string(next)
case !unicode.IsPrint(next):
stripped += "?"
continue
}

stripped += "?"
stripped += string(next)
}

return stripped
Expand Down

0 comments on commit 44101a1

Please sign in to comment.