|
| 1 | +# Task 6 Report: Privacy-safe values and exhaustive sink scanning |
| 2 | + |
| 3 | +## Status |
| 4 | + |
| 5 | +DONE. `SinkScanner` now scans normalized canary variants across nested TruthBench |
| 6 | +sinks and emits only `Leak(canary_id, variant, path)` metadata. Redaction markers |
| 7 | +contain run-scoped HMAC-SHA256 digests and never matched text. |
| 8 | + |
| 9 | +## TDD evidence |
| 10 | + |
| 11 | +### RED |
| 12 | + |
| 13 | +```text |
| 14 | +PYTHONPATH=src python -m pytest tests/truthbench/test_privacy.py -q --no-cov |
| 15 | +``` |
| 16 | + |
| 17 | +Observed collection failure before implementation: |
| 18 | + |
| 19 | +```text |
| 20 | +ModuleNotFoundError: No module named 'benchmarks.truthbench.privacy' |
| 21 | +``` |
| 22 | + |
| 23 | +### GREEN |
| 24 | + |
| 25 | +Focused privacy suite: |
| 26 | + |
| 27 | +```text |
| 28 | +PYTHONPATH=src python -m pytest tests/truthbench/test_privacy.py -q --no-cov |
| 29 | +``` |
| 30 | + |
| 31 | +Result: `18 passed`. |
| 32 | + |
| 33 | +Adjacent TruthBench suites: |
| 34 | + |
| 35 | +```text |
| 36 | +PYTHONPATH=src python -m pytest \ |
| 37 | + tests/truthbench/test_privacy.py \ |
| 38 | + tests/truthbench/test_fixtures.py \ |
| 39 | + tests/truthbench/test_models_exact.py \ |
| 40 | + tests/truthbench/test_schema.py -q --no-cov |
| 41 | +``` |
| 42 | + |
| 43 | +Result: `131 passed`. |
| 44 | + |
| 45 | +Static checks: |
| 46 | + |
| 47 | +```text |
| 48 | +python -m ruff check benchmarks/truthbench/privacy.py \ |
| 49 | + benchmarks/truthbench/__init__.py tests/truthbench/test_privacy.py |
| 50 | +python -m ruff format --check benchmarks/truthbench/privacy.py \ |
| 51 | + benchmarks/truthbench/__init__.py tests/truthbench/test_privacy.py |
| 52 | +mypy --ignore-missing-imports --explicit-package-bases \ |
| 53 | + benchmarks/truthbench/privacy.py tests/truthbench/test_privacy.py |
| 54 | +git diff --check |
| 55 | +``` |
| 56 | + |
| 57 | +## Review follow-up: MultiIndex and hostile-label privacy hardening |
| 58 | + |
| 59 | +### RED |
| 60 | + |
| 61 | +Added regression tests for MultiIndex columns/index level names, tuple-label |
| 62 | +structure during redaction, and custom non-string labels whose stringification |
| 63 | +contains a canary. Before the fix: |
| 64 | + |
| 65 | +```text |
| 66 | +pytest -q tests/truthbench/test_privacy.py --no-cov |
| 67 | +``` |
| 68 | + |
| 69 | +Result: `24 passed, 2 failed`. |
| 70 | + |
| 71 | +The failures were the expected defects: redacting tuple labels converted them |
| 72 | +to lists and raised pandas `ValueError` (length mismatch), while hostile custom |
| 73 | +labels were not scanned. |
| 74 | + |
| 75 | +### GREEN |
| 76 | + |
| 77 | +Structure-preserving label traversal/redaction now handles tuple/MultiIndex |
| 78 | +levels and names, and sanitizes custom label paths before reporting or replacing |
| 79 | +them with digest markers: |
| 80 | + |
| 81 | +```text |
| 82 | +pytest -q tests/truthbench/test_privacy.py --no-cov |
| 83 | +``` |
| 84 | + |
| 85 | +Result: `26 passed`. |
| 86 | + |
| 87 | +Adjacent TruthBench verification: |
| 88 | + |
| 89 | +```text |
| 90 | +pytest -q tests/truthbench --no-cov |
| 91 | +``` |
| 92 | + |
| 93 | +Result: `139 passed`. |
| 94 | + |
| 95 | +Static checks: |
| 96 | + |
| 97 | +```text |
| 98 | +ruff check benchmarks/truthbench/privacy.py tests/truthbench/test_privacy.py |
| 99 | +ruff format --check benchmarks/truthbench/privacy.py tests/truthbench/test_privacy.py |
| 100 | +mypy benchmarks/truthbench/privacy.py |
| 101 | +git diff --check |
| 102 | +``` |
| 103 | + |
| 104 | +All passed. |
| 105 | + |
| 106 | +All passed. |
| 107 | + |
| 108 | +## Files |
| 109 | + |
| 110 | +- `benchmarks/truthbench/privacy.py` — `Leak`, `PrivacySafeValue`, named |
| 111 | + normalizers, run-scoped HMAC scanner, recursive redaction, typed redaction |
| 112 | + handling, pandas/dataclass/bytes support, self-test, and named sink entry points. |
| 113 | +- `benchmarks/truthbench/__init__.py` — exports privacy scanner primitives. |
| 114 | +- `tests/truthbench/test_privacy.py` — mutation matrix for every required |
| 115 | + normalized form, nested sink coverage, redaction/self-test behavior, and typed |
| 116 | + redaction digest safety. |
| 117 | + |
| 118 | +## Self-review |
| 119 | + |
| 120 | +- Leak objects contain only identifiers, transform labels, and JSONPath-like |
| 121 | + locations; `repr(leaks)` cannot repeat canary text. |
| 122 | +- Literal, case-folded, whitespace-stripped, punctuation-stripped, digit-only, |
| 123 | + URL-decoded, HTML-unescaped, UTF-8/hex/escape bytes, NFKC/NFC/NFD, |
| 124 | + zero-width-removed, and JSON-escaped forms are covered. |
| 125 | +- Mapping, sequence, dataclass, pandas DataFrame/Series/Index, exception, |
| 126 | + report, plan, generated-code, stream, markup, JSON, and failure-artifact sinks |
| 127 | + are traversed. Exact redacted `TypedValue` payloads are treated as safe and |
| 128 | + their HMAC digests are not re-scanned as plaintext. |
| 129 | +- Redaction is recursive, emits `[REDACTED:<digest>]`, and `self_test` raises on |
| 130 | + an unredacted result while accepting the scanner's own redacted output. |
| 131 | + |
| 132 | +## Concerns |
| 133 | + |
| 134 | +- The scanner intentionally treats digit-only normalized forms conservatively; |
| 135 | + very short numeric canaries can match unrelated text. Fixtures use synthetic |
| 136 | + identifiers and email/phone canaries, so this does not affect the bundled |
| 137 | + corpus. |
| 138 | +- Redacting a pandas object may change a sensitive column to object/string dtype, |
| 139 | + which is preferable to retaining a raw value in an audit sink. |
| 140 | + |
| 141 | +## Follow-up RED/GREEN evidence |
| 142 | + |
| 143 | +A follow-up regression test used the exact sensitive `TypedValue` redaction shape |
| 144 | +with a one-digit canary. Before the redacted-payload guard, the digest's hex text |
| 145 | +was incorrectly reported as a digit-only leak. After adding the guard: |
| 146 | + |
| 147 | +```text |
| 148 | +PYTHONPATH=src python -m pytest \ |
| 149 | + tests/truthbench/test_privacy.py::test_scanner_accepts_exact_typed_redaction_without_scanning_digest \ |
| 150 | + -q --no-cov |
| 151 | +``` |
| 152 | + |
| 153 | +Result: `1 passed`. |
| 154 | + |
| 155 | +## Review follow-up: marker, key, and label hardening |
| 156 | + |
| 157 | +### RED |
| 158 | + |
| 159 | +The review regression matrix was run before the hardening changes: |
| 160 | + |
| 161 | +```text |
| 162 | +PYTHONPATH=src python -m pytest tests/truthbench/test_privacy.py -q --no-cov |
| 163 | +``` |
| 164 | + |
| 165 | +Result: `4 failed, 17 passed` for forged redaction markers, sensitive mapping |
| 166 | +keys, pandas labels, and the digest compatibility alias. |
| 167 | + |
| 168 | +### GREEN |
| 169 | + |
| 170 | +After validating markers against the scanner's own 64-hex HMAC digest set, |
| 171 | +redacting mapping keys and pandas column/index/name labels, scanning arbitrary |
| 172 | +key stringifications, and adding `digest` as an alias: |
| 173 | + |
| 174 | +```text |
| 175 | +PYTHONPATH=src python -m pytest tests/truthbench/test_privacy.py -q --no-cov |
| 176 | +``` |
| 177 | + |
| 178 | +Result: `23 passed`. |
| 179 | + |
| 180 | +Adjacent TruthBench verification: |
| 181 | + |
| 182 | +```text |
| 183 | +PYTHONPATH=src python -m pytest \ |
| 184 | + tests/truthbench/test_privacy.py \ |
| 185 | + tests/truthbench/test_fixtures.py \ |
| 186 | + tests/truthbench/test_models_exact.py \ |
| 187 | + tests/truthbench/test_schema.py -q --no-cov |
| 188 | +``` |
| 189 | + |
| 190 | +Result: `136 passed`. |
| 191 | + |
| 192 | +Static checks were rerun after the follow-up and remained clean: |
| 193 | + |
| 194 | +```text |
| 195 | +python -m ruff check benchmarks/truthbench/privacy.py \ |
| 196 | + tests/truthbench/test_privacy.py |
| 197 | +python -m ruff format --check benchmarks/truthbench/privacy.py \ |
| 198 | + tests/truthbench/test_privacy.py |
| 199 | +mypy --ignore-missing-imports --explicit-package-bases \ |
| 200 | + benchmarks/truthbench/privacy.py tests/truthbench/test_privacy.py |
| 201 | +git diff --check |
| 202 | +``` |
0 commit comments