DEV Community

Cover image for Why Drawing Black Boxes Over a PDF Leaks Sensitive Text (and How Offline Pixel Burn-In + Re-OCR Audit Solves It)
Lukas
Lukas

Posted on Edited on Originally published at lukaslabs.top

Why Drawing Black Boxes Over a PDF Leaks Sensitive Text (and How Offline Pixel Burn-In + Re-OCR Audit Solves It)

High-profile court filings and FOIA releases still fail every year for the same reason: someone opened a PDF editor, drew opaque black rectangles over names or SSNs, saved the file, and emailed it out.

Anyone who presses Ctrl+A and Ctrl+C (or runs pdftotext) still extracts every word underneath those boxes — along with Author, Creator, XMP history, and annotation layers.

What forensic-grade offline redaction actually requires

  1. True pixel burn-in (150–300 DPI): Render each page onto an HTML5 Canvas, paint solid black over the selected bounding boxes so the original glyphs never exist in the pixel buffer, and rebuild a clean PDF from the flattened raster pages.
  2. Metadata & EXIF stripping: Clear Info dictionary entries (Author, Title, Creator, Producer), drop XMP streams, AcroForm fields, bookmarks, and annotations — and strip EXIF GPS/device headers when importing scanned photos (PNG/JPG/WebP).
  3. Automated second-pass + Re-OCR verification: Re-open the generated PDF bytes in a fresh parser pass (VERIFIED · 0 Leaked Text) and run Re-OCR Verify Output using self-hosted in-browser LSTM WASM OCR (tesseract.js + same-origin eng.traineddata.gz) to prove zero sensitive targets survive even in the flattened pixels.

Try it offline in your browser (zero uploads)

(Disclosure: Built independently at Lukas Labs.)


Update (2026-12-03): Raw Byte / Hex Stream & Incremental %%EOF Revision Verification

Great point from @kamalmosadegh in the comments below: auditing the finished output bytes directly (not just trusting the rasterization pipeline) catches incremental-update tails and hex-encoded PDF strings that a simple text-layer check can miss.

We just shipped two updates based directly on that feedback:

  1. Upgraded VeilPress's local post-redaction verifier to also grep raw output PDF bytes and inflated FlateDecode streams (plain ASCII, PDF <hex>, and UTF-16BE hex), verify exactly 1 %%EOF revision trailer (proving zero incremental-update tail survived), and assert 0 selectable text chars on full-raster rebuilds.
  2. Open-sourced a standalone MIT PDF Redaction Leak Checker (zero-dependency browser tool + Python 3 CLI audit_pdf_redaction.py for CI/terminal verification):

Top comments (7)

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

Good write-up — the failure mode is real, and burn-in plus re-OCR is the right shape. One check I'd add before calling a file clean: verify the output file itself, not just the process. Grep the raw bytes of the finished PDF for the redacted string — and in hex form too, since PDF strings can be hex-encoded — after expanding it with qpdf --qdf, and check every revision, not just the latest one. An incremental-update tail can keep the original text alive in an older revision even when the current one is clean, and that's the leak a 'verify the pixels' pass never sees, because the pixels were never the problem — the file was. A second, cheaper gate: pdftotext on the output should return nothing at all. If any text survives a raster rebuild, the raster path leaked somewhere.

Collapse
 
lukaslabs profile image
Lukas •

Spot on — thank you for calling that out. We actually shipped your exact checks in VeilPress v1.1.1 this morning:

  1. Raw output-file audit (not just process audit): decompresses every FlateDecode stream in the finished output bytes and greps both raw and inflated streams for redacted tokens across ASCII, PDF <hex> strings, and UTF-16BE hex.
  2. Revision / incremental-update gate: counts %%EOF trailers in the final bytes and fails verification if more than 1 exists (so older incremental revisions can't keep pre-redaction text alive).
  3. Standalone MIT verifier: we also split out the browser + zero-dependency Python 3 CLI checker (audit_pdf_redaction.py, works standalone or alongside qpdf --qdf) so anyone can run the byte/hex/%%EOF audit independently: github.com/oneguo-boop/pdf-redacti...

Really appreciate the review — that revision + hex-string edge case is exactly the kind of blind spot that makes "trust the UI" redaction dangerous.

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

That's exactly the right shape — and the UTF-16BE hex coverage is the part most tools skip, so good catch there. One gap worth testing: a token split across hex-string segments, or rendered through a subset font with a custom encoding, won't match a hex grep even after inflation — that's the case the pdftotext-empty gate was for. Do you run that gate too, or does the FlateDecode audit cover it in practice?

Thread Thread
 
lukaslabs profile image
Lukas •

Yes — VeilPress runs that exact zero-text-layer gate too:

  • In VeilPress (runForensicAudit): Right after rebuilding the finished PDF from burned raster pages into a fresh PDFDocument.create(), it re-opens the output bytes with pdfjs-dist (page.getTextContent()), which resolves subset fonts, custom encodings, ToUnicode CMaps, and split TJ runs — the browser equivalent of pdftotext. In default full-document raster mode, outputTextChars === 0 is a hard pass gate (passed fails if any selectable text survives, even if a raw/hex grep missed it). In redacted-only mode, redacted pages are rebuilt strictly as image-only pages while pdfjs-dist text extraction checks all redacted targets (plus whitespace/hyphen-compacted forms) alongside the FlateDecode byte grep.
  • Honest caveat on the standalone stdlib-only CLI (audit_pdf_redaction.py): Because it intentionally has zero poppler/pdfium dependencies, it scans raw/inflated Tj/TJ operators rather than decoding custom font CMaps. On a fully rasterized file, extracted_text_chars == 0 still catches surviving text operators, but for arbitrary third-party PDFs with custom subset-font encodings, pairing it with pdftotext out.pdf - (must be empty) is definitely still the cleanest independent double-check.

Thanks again for calling out the split-hex / custom-encoding case — keeping the boundary clear between CMap-decoded text extraction and raw stream greps is huge.

Thread Thread
 
Sloan, the sloth mascot
Comment deleted
 
kamalmosadegh profile image
Kamal Mosadegh •

Thanks — that's the boundary stated exactly right. The pdfjs-dist gate is the CMap-decoded layer, and the stdlib CLI's raw-stream grep is the other layer; neither replaces the other. The pdftotext-empty check is the cleanest independent double-check for the CLI case — worth documenting as the required second check rather than an optional one, since that's what catches the custom-encoding file the grep can't see.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

That's exactly the boundary I was hoping for — CMap-decoded extraction as the gate, raw stream grep as the fallback, never the other way round. And the honest caveat on the stdlib CLI is the part that matters most: it knows it can't decode custom encodings, so it doesn't pretend a hex grep is a verdict. pdftotext empty as the independent double-check is the right call — two different mechanisms agreeing is what turns 'clean' from a hope into a claim.