fix(core): exempter les hits forcés (overrides) du filtre catégorie — anti-fuite PDF (P1-2/T1)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-27 11:38:19 +02:00
parent 5663966938
commit 4357a58d7d
2 changed files with 88 additions and 4 deletions

View File

@@ -685,7 +685,11 @@ def _filter_audit_by_disabled(audit, disabled_kinds):
"""
if not disabled_kinds:
return audit
return [h for h in audit if _category_of(h.kind) not in disabled_kinds]
# P1-2/T1 (anti-fuite PDF) : un hit FORCÉ (override utilisateur / blacklist
# force-mask) est TOUJOURS conservé → toujours gravé, quel que soit le toggle
# de catégorie. getattr défensif au cas où un PiiHit serait construit ailleurs
# sans le champ (le default du dataclass couvre déjà ce cas).
return [h for h in audit if getattr(h, "forced", False) or _category_of(h.kind) not in disabled_kinds]
# Baseline regex
@@ -1331,6 +1335,10 @@ class PiiHit:
original: str
placeholder: str
bbox_hint: Optional[Tuple[float, float, float, float]] = None
# P1-2/T1 (anti-fuite PDF) : un hit FORCÉ (override utilisateur / blacklist
# force-mask) est TOUJOURS gravé, jamais retiré par un toggle de catégorie.
# Default False ⇒ no-op strict pour tous les call sites existants.
forced: bool = False
@dataclass
class AnonResult:
@@ -1769,7 +1777,7 @@ def _apply_overrides(line: str, audit: List[PiiHit], page_idx: int, cfg: Dict[st
except Exception:
continue
def _rep(m: re.Match):
audit.append(PiiHit(page_idx, name, m.group(0), placeholder))
audit.append(PiiHit(page_idx, name, m.group(0), placeholder, forced=True))
return placeholder
line = rx.sub(_rep, line)
# force-mask literals
@@ -1777,7 +1785,7 @@ def _apply_overrides(line: str, audit: List[PiiHit], page_idx: int, cfg: Dict[st
if not term: continue
word_rx = re.compile(rf"\b{re.escape(term)}\b", re.IGNORECASE)
if word_rx.search(line):
audit.append(PiiHit(page_idx, "force_term", term, PLACEHOLDERS["MASK"]))
audit.append(PiiHit(page_idx, "force_term", term, PLACEHOLDERS["MASK"], forced=True))
line = word_rx.sub(PLACEHOLDERS["MASK"], line)
# force-mask regex
for pat in (cfg.get("blacklist", {}).get("force_mask_regex", []) or []):
@@ -1786,7 +1794,7 @@ def _apply_overrides(line: str, audit: List[PiiHit], page_idx: int, cfg: Dict[st
except Exception:
continue
def _repl_force_regex(m: re.Match, _pat=pat):
audit.append(PiiHit(page_idx, "force_regex", m.group(0), PLACEHOLDERS["MASK"]))
audit.append(PiiHit(page_idx, "force_regex", m.group(0), PLACEHOLDERS["MASK"], forced=True))
return PLACEHOLDERS["MASK"]
line = rx.sub(_repl_force_regex, line)
return line