feat(privacy): detect an already-sanitized source

Scan now reports PrivacyScan.Sanitized {detected, markers, strong, files,
evidence}. SanitizationMarkers recognises a value slot filled with one
repeated placeholder + separators (xxxxx.xxxx.xx, x@xxxx.xxxx.xx,
000.00.00.0, a decoy timezone) - it matches the shape, not the literal "x",
so evolving the redaction mechanism still trips it.

detected requires corroboration: strong>=2, or strong>=1 && markers>=3, or
markers>=4. A single filler-looking token is reported (markers:1) but never
asserted as sanitized, so a partial future pass or a coincidence does not
read as "done". 0.0.0.0 / 000 / UTC / Etc/UTC are too plausibly intentional
and do not count.

UI: the Customer-data panel shows "файл уже обезличен" and hides the
sanitize button when detected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014jDYM1nnoZZ3vFz23DDaV1
This commit is contained in:
Mikhail Chusavitin
2026-09-03 10:02:02 +03:00
co-authored by Claude Sonnet 5
parent a63bb17438
commit f38fb2de69
10 changed files with 334 additions and 10 deletions
+7 -2
View File
@@ -48,6 +48,7 @@ func Scan(files []File) *models.PrivacyScan {
findings = append(findings, f)
}
san := newSanTally()
for _, file := range files {
if isAllowlistedFilename(file.Path) {
continue
@@ -56,7 +57,7 @@ func Scan(files []File) *models.PrivacyScan {
continue
}
scanned++
scanFileLines(file, emit)
scanFileLines(file, emit, san)
}
if scanned == 0 {
@@ -70,11 +71,12 @@ func Scan(files []File) *models.PrivacyScan {
Findings: findings,
Customers: guessCustomers(findings),
Summary: summarize(findings),
Sanitized: san.report(),
}
return report
}
func scanFileLines(file File, emit func(models.PrivacyFinding)) {
func scanFileLines(file File, emit func(models.PrivacyFinding), san *sanTally) {
certFile := isCertFilename(file.Path)
sc := bufio.NewScanner(bytes.NewReader(file.Content))
sc.Buffer(make([]byte, 0, 64*1024), 1024*1024)
@@ -86,6 +88,9 @@ func scanFileLines(file File, emit func(models.PrivacyFinding)) {
line = line[:maxScanLineBytes]
}
scanLine(file.Path, line, ln, certFile, emit)
for _, m := range SanitizationMarkers(line) {
san.add(file.Path, ln, line, m)
}
}
}