fix: project inline binary metadata and protect private markup attributes

This commit is contained in:
2026-10-10 06:24:15 +08:00
parent 113eaec32f
commit 64bd48bf70
5 changed files with 196 additions and 2 deletions
+9 -1
View File
@@ -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)