Part 1 ended with a report: every entity Elide found in a document, reconciled, and checked by a person. This part is about applying it.
Two things have to leave the file. The entities a reviewer approved, each replaced by something that no longer says what it said. And everything else the file carries that no reader sees: properties, tracked changes, a thumbnail of the first page. Then there is a third obligation, which is to leave a record someone else can check.
What an entity becomes
An operator produces the replacement for one entity, and a policy binds
operators to labels: mask government IDs, replace names, erase whatever no
rule covers. The catalogue runs from Erase and Replace through Mask,
Truncate, hashes and Pseudonymize to AesEncrypt; images get Blur,
Pixelate and Blackbox, audio Silence and Beep.
The useful question about an operator is how much of the original survives
it. Every operator declares this as a LeakProfile:
- Irrecoverable: nothing survives.
Erase, and dropping a row or column. - Partial: the value is gone; its position and extent remain.
MaskandReplaceare partial, and so isBlackbox: a solid box over a signature still says where the signature was and how large. - Recoverable: the output stays linked to the original.
AesEncryptdecrypts with its key.Pseudonymizekeeps a vault that maps each value to its surrogate. A hash can be brute-forced when the inputs are few, which is why SHA-2 and HMAC count as recoverable. And aReplacetemplate that writes{value}back is recoverable whatever it looks like.
The operator declares its profile in code, so a policy can be checked before it ships: reject any recoverable operator on a label your policy says must be destroyed.
The plan shown is the plan that runs
A reviewer who approved what was found also needs to see what will be done to
it. orchestrator.pick(&mut report) records that on every entity as a
selection event, without touching the document. A selection carries the
operator’s name and version, its leak profile, the rule that matched (a label,
a tag, a predicate, or the fallback), and the rationale the rule carries.
The gap this closes is a plan shown to a reviewer that differs from the one
that runs. pick uses the same anonymizers and scope as anonymize_with, and
resolves overlapping entities the same way. Suppressed entities are skipped.
Picking again after an edit records only the selections that changed, so the
trail stays a list of decisions.
orchestrator.pick(&mut report)?;
let applied = orchestrator.anonymize_with(&mut document, report).await?;
Applying checks that the pick is still current. anonymize_with
resolves each decision again and, if an edit changed it, records the new
selection before running anything. It then records a redaction event, which
holds exactly one field: the hash of the selection it applied. The answer to
“which operator ran, and why” is read from the decision itself, so it is recorded once.
Two details keep this honest. Redaction events are recorded only after the
write into the document succeeds, so a failed write cannot leave a trail
claiming something was hidden. And Keep writes nothing and gets no redaction
event; its selection alone records that the policy chose to keep the value.
For the SSN from part 1, under a policy that masks government IDs on the authority of GDPR’s right to erasure, the trail reads:
pattern 0.50 rule ssn, validator us.ssn, at 25..36
refinement 0.85 keyword "ssn" near the match
selection 0.85 mask 1.0.0, partial, label government_id, gdpr-art-17
redaction 0.85 mask, applied selection 3b71…e0
What else a file carries
Everyone has seen the redacted document that was not. The black boxes sit in the right places, and then someone opens the file’s properties and finds the author, or turns on tracked changes and reads the paragraph deleted before the boxes went on, or opens the thumbnail of the first page, rendered before anything was redacted.
Take a settlement agreement drafted in Word and reviewed by a partner. Beside
its body text, the .docx holds:
| Kind | Example |
|---|---|
| Metadata | Author, last editor, company, custom properties |
| Collaboration | The partner’s comments, tracked insertions and deletions; in a PDF, annotations |
| Preview | A thumbnail of the first page |
| External reference | The path of the attached template on someone’s disk |
| Active content | Macros, ActiveX controls, add-ins |
| Fingerprint | Editing-session ids, document ids, a protection password hash |
| Remnant | In a PDF, objects an earlier revision left behind |
| Unextracted | Alternative text, a content control’s title and tag |
These are eight of the nine kinds of hidden content Elide names; the ninth is
an embedded file no codec can read. Some are worse than they look. Word stamps
rsid attributes on paragraphs to tie a document’s editing sessions together.
Excel records absPath, the absolute path the workbook was last saved to,
which often contains a user name. Elide removes these on every decode,
whatever the caller asks for.
Strip at decode, check at encode
Hidden content is stripped when the file is decoded, before any recognizer runs, so detection sees exactly what the redacted file will carry. There is no second pass that cleans up afterwards and could disagree with what was detected.
The PDF codec takes this furthest. It writes a new document at decode, copying only the pages, the resources their content names, links inside the document, and attached files under neutral names. Everything else stays behind, including objects that only an earlier revision still reaches.
On the way out, every encode checks its own output. For an Office package, the check sanitizes the encoded file a second time and requires that pass to remove and change nothing, every relationship to resolve, and every property part to use only reviewed XML vocabularies. For a PDF, a trial rebuild of the output must drop nothing. A file that fails is withheld: the encode completed, and its output failed the check.
Two choices, three answers
Only metadata and collaboration are a choice, because they are the only kinds
where reasonable callers want different outcomes. A firm sending a contract to
opposing counsel wants comments gone; a team archiving a reviewed draft may
want them kept and scanned. The choice is a HiddenContentPolicy, set per
document when it is decoded:
let policy = HiddenContentPolicy::default()
.with_metadata(Disposition::ScanAsContent)
.with_collaboration(Disposition::FlagEverything);
let document = FormatRegistry::with_builtin()
.document("agreement.docx", bytes, policy)
.await?;
KeepOnlyEssential, the default, removes the content without inspecting it.
For the agreement, that is the final visible document: insertions accepted,
deletions applied, comments dropped. For a photo, every EXIF tag goes except
Orientation, which decides which way up the pixels are drawn.
ScanAsContent keeps the content and treats it like the body. The agreement’s
properties become fields labelled by what they are, and a field whose label the
request covers is redacted. The comments stay, and recognizers read them like
body text, so a client’s name in a comment is redacted and the rest survives.
FlagEverything makes every comment, author and tracked deletion an entity of
its own, whatever the request covers, and erases it unless a rule says
otherwise, Keep included.
Everything stripped is named
Removing things silently would be its own problem, since nobody could check
what went. Every stripped item is recorded on the report with the part it came
from, what it was, and how many: Comment (Collaboration) x3 in
word/comments.xml. It never holds the removed value, so the report can be
shared without shipping what it records. Items are named by what they are,
whatever the format: EXIF, a PDF’s /Info, an ID3 tag and an HTML <meta> field are
all Properties.
Refusals, and the less obvious consequences
Some files cannot be redacted safely, and the honest answer is to refuse them. An Office part whose content type Elide does not recognize refuses the file, as does XML in a vocabulary nobody has reviewed; nested inside another file, it is stripped and recorded instead, and the parent is still redacted. A PDF that needs a password is refused, because nothing in its ciphertext could be detected. And a decompression bomb fails the whole document, wherever it is nested: an Office part may inflate to at most 512 MiB, a package to 1 GiB.
Treating side text as content has effects that are easy to miss. A sheet name
is content, and Excel allows neither brackets nor more than 31 characters in
one, so [PERSON] becomes (PERSON), and a second sheet redacted the same way
becomes (PERSON) (2). A hyperlink to the renamed sheet follows it; a formula
that names it no longer resolves.
Some EXIF fields leak as a group. Clearing a latitude alone leaves the
hemisphere, the altitude and the GPS timestamp, so redacting a coordinate
clears the whole GPS block. Redacting any of Make, Model or SerialNumber
clears all three with the lens details, since one alone still narrows down the
camera.
What the record can prove
Every event on a trail is hashed with BLAKE3 over its parents’ hashes, its
source, timestamp, confidence and every field of its payload, a reviewer’s
attribution and a leak profile included. verify recomputes them all, rejects
a parent that does not come earlier and a duplicated event, and requires a
single tip, so an inserted, deleted or edited event shows up. It also rejects a
redaction that names no earlier selection, even when every hash is intact: a
redaction with no recorded decision behind it is exactly the claim without
evidence this design rules out. A report runs these checks on every trail as it
loads, and one that fails is refused.
A trail on its own cannot catch everything. Its hashes are not keyed, so
whoever rewrites a whole entity can recompute its trail. A trail cut back to
an earlier event is still intact on its own terms. And trails are per entity,
so dropping an entity outright, which would leave it unredacted, breaks no
other trail. report.digest() closes those gaps: one hash over every part,
every entity’s fields and every event of its trail, in order. Record it after
analysis, and again after a trusted review, somewhere the report’s carrier
cannot write, such as a signed log, a write-once bucket or a timestamping
service. Compare it before applying. Elide computes the digest; anchoring it
is the deployment’s job.
anonymize_with returns the applied report, with every redaction event on it.
Report is #[must_use], so discarding that record is a compiler warning.
Where the limits are
A PDF’s metadata and annotations are always stripped, whatever the policy,
because the rebuild cannot yet scan them in place
(#410). A PDF image the image
pipeline cannot read, such as fax or JBIG2 samples, is removed and recorded.
Metadata that cannot be surfaced field by field, such as XMP, IPTC or a
camera’s maker note, is stripped even under ScanAsContent. Each of these
costs something a caller might have wanted to keep, and each follows the rule
the rest of this post does: nothing ships that detection could not see.
Elide is a library: it builds the record and checks it, and storing it is up to the application. Within that, the record is specific: what was found and by what, what a named person changed and why, what was planned, which plan each redaction carried out, and what was stripped before any of it. The source is at nvisycom/elide, and the book’s chapters on review and hidden content cover the edge cases.
