redact-audit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- redact_audit-0.1.0/LICENSE +21 -0
- redact_audit-0.1.0/PKG-INFO +410 -0
- redact_audit-0.1.0/README.md +369 -0
- redact_audit-0.1.0/pyproject.toml +64 -0
- redact_audit-0.1.0/redact_audit/__init__.py +3 -0
- redact_audit-0.1.0/redact_audit/__main__.py +202 -0
- redact_audit-0.1.0/redact_audit/_synthetic.py +47 -0
- redact_audit-0.1.0/redact_audit/adapters/__init__.py +200 -0
- redact_audit-0.1.0/redact_audit/adapters/_presidio_nlp.py +89 -0
- redact_audit-0.1.0/redact_audit/adapters/_spans.py +147 -0
- redact_audit-0.1.0/redact_audit/adapters/base.py +182 -0
- redact_audit-0.1.0/redact_audit/adapters/cfproxy.py +194 -0
- redact_audit-0.1.0/redact_audit/adapters/cosy.py +166 -0
- redact_audit-0.1.0/redact_audit/adapters/detect_secrets.py +185 -0
- redact_audit-0.1.0/redact_audit/adapters/guard.py +268 -0
- redact_audit-0.1.0/redact_audit/adapters/llm_guard.py +141 -0
- redact_audit-0.1.0/redact_audit/adapters/mitm/__init__.py +28 -0
- redact_audit-0.1.0/redact_audit/adapters/mitm/ca.py +151 -0
- redact_audit-0.1.0/redact_audit/adapters/mitm/client.py +94 -0
- redact_audit-0.1.0/redact_audit/adapters/mitm/gateway.py +381 -0
- redact_audit-0.1.0/redact_audit/adapters/mitm/proxy.py +199 -0
- redact_audit-0.1.0/redact_audit/adapters/mitm/upstream.py +284 -0
- redact_audit-0.1.0/redact_audit/adapters/mitm_adapter.py +469 -0
- redact_audit-0.1.0/redact_audit/adapters/mitmproxy_adapter.py +666 -0
- redact_audit-0.1.0/redact_audit/adapters/presidio.py +232 -0
- redact_audit-0.1.0/redact_audit/adapters/scrubadub_adapter.py +150 -0
- redact_audit-0.1.0/redact_audit/bridge/__init__.py +170 -0
- redact_audit-0.1.0/redact_audit/bridge/cf_bridge.mjs +157 -0
- redact_audit-0.1.0/redact_audit/bridge/cosy_bridge.mjs +199 -0
- redact_audit-0.1.0/redact_audit/bridge/guard_bridge.mjs +135 -0
- redact_audit-0.1.0/redact_audit/data/baseline/cf-proxy-2026-12-01T170037.json +834 -0
- redact_audit-0.1.0/redact_audit/data/baseline/cosy-2026-12-01T165923.json +638 -0
- redact_audit-0.1.0/redact_audit/data/baseline/detect-secrets-2026-12-01T170035.json +820 -0
- redact_audit-0.1.0/redact_audit/data/baseline/guard-2026-12-01T191604.json +644 -0
- redact_audit-0.1.0/redact_audit/data/baseline/guard-all-2026-12-01T191605.json +621 -0
- redact_audit-0.1.0/redact_audit/data/baseline/llm-guard-2026-12-01T170038.json +15 -0
- redact_audit-0.1.0/redact_audit/data/baseline/mitm-2026-12-01T165923.json +726 -0
- redact_audit-0.1.0/redact_audit/data/baseline/mitmproxy-2026-12-01T165951.json +726 -0
- redact_audit-0.1.0/redact_audit/data/baseline/presidio-2026-12-01T170033.json +776 -0
- redact_audit-0.1.0/redact_audit/data/baseline/scrubadub-2026-12-01T170035.json +700 -0
- redact_audit-0.1.0/redact_audit/data/gen_vectors.py +276 -0
- redact_audit-0.1.0/redact_audit/report/__init__.py +313 -0
- redact_audit-0.1.0/redact_audit/report/compare.py +188 -0
- redact_audit-0.1.0/redact_audit/report/sanitize.py +97 -0
- redact_audit-0.1.0/redact_audit/runners/__init__.py +7 -0
- redact_audit-0.1.0/redact_audit/runners/audit.py +237 -0
- redact_audit-0.1.0/redact_audit/runners/egress.py +450 -0
- redact_audit-0.1.0/redact_audit/runners/frag.py +179 -0
- redact_audit-0.1.0/redact_audit/runners/rehydrate.py +163 -0
- redact_audit-0.1.0/redact_audit/runners/roundtrip.py +151 -0
- redact_audit-0.1.0/redact_audit/runners/roundtrip_cases.py +102 -0
- redact_audit-0.1.0/redact_audit/runners/vectors.py +106 -0
- redact_audit-0.1.0/redact_audit/scorers/__init__.py +8 -0
- redact_audit-0.1.0/redact_audit/scorers/detect.py +218 -0
- redact_audit-0.1.0/redact_audit/scorers/integrity.py +145 -0
- redact_audit-0.1.0/redact_audit/scorers/integrity_cases.py +100 -0
- redact_audit-0.1.0/redact_audit/vendor/cosy_worker.js +993 -0
- redact_audit-0.1.0/redact_audit/vendor/passthrough_worker.js +51 -0
- redact_audit-0.1.0/redact_audit.egg-info/PKG-INFO +410 -0
- redact_audit-0.1.0/redact_audit.egg-info/SOURCES.txt +70 -0
- redact_audit-0.1.0/redact_audit.egg-info/dependency_links.txt +1 -0
- redact_audit-0.1.0/redact_audit.egg-info/entry_points.txt +2 -0
- redact_audit-0.1.0/redact_audit.egg-info/requires.txt +31 -0
- redact_audit-0.1.0/redact_audit.egg-info/top_level.txt +1 -0
- redact_audit-0.1.0/setup.cfg +4 -0
- redact_audit-0.1.0/tests/test_cli_encoding.py +57 -0
- redact_audit-0.1.0/tests/test_compare.py +142 -0
- redact_audit-0.1.0/tests/test_egress.py +98 -0
- redact_audit-0.1.0/tests/test_guard_version.py +46 -0
- redact_audit-0.1.0/tests/test_mitm_adapter.py +135 -0
- redact_audit-0.1.0/tests/test_mitmproxy_adapter.py +210 -0
- redact_audit-0.1.0/tests/test_regression.py +117 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 redact-audit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: redact-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Audit LLM redaction gateways: detection accuracy, integrity, round-trip, chunk safety, placeholder-rewrite resilience
|
|
5
|
+
Author: redact-audit
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jwcy-jy/redact-audit
|
|
8
|
+
Project-URL: Repository, https://github.com/jwcy-jy/redact-audit
|
|
9
|
+
Project-URL: Issues, https://github.com/jwcy-jy/redact-audit/issues
|
|
10
|
+
Keywords: llm,redaction,pii,security,gateway,audit
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Security
|
|
13
|
+
Classifier: Topic :: Text Processing
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Provides-Extra: mitm
|
|
18
|
+
Requires-Dist: cryptography>=41; extra == "mitm"
|
|
19
|
+
Provides-Extra: presidio
|
|
20
|
+
Requires-Dist: presidio-analyzer; extra == "presidio"
|
|
21
|
+
Requires-Dist: presidio-anonymizer; extra == "presidio"
|
|
22
|
+
Provides-Extra: detect-secrets
|
|
23
|
+
Requires-Dist: detect-secrets; extra == "detect-secrets"
|
|
24
|
+
Provides-Extra: scrubadub
|
|
25
|
+
Requires-Dist: scrubadub; extra == "scrubadub"
|
|
26
|
+
Provides-Extra: mitmproxy
|
|
27
|
+
Requires-Dist: mitmproxy; extra == "mitmproxy"
|
|
28
|
+
Provides-Extra: llm-guard
|
|
29
|
+
Requires-Dist: llm-guard; extra == "llm-guard"
|
|
30
|
+
Provides-Extra: all
|
|
31
|
+
Requires-Dist: cryptography>=41; extra == "all"
|
|
32
|
+
Requires-Dist: presidio-analyzer; extra == "all"
|
|
33
|
+
Requires-Dist: presidio-anonymizer; extra == "all"
|
|
34
|
+
Requires-Dist: detect-secrets; extra == "all"
|
|
35
|
+
Requires-Dist: scrubadub; extra == "all"
|
|
36
|
+
Requires-Dist: mitmproxy; extra == "all"
|
|
37
|
+
Requires-Dist: llm-guard; extra == "all"
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# redact-audit
|
|
43
|
+
|
|
44
|
+
**English** · [简体中文](README.zh-CN.md)
|
|
45
|
+
|
|
46
|
+
Audit whether an **LLM redaction gateway** actually works.
|
|
47
|
+
|
|
48
|
+
Most such tools describe themselves with "we support 200+ rules, we detect secrets and PII". That tells you almost nothing. The questions that decide whether a gateway is safe to put in front of a model are different, and almost nobody measures them:
|
|
49
|
+
|
|
50
|
+
| Question | Why it is fatal |
|
|
51
|
+
|---|---|
|
|
52
|
+
| When a span is reported, is the **whole** secret covered? | Covering the second half of a password leaves the first half in the clear |
|
|
53
|
+
| Can placeholders still be restored after the model rewrites them? | If not, the user gets garbage back and **never finds out** |
|
|
54
|
+
| Is a streamed response safe when cut at an arbitrary byte boundary? | A half-emitted placeholder leaks, and the original is lost forever |
|
|
55
|
+
| How bad are the false positives? | Masking git SHAs and base64 images makes the model unable to read your code |
|
|
56
|
+
|
|
57
|
+
`redact-audit` turns those questions into repeatable, comparable measurements.
|
|
58
|
+
|
|
59
|
+
> **Just want the verdict?** → [**AUDIT.md**](AUDIT.md) is the audit report over **10 redaction approaches** (written for people choosing a gateway: conclusions first, five failure modes, and an explicit limitations section). [简体中文版](AUDIT.zh-CN.md).
|
|
60
|
+
> This document is about **how to use the tool, what it measures, and why it measures it that way**.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Engines under audit
|
|
65
|
+
|
|
66
|
+
`python -m redact_audit --list` shows all ten adapters. They fall into three groups, and **that grouping decides which tests mean anything for them**:
|
|
67
|
+
|
|
68
|
+
| Engine | Kind | Mode | Round-trip | Streaming | Upstream | Notes |
|
|
69
|
+
|---|---|---|---|---|---|---|
|
|
70
|
+
| `cosy` | self-built gateway | offline | ✅ | ✅ | — | CosyRedactGateway (218 gitleaks rules) |
|
|
71
|
+
| `mitm` | self-built gateway | mitm | ✅ | ✅ | ✅ | real TLS chain; measures the bytes upstream actually receives |
|
|
72
|
+
| `mitmproxy` | self-built gateway | mitm | ✅ | ✅ | ✅ | mitmproxy addon |
|
|
73
|
+
| `guard` | self-built gateway | offline | ❌ | ❌ | ✅ | dsh-redact-guard, 13 of 17 rules by default |
|
|
74
|
+
| `guard-all` | comparison config | offline | ❌ | ❌ | ✅ | same engine, all 17 rules |
|
|
75
|
+
| `presidio` | OSS library | offline | ❌ | ❌ | — | Microsoft Presidio, pattern recognizers only |
|
|
76
|
+
| `detect-secrets` | OSS library | offline | ❌ | ❌ | — | Yelp detect-secrets, scanner semantics |
|
|
77
|
+
| `scrubadub` | OSS library | offline | ❌ | ❌ | — | scrubadub, PII-oriented |
|
|
78
|
+
| `llm-guard` | OSS library | offline | ❌ | ❌ | — | LLM Guard Anonymize, needs torch |
|
|
79
|
+
| `cf-proxy` | **negative control** | reverse | ❌ | ❌ | ✅ | pure passthrough, **must score zero everywhere** |
|
|
80
|
+
|
|
81
|
+
**The three OSS libraries are not gateways.** detect-secrets and presidio are designed to "flag suspicious strings for a human to review before commit" — false positives are acceptable because a person adjudicates. A gateway's false positives rewrite the user's code and logs directly. Running this suite against them measures "what happens when you put a scanner in the request path", and the unflattering result *is* the finding.
|
|
82
|
+
|
|
83
|
+
### "Not tested" is not "failed"
|
|
84
|
+
|
|
85
|
+
This is the easiest thing to get wrong in this project, so it is enforced in code and documented here.
|
|
86
|
+
|
|
87
|
+
A test that did not run has four distinct causes, and a report must keep them apart:
|
|
88
|
+
|
|
89
|
+
| State | Meaning | Shown as |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| PASS | ran, passed | `✅ PASS` |
|
|
92
|
+
| FAIL | ran, failed | `❌ FAIL` |
|
|
93
|
+
| **not tested (capability missing)** | the engine declares it does not support this; the test does not apply | `⏸ n/a` + reason |
|
|
94
|
+
| **skipped** | dependency missing / engine would not start | `— skipped —`, every score field `None` |
|
|
95
|
+
|
|
96
|
+
**Why be pedantic about it:** an early version merged the two `frag` halves with `ok = a.ok and b.ok`. `None and x` is falsy, so "not a single split point ran" was silently downgraded to "fragmentation failed". Readers would then go fix a bug that does not exist — **worse than not testing at all.**
|
|
97
|
+
|
|
98
|
+
The same trap sits in `capabilities()` overrides: forget one key and it returns `None` instead of `False`. Both are falsy, so any `is False` check silently stops working. **An override must spell out every key of the base class.**
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## The six test families
|
|
103
|
+
|
|
104
|
+
### 1. Detection accuracy (Detect)
|
|
105
|
+
|
|
106
|
+
33 true-positive vectors and 31 trap vectors.
|
|
107
|
+
|
|
108
|
+
- **Recall** — the `secret` literal must be fully covered by some span at **every** occurrence in the input. Missing one occurrence means the vector is missed. Counted per vector, not per character: counting characters makes "covered half of it" look like success.
|
|
109
|
+
- **Precision** — any span at all inside a trap text counts as a false positive. Traps deliberately contain no secrets, so the tolerance is zero.
|
|
110
|
+
- **Attribution** — every false positive must name the rule that fired, otherwise the cause cannot be located.
|
|
111
|
+
|
|
112
|
+
### 2. Integrity — the core of this project
|
|
113
|
+
|
|
114
|
+
P/R only ask "was a span reported". **A reported span is not a covered secret.** Integrity checks per-character coverage:
|
|
115
|
+
|
|
116
|
+
> Split the must-stay-secret literal into characters and check that every position falls inside a reported span.
|
|
117
|
+
|
|
118
|
+
This catches the most dangerous failure class:
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
input postgres://admin:s3cr3tP@ssw0rd@db.internal:5432/prod
|
|
122
|
+
span [25:43] "ssw0rd@db.internal" ← email rule matches from the LAST @
|
|
123
|
+
result postgres://admin:s3cr3tP@{{Redact:...}}:5432/prod
|
|
124
|
+
^^^^^^^^ password prefix sent upstream in the clear
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
In P/R this shows up as a *hit*. In the real world it shows up as a **credential leak**.
|
|
128
|
+
|
|
129
|
+
### 3. Round-trip (Roundtrip)
|
|
130
|
+
|
|
131
|
+
Redact → restore must be **byte-identical**. Covered for plain text, three API protocols (`openai_chat` / `anthropic_messages` / `openai_responses`) and SSE streams.
|
|
132
|
+
|
|
133
|
+
Semantic boundaries are checked too: the `model` field must not be touched (changing it gets you a 400), existing placeholders must not be processed twice, equal values deduplicate, and salts are isolated per session.
|
|
134
|
+
|
|
135
|
+
### 4. Chunk safety (SPG-FRAG-1)
|
|
136
|
+
|
|
137
|
+
When an SSE response arrives split across TCP segments, a 74-character placeholder will almost certainly be cut in half.
|
|
138
|
+
|
|
139
|
+
Criterion: at **every** two-part split point, plus character-by-character delivery, the restored text must be complete and must not retain any `{{Redact:`.
|
|
140
|
+
|
|
141
|
+
### 5. Placeholder-rewrite resilience (SPG-REHYDRATE-1)
|
|
142
|
+
|
|
143
|
+
Placeholders travel through the model's context, and models rewrite them constantly: backticks, bold, case changes, line breaks, added spaces, stripped braces.
|
|
144
|
+
|
|
145
|
+
20 rewrite shapes are tested. The criterion is **whether the original text actually came back**, not "whether the placeholder disappeared" — the latter counts "braces stripped, so the bare hex no longer matches" as success.
|
|
146
|
+
|
|
147
|
+
Silent failure is checked separately: no exception, no warning, no log entry means the caller has no way to know.
|
|
148
|
+
|
|
149
|
+
### 6. Upstream leakage (EGRESS-1)
|
|
150
|
+
|
|
151
|
+
The first five families look at what the engine *says* it masked. This one compares **the bytes the upstream server actually received**, captured through a real proxy chain.
|
|
152
|
+
|
|
153
|
+
Six cases: one control (plaintext must pass through untouched, proving the chain does not corrupt requests), two full-mask cases, three partial-mask cases.
|
|
154
|
+
|
|
155
|
+
**Only adapters that can sit on the wire run this family.** A pure-function engine (Cosy's offline mode) has no "upstream"; it declares `egress: False` in `capabilities()` and the report records `n/a`. **`n/a` means not tested, not zero leakage** — conflating the two produces the opposite conclusion.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Install and use
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pip install redact-audit # core package: zero Python dependencies, node is enough
|
|
163
|
+
|
|
164
|
+
# optional engine extras
|
|
165
|
+
pip install 'redact-audit[mitm]' # cryptography, for the MITM chain and EGRESS-1
|
|
166
|
+
pip install 'redact-audit[presidio]' # presidio-analyzer / presidio-anonymizer
|
|
167
|
+
pip install 'redact-audit[all]' # everything, including llm-guard (~2GB of torch)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# full audit
|
|
172
|
+
redact-audit --adapter cosy --vectors all
|
|
173
|
+
|
|
174
|
+
# fastest useful subset
|
|
175
|
+
redact-audit --adapter cosy --only detect,integrity
|
|
176
|
+
|
|
177
|
+
# machine-readable
|
|
178
|
+
redact-audit --adapter cosy --quiet # overall verdict JSON only
|
|
179
|
+
redact-audit --adapter cosy --json # full JSON
|
|
180
|
+
|
|
181
|
+
# list adapters
|
|
182
|
+
redact-audit --list
|
|
183
|
+
|
|
184
|
+
# compare: one table of the latest run per engine
|
|
185
|
+
redact-audit --compare
|
|
186
|
+
redact-audit --compare --adapters cosy,guard,mitmproxy
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Results go to `./out/`: a Markdown report plus a full JSON. `--compare` additionally writes `out/compare.md` and `out/compare.json`.
|
|
190
|
+
|
|
191
|
+
**Exit code**: integrity leak / fragmentation failure / silent failure → `1`, usable directly as a CI gate.
|
|
192
|
+
|
|
193
|
+
The vector set is a generated artifact and is **not** shipped as plaintext (positive samples must contain realistic-looking credential literals). The generator *is* shipped, so a fresh install generates it on first run into the user cache directory. `REDACT_AUDIT_VECTORS` overrides the location.
|
|
194
|
+
|
|
195
|
+
### Three rules that make the comparison table trustworthy
|
|
196
|
+
|
|
197
|
+
They are documented in the docstring of `redact_audit/report/compare.py`:
|
|
198
|
+
|
|
199
|
+
1. **Skipped rows do not enter the ranking.** An engine with a missing dependency is recorded as "— skipped —". Ranking it at zero turns "I did not install it" into "it is the worst", which is the easiest way to fool yourself.
|
|
200
|
+
2. **The negative control does not enter the ranking.** `cf-proxy` deliberately does not redact; its job is to validate the auditor (it must score zero). Ranking it is meaningless.
|
|
201
|
+
3. **`None` neither sorts nor renders as 0.** A ratio with a zero denominator is undefined. Showing 0 reads as "computed to be 0".
|
|
202
|
+
|
|
203
|
+
`--compare` reads results already present in `out/*.json`; it never re-runs. Re-running would let the inputs (vector set, engine version, randomness) change, and then you would be comparing run moments instead of engines.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Results
|
|
208
|
+
|
|
209
|
+
Full report in [**AUDIT.md**](AUDIT.md). Below is only the cross-engine table, and all rows come from **the same run** (`scripts/_rerun_all.py`, 44.9 s):
|
|
210
|
+
|
|
211
|
+
| Engine | P | R | F1 | Spec | Integrity | Leaked chars | RT | Chunk | Rewrite | Silent | Egress |
|
|
212
|
+
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
213
|
+
| cosy | 71.7% | **100%** | 83.5% | 58.1% | 84.6% | 12 | 8/8 | ✅ 303 | 20.0% | 16 | n/a |
|
|
214
|
+
| mitm | 71.7% | **100%** | 83.5% | 58.1% | 84.6% | 12 | 8/8 | ✅ 303 | 20.0% | 16 | 0 |
|
|
215
|
+
| mitmproxy | 71.7% | **100%** | 83.5% | 58.1% | 84.6% | 12 | 8/8 | ✅ 303 | 20.0% | 16 | 0 |
|
|
216
|
+
| guard-all | 87.5% | 63.6% | 73.7% | 90.3% | **100%** | **0** | 0/8 | ⏸ n/a | 0.0% | 0 | 0 |
|
|
217
|
+
| guard | 90.0% | 54.5% | 67.9% | 93.5% | 84.6% | 25 | 0/8 | ⏸ n/a | 0.0% | 0 | 0 |
|
|
218
|
+
| detect-secrets | 43.5% | 60.6% | 50.6% | **16.1%** | 53.8% | 58 | 0/8 | ⏸ n/a | 0.0% | 0 | n/a |
|
|
219
|
+
| scrubadub | 83.3% | 15.2% | 25.6% | 96.8% | 30.8% | 270 | 0/8 | ⏸ n/a | 0.0% | 0 | n/a |
|
|
220
|
+
| presidio | 37.5% | 9.1% | 14.6% | 83.9% | 7.7% | 373 | 0/8 | ⏸ n/a | 0.0% | 0 | n/a |
|
|
221
|
+
| cf-proxy | n/a | 0.0% | n/a | 100% | 0.0% | 392 | 0/8 | ⏸ n/a | 0.0% | 0 | **345** |
|
|
222
|
+
| llm-guard | — skipped (`No module named 'llm_guard'`, needs torch ≈2GB) ||||||||||
|
|
223
|
+
|
|
224
|
+
**Three things to keep in mind reading this table:**
|
|
225
|
+
|
|
226
|
+
1. **`⏸ n/a` is not `❌ FAIL`.** The guard engines have no streaming restore (`capabilities.streaming=False`); the presidio family never redacts in the first place (plaintext is still in the output, so there is no placeholder to cut). Neither reaches the "cut it" step. Recording "95 of 95 failed" would accuse them of something they never attempted.
|
|
227
|
+
2. **Round-trip and chunk columns only mean something for engines declaring `roundtrip` / `streaming`.** The three OSS libraries and cf-proxy do not claim either capability, so comparing them to a gateway there is unfair — **but the P/R/specificity column is fair**, that is their actual job.
|
|
228
|
+
3. **`n/a` means not tested, not 0.** A pure-function engine has no "upstream", so EGRESS-1 cannot be observed on it.
|
|
229
|
+
|
|
230
|
+
### CosyRedactGateway detail (218 gitleaks rules, offline pure function)
|
|
231
|
+
|
|
232
|
+
> Offline pure-function mode is the **ceiling reference** for this class of engine: if it cannot be accurate as a pure function, it will only be worse in production.
|
|
233
|
+
|
|
234
|
+
| Metric | Score |
|
|
235
|
+
|---|---|
|
|
236
|
+
| Precision | 71.7% |
|
|
237
|
+
| Recall | **100.0%** |
|
|
238
|
+
| F1 | 83.5% |
|
|
239
|
+
| Specificity | 58.1% |
|
|
240
|
+
| Integrity pass rate | 84.6% |
|
|
241
|
+
| Integrity leaked chars | **12** |
|
|
242
|
+
| Round-trip | 8/8 ✅ |
|
|
243
|
+
| Chunk safety | ✅ PASS (303 split points) |
|
|
244
|
+
| Rewrite resilience | **20.0%** (4/20) |
|
|
245
|
+
| Silent failures | **16** |
|
|
246
|
+
|
|
247
|
+
### Three hard findings
|
|
248
|
+
|
|
249
|
+
**1. When a connection-string password contains `@` or `:`, part of it goes upstream in the clear**
|
|
250
|
+
|
|
251
|
+
| Password | Leak |
|
|
252
|
+
|---|---|
|
|
253
|
+
| `PlainPassword123` | 0/16 ✅ |
|
|
254
|
+
| `s3cr3tP@ssw0rd` | **8/14** ❌ `s3cr3tP@` in the clear |
|
|
255
|
+
| `abc:def` | **4/7** ❌ `abc:` in the clear |
|
|
256
|
+
|
|
257
|
+
Root cause: the email rule matches from the **last** `@`, leaving the password prefix uncovered by any span.
|
|
258
|
+
|
|
259
|
+
**2. Rewrite resilience is only 20%, and every failure is silent**
|
|
260
|
+
|
|
261
|
+
16 of 20 structural rewrites (braces stripped, case changed, split across lines, spaces inserted…) fail to restore, and nothing throws, warns, or logs. The client just sees a leftover placeholder or a bare hex string treated as ordinary text.
|
|
262
|
+
|
|
263
|
+
**3. All 13 false positives come from the `entropy` rule**
|
|
264
|
+
|
|
265
|
+
Masked by mistake: git SHA-1, MD5, SHA-256, base64 image fragments, hyphen-less UUIDs, trace IDs, docker digests, base32 strings, SSH public keys, PEM public keys, DB schema, ordinary long words.
|
|
266
|
+
|
|
267
|
+
These directly break the model's understanding of code: mask the commit SHA in `git log` and the model can no longer locate the change.
|
|
268
|
+
|
|
269
|
+
### One genuine strength
|
|
270
|
+
|
|
271
|
+
Chunk safety **PASS**: all 303 split points restore correctly. The `SseRestorer` logic that holds back a buffer while `possibleTokenSuffixLength > 0` works. This is rare among comparable engines.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Architecture
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
redact_audit/
|
|
279
|
+
├── adapters/ adapter protocol + engine implementations
|
|
280
|
+
│ ├── base.py Adapter / Span / DetectResult (capability defaults live here)
|
|
281
|
+
│ ├── cosy.py CosyRedactGateway (offline)
|
|
282
|
+
│ ├── guard.py dsh-redact-guard (13-rule default / all 17 rules)
|
|
283
|
+
│ ├── cfproxy.py cf-proxy pure passthrough (negative control)
|
|
284
|
+
│ ├── presidio.py Microsoft Presidio (pattern recognizers only)
|
|
285
|
+
│ ├── detect_secrets.py Yelp detect-secrets
|
|
286
|
+
│ ├── scrubadub_adapter.py scrubadub
|
|
287
|
+
│ ├── llm_guard.py LLM Guard Anonymize (needs torch)
|
|
288
|
+
│ ├── mitm_adapter.py MITM-chain adapter (detect over real TLS)
|
|
289
|
+
│ ├── mitmproxy_adapter.py mitmproxy addon (streaming restore pipeline)
|
|
290
|
+
│ └── mitm/ self-contained MITM components
|
|
291
|
+
│ ├── ca.py local CA, issues site certs on the fly
|
|
292
|
+
│ ├── proxy.py CONNECT proxy with half-close forwarding
|
|
293
|
+
│ ├── gateway.py reference gateway (rewrite / streaming restore)
|
|
294
|
+
│ └── upstream.py fake upstream (records what it really received)
|
|
295
|
+
├── bridge/ Python ↔ Node JSONL RPC
|
|
296
|
+
│ ├── __init__.py NodeBridge (long-lived child process, holds the session table)
|
|
297
|
+
│ └── cosy_bridge.mjs
|
|
298
|
+
├── runners/ the six test families
|
|
299
|
+
│ ├── audit.py orchestration; skipped and errors are kept separate
|
|
300
|
+
│ ├── roundtrip.py + roundtrip_cases.py
|
|
301
|
+
│ ├── frag.py SPG-FRAG-1 (tri-state ok plus a skip field)
|
|
302
|
+
│ ├── egress.py EGRESS-1 (the bytes upstream actually received)
|
|
303
|
+
│ └── rehydrate.py SPG-REHYDRATE-1
|
|
304
|
+
├── scorers/
|
|
305
|
+
│ ├── detect.py P/R/F1 + false-positive attribution
|
|
306
|
+
│ └── integrity.py + integrity_cases.py per-character coverage
|
|
307
|
+
└── report/
|
|
308
|
+
├── __init__.py single-engine report (_frag_cell / _frag_detail handle tri-state)
|
|
309
|
+
├── compare.py cross-engine table (_fmt distinguishes tri-state from numeric None)
|
|
310
|
+
└── sanitize.py masks secret-shaped substrings before anything is written to disk
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### The three adapter modes
|
|
314
|
+
|
|
315
|
+
A redaction gateway comes in three shapes, and the only capability they must share is: **given text, tell me which ranges it masked.** Everything else is composed by the runners, which is what keeps scores comparable across engines.
|
|
316
|
+
|
|
317
|
+
| Mode | Shape | How a client connects |
|
|
318
|
+
|---|---|---|
|
|
319
|
+
| `offline` | the engine is callable as a pure function | import it directly (Cosy's `worker.js`) |
|
|
320
|
+
| `reverse` | reverse-proxy gateway | change `base_url` |
|
|
321
|
+
| `mitm` | MITM-proxy gateway | set `HTTPS_PROXY` + install the CA |
|
|
322
|
+
|
|
323
|
+
### MITM mode: why the whole chain is built in-tree
|
|
324
|
+
|
|
325
|
+
`offline` mode can only see **what the engine returned**. On a security product that is fatal: the engine says it masked something, the test records that it masked it — you are measuring self-report.
|
|
326
|
+
|
|
327
|
+
The `mitm` adapter's `detect()` does not read the engine's answer. It reads:
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
client → CONNECT proxy → reference gateway → fake upstream
|
|
331
|
+
↑
|
|
332
|
+
the body is taken off right here
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
It captures the bytes the upstream actually received and reconstructs spans from the original. If any link in the chain misbehaves, the reconstruction exposes it.
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
redact-audit --adapter mitm --vectors all
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
The chain brings its own local CA (issued on the fly with `cryptography`, no `openssl` CLI), CONNECT proxy, programmable gateway, and a request-recording fake upstream. Swapping the engine under test is one constructor argument.
|
|
342
|
+
|
|
343
|
+
**Engines are pluggable**: `MitmAdapter(engine=...)` only requires `redact(text)` / `restore(text)`. The default uses Cosy's `worker.js` — not because it is equivalent to any particular commercial gateway, but because **the chain itself must be validated first**. The report states this plainly: the default configuration measures "the Cosy engine behind an MITM gateway", not "the redaction quality of VibeGuard".
|
|
344
|
+
|
|
345
|
+
#### Three problems that only surface on a real wire
|
|
346
|
+
|
|
347
|
+
None of these are theoretical; they were found by running it:
|
|
348
|
+
|
|
349
|
+
1. **The proxy does not forward EOF, so the client hangs forever.** When a response carries `Connection: close`, the client uses EOF to detect the end. `_splice` used to remove only itself from the set when one side returned `b""`, leaving the peer open — the client waits until timeout. Half-close forwarding (`shutdown(SHUT_WR)` to the peer) is mandatory.
|
|
350
|
+
|
|
351
|
+
2. **SSE frame boundaries land inside placeholders.** `data: {{Redact:ab` + `\n\n` + `data: cd...}}` — searching raw bytes for `{{` will never find a complete token. The `data:` line payloads must be joined first, and the hold-back decision made on the joined text. **A gateway that only regexes the byte stream silently fails to restore under SSE**: the client sees half a placeholder while the log says "processed".
|
|
352
|
+
|
|
353
|
+
3. **Character-level diffing fools itself.** The `138` inside a secret and the `138` inside a placeholder's hex get aligned as "equal" by `SequenceMatcher`, so the span covers only the middle of the secret and an 11-character phone number is judged "uncovered" — it looks like a detection miss, but the algorithm is wrong. The fix is **anchor segmentation**: the redaction product is recognizable, and the plain text between products is necessarily preserved verbatim, so sequential location reconstructs the ranges.
|
|
354
|
+
|
|
355
|
+
### Why a Node bridge instead of a Python rewrite
|
|
356
|
+
|
|
357
|
+
Cosy's `RedactionContext` is stateful (token→raw lives inside the instance), and redact/restore must happen on the **same instance**. Python cannot hold a JS object, so a long-lived Node process holds the session table and Python only sends ops.
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Pitfalls (recorded so nobody repeats them)
|
|
362
|
+
|
|
363
|
+
1. `findSensitiveSpans(text, flags, ...)` takes `flags` as an **object**, not a string. `parseFlags('')` turns everything on.
|
|
364
|
+
2. `restoreJson` **mutates its argument in place**. Round-trip tests must snapshot with `json.dumps` first, otherwise restore rewrites `redacted` back to the original and you get a **false pass**.
|
|
365
|
+
3. `restoreSseStream` takes a **ReadableStream**, not a string.
|
|
366
|
+
4. Restore must reuse the **same** `RedactionContext` instance.
|
|
367
|
+
5. `text.find(secret)` only finds the first occurrence. If a trap text happens to contain a secret substring you get a **false leak**. Every occurrence must be walked.
|
|
368
|
+
6. Rewrite resilience cannot be judged by "did the placeholder disappear" — once the braces are stripped it is not a placeholder anymore and gets counted as a successful restore.
|
|
369
|
+
7. Card-number vectors must pass Luhn, otherwise the engine (correctly) refuses to flag them and it looks like a miss.
|
|
370
|
+
8. A PowerShell here-string `@"..."@` expands `$`. Code containing `$` must be written to a file and executed.
|
|
371
|
+
9. The fake upstream sending the whole body in one `sendall` lets TCP coalesce it into a single segment — the gateway then sees exactly one `recv` and "fragmentation" never happens. Send chunk by chunk with a small gap (4 ms is enough), or the chunk test passes for the wrong reason.
|
|
372
|
+
10. If `CannedResponse` prepends `data: ` to a fragment that is already complete SSE text, you get double framing and are no longer testing fragmentation. A `raw_chunks` channel that emits bytes verbatim is required.
|
|
373
|
+
11. If `restore_stream` returns only the joined payload and drops the `data: ` framing, it can never equal the original SSE text. Real consumers `JSON.parse` frame by frame; the framing *is* the subject under test.
|
|
374
|
+
12. **mitmproxy's `stream` callback may only return `list[bytes]`.** Per `mitmproxy/proxy/layers/http/__init__.py:447-456`: `if isinstance(chunks, bytes): chunks = [chunks]` then `for chunk in chunks: yield ResponseData(...)`. Measured consequences of the three shapes — `b""` is wrapped into `[b""]`, emitting a **zero-length chunked block**, and a zero-length block means end-of-message, so the client considers the body finished (character-by-character delivery is left with just the opening `data: `); `None` makes `for chunk in None` raise TypeError, the stream dies mid-flight and the client times out (round-trip drops from 8/8 to 6/8, both failures being `TimeoutError`); only `[]` means "hold this block, keep the stream open".
|
|
375
|
+
13. **The incremental restorer's hold-back buffer must be cleared after it is emitted.** `_ChunkRestorer.feed()` used to store the held-back part in `_tail` without clearing `_buf`, so the next round's `_buf += _tail + chunk` re-joined bytes that had already gone out. The symptom is distinctive: mass failures at arbitrary split points (75/303) while character-by-character delivery "mostly passes" — because at one character per chunk the held length is always 1 and the duplication is too small to notice.
|
|
376
|
+
14. **Deciding whether a partial placeholder must be held back cannot rely on guessing the token with a regex.** `{{Redact:[0-9a-f]{0,64}` was exact-matching, but inside JSON the partial token is followed by a structural character such as `"` (`...{{Redact:aaa"}`), the regex failed on the trailing character, "should hold" became "ordinary text", and the half placeholder went to the client — **irreversibly**. The correct criterion is purely structural: a trailing single `{` holds 1 character (it may be the first half of `{{`); if the last `{{` has no `}}` after it, hold the whole tail. Prefer holding too much — a held byte is guaranteed to be flushed later, an emitted one cannot be taken back.
|
|
377
|
+
15. **Do not write a separate "merge frame payloads then restore" path for SSE.** Merging two frames yields `{"content":"…"}{"content":"…"}`, which is not valid JSON and breaks any real client on parse; and in real SSE a placeholder never spans frames (frames are `\n\n`-delimited and only complete frames are sent). Byte-level hold-back already covers every real case, and one extra layer of cleverness only adds new breakage points.
|
|
378
|
+
16. **`None and x` silently downgrades "not tested" to "failed".** `audit.py` used to compute the frag verdict as `"ok": fo.ok and pc.ok`. After `FragOutcome.ok` became tri-state `bool | None`, `None and False` is `None` but the whole expression is falsy, the renderer treated it as `False`, and an engine that ran zero split points showed up as `❌ FAIL` in the report. **Readers would go fix a bug that does not exist.** The fix is to filter `None` first: `oks = [x for x in (a, b) if x is not None]`, returning `None` only when all are `None`.
|
|
379
|
+
17. **Capability declarations must be checked before guessing at symptoms.** The first frag gate tested "output contains no mutable placeholder" before "does the engine declare streaming", so guard's fixed `[REDACTED:api-key]` fell into that branch and was misjudged as "there is no failure mode where a token gets cut". It certainly *would* be cut into `[REDACTED:api` — the real cause is not "no mutable token" but "no restore capability at all". **Wrong order of checks gives a conclusion that looks right for entirely wrong reasons.**
|
|
380
|
+
18. **A missing key in a `capabilities()` override lets `None` impersonate `False`.** `cosy.py`'s override omitted `egress`, so it returned `None` instead of the base class default `False`. Both are falsy, `.get("egress")` cannot tell the difference, and any `is False` check silently stops working (the negative control's criterion ran straight into this: `frag is False` against `None` reports a false anomaly). **An override must spell out every key of the base class; one missing is one latent bug.**
|
|
381
|
+
19. **Check the JSON shape before writing a statistics script, not your memory of it.** The first `_count_assertions.py` used `len(detect["positives"])` and `len(frag["cases"])` and produced the fake numbers detect=0, frag=2 — the detect assertion count is `tp+fp+fn+tn`, and `frag`'s `cases` holds only 2 summary records while the real count is `splits`. **Run a tiny `_shape.py` that prints keys and lengths first.**
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## Tests
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
pip install -e ".[dev,mitm]"
|
|
389
|
+
python -m pytest tests -q
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
64 regression tests pinning behaviour that was measured. Two of them **deliberately assert that a leak still exists** — if an engine ever fixes it, the test fails and reminds you to update the report.
|
|
393
|
+
|
|
394
|
+
The `mitm` extra is required for the full count: `tests/test_mitm_adapter.py`, `tests/test_mitmproxy_adapter.py` and `tests/test_egress.py` import the TLS chain at module level, and it needs `cryptography`. Without it those three files **skip** (31 pass, 3 skip) rather than abort collection — a collection error would take down the other 61 tests too. CI installs the extra and fails on any skip.
|
|
395
|
+
|
|
396
|
+
Releasing is covered separately in [`docs/RELEASING.md`](docs/RELEASING.md) — read it before the first upload, because a PyPI filename is permanently spent once used and deleting a release does not free it.
|
|
397
|
+
|
|
398
|
+
`tests/test_mitm_adapter.py` guards four properties of the MITM chain: that observation happens at the end of the chain, that span reconstruction is not fooled by character-level misalignment, that SSE frame boundaries rejoin without changing frame structure, and that character-by-character fragmentation still restores completely. None of these test "how well the engine masks" — that is the vector set's job.
|
|
399
|
+
|
|
400
|
+
`tests/test_mitmproxy_adapter.py` guards **the adapter's own restore pipeline** (pitfalls 12–15 each have a case): hold-back boundaries (including a split between the two `{` and a partial placeholder followed by a JSON structural character), no double-join under character delivery, flush always emitting held bytes, failing to restore emitting the bytes as-is rather than silently swallowing them, and the `stream` callback **must return a list** — the easiest semantic to get wrong.
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
## Synthetic credentials
|
|
405
|
+
|
|
406
|
+
Every credential literal in this repository is fictitious and assembled at import time from short fragments (`redact_audit/_synthetic.py`), so the source tree never contains a contiguous secret-shaped string. This keeps GitHub push protection quiet and keeps your own secret scanner from firing on the checkout. The vector set is likewise generated rather than committed.
|
|
407
|
+
|
|
408
|
+
## License
|
|
409
|
+
|
|
410
|
+
MIT
|