Files
Reims-Go/internal/driver/reims/redact.go
T
Nwflower ceeb483cfb fix(i18n,plugin,ui): harden PR #10 redaction, trust boundaries, ICU limits, and UI contrast
Follow-up hardening from PR #10 review:
- Redact quoted/space-containing SMC OSKs, hyphenated MACs, and extended token keys without corrupting benign 'serial ...' messages; make RawDetail truncation UTF-8-safe and register reims.RedactText in CLI
- Enforce trust boundaries so unprivileged community language packs cannot hijack built-in zh-CN/en-US catalogs or overwrite target-owned plugin metadata/messages
- Avoid triggering inUseChecker/Sidecar wake-ups inside Registry.OnChange (ResolvedLocalePacks) and Broker.AllowRate; bound Sidecar NotifyIfRunning with a 500ms timeout; add l10nCache generation counter and syncLocales broadcast
- Cap ICU nesting depth (16) and template size (16 KiB) in Go & TS; reserve built-in anchors in 8-hop FallbackChain; fix C.UTF-8 detection, zero-var fault isolation, and PseudoLocalize brace escaping
- Fix pluginsdk Server.T apostrophe/contraction handling, defensive cloning, and sequential plugin/localeChanged dispatch
- Fix WCAG 2.1 AA contrast for --accent-soft-text, prevent PluginPanelFrame RPC hang on locale switch, guard setPluginLocales re-renders, and fix <=768px drawer & RTL toast swipe-out CSS
2026-11-30 00:26:14 -07:00

37 lines
1.5 KiB
Go

package reims
import (
"regexp"
"strings"
)
var (
reLogMac = regexp.MustCompile(`(?i)\b(mac(?:_?address)?[\s:=]+)["']?[0-9a-f]{2}(?:[:-][0-9a-f]{2}){5}["']?`)
reLogSerialKV = regexp.MustCompile(`(?i)\b((?:system)?serial(?:_?number)?\s*[:=]\s*|mlb\s*[:=]\s*|smuuid\s*[:=]\s*)["']?[A-Za-z0-9-]{8,}["']?`)
reLogSerialSp = regexp.MustCompile(`(?i)\b(serial\s+)["']?(?-i:[A-Z0-9]{8,})["']?`)
reLogOSK = regexp.MustCompile(`(?i)\b(osk\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,"']+)`)
reLogBearer = regexp.MustCompile(`(?i)((?:Bearer|Basic|Authorization:\s*token)\s+)[A-Za-z0-9._~+/=-]{16,}`)
reLogTokenKV = regexp.MustCompile(`(?i)((?:REIMS_TOKEN|GITHUB_TOKEN|access_token|auth_token|token|"token")\s*[:=]\s*["']?)[A-Za-z0-9._~+/-]{16,}(["']?)`)
)
// RedactLogLine removes MAC addresses, SMBIOS serial numbers, SMC OSK keys, and
// Guest Tools Bearer tokens before lines are emitted or exported.
func RedactLogLine(line string) string {
line = reLogMac.ReplaceAllString(line, "${1}[redacted]")
line = reLogSerialKV.ReplaceAllString(line, "${1}[redacted]")
line = reLogSerialSp.ReplaceAllString(line, "${1}[redacted]")
line = reLogOSK.ReplaceAllString(line, "${1}[redacted]")
line = reLogBearer.ReplaceAllString(line, "${1}[redacted]")
line = reLogTokenKV.ReplaceAllString(line, "${1}[redacted]${2}")
return line
}
// RedactText applies RedactLogLine across a multi-line log or JSON text block.
func RedactText(s string) string {
lines := strings.Split(s, "\n")
for i, l := range lines {
lines[i] = RedactLogLine(l)
}
return strings.Join(lines, "\n")
}