fix: project inline binary metadata and protect private markup attributes
This commit is contained in:
@@ -55,9 +55,17 @@ func redactMarkup(body string) string {
|
||||
}
|
||||
}
|
||||
for _, a := range token.Attr {
|
||||
safe := redactInlineBinary(a.Val)
|
||||
if sensitive(a.Key) || (hideValue && a.Key == "value") {
|
||||
safe = redacted
|
||||
} else if safe == a.Val && a.Val != "" && (sensitive(token.Data) || hideValue) && !diagnosticTextLine(a.Key+"="+a.Val, 0) && !isInlineBinarySummary(a.Val) {
|
||||
// Private elements own their attribute payloads too, not only inner
|
||||
// text. Preserve only typed diagnostic scalars or binary metadata.
|
||||
safe = redacted
|
||||
}
|
||||
if safe != a.Val {
|
||||
pattern := regexp.MustCompile(`(?i)(\b` + regexp.QuoteMeta(a.Key) + `\s*=\s*)(?:"[^"]*"|'[^']*'|[^\s>]+)`)
|
||||
tag = pattern.ReplaceAllString(tag, `${1}"[REDACTED]"`)
|
||||
tag = pattern.ReplaceAllStringFunc(tag, func(match string) string { return pattern.FindStringSubmatch(match)[1] + strconv.Quote(safe) })
|
||||
}
|
||||
}
|
||||
out.WriteString(tag)
|
||||
|
||||
Reference in New Issue
Block a user