Skip to content

True Redaction

SIDHARTH SINGH edited this page Dec 3, 2026 · 1 revision

True Content-Stream Redaction (redactPdf)

Drawing a solid black box over text inside a PDF does not remove the underlying text—any PDF reader copy-paste or automated scraper still extracts the secret text right out from underneath the rectangle.

How ONEX Redacts Safely

  1. Walks page content streams and nested Form XObjects using ONEX's matrix-aware tokenizer (extract/tables.ts) to resolve the real visual position and decoded characters of every text run (Tj, TJ, ', ") and Do image draw call.
  2. Matches targets across three flexible inputs:
    • Built-in PII categories (detect): aadhaar, pan, gstin (validated with isValidGstin()), phone, ifsc, email, and Luhn-checked creditCard.
    • Custom search (search): Exact strings or regular expressions.
    • Coordinates (regions): Explicit PDF { page, x, y, width, height } rectangles (removes both overlapping text and overlapping images).
  3. Surgically removes offending characters (splitting TJ arrays cleanly with spacing adjustment so surrounding safe text on the same line stays readable) and prunes dropped image XObjects from page resources plus optimization garbage collection so deleted images cannot be recovered from orphaned objects.
  4. Scrubs /Info and /Metadata when scrubMetadata !== false and draws isolated q ... Q black burn-in boxes.
  5. Fail-Closed Verification Pass: Re-extracts text from the final compacted PDF via extractText() and fails with ONEX_REDACTION_VERIFICATION_FAILED if any targeted match survived.
import { redactPdf } from 'onex-pdf';

const { bytes, report } = redactPdf(rawPdf, {
  detect: ['aadhaar', 'pan', 'gstin', 'phone'],
  search: ['CONFIDENTIAL-RATE-CARD'],
  burnIn: true,
  scrubMetadata: true,
});

On success, report.verified is true and report.leaks is empty. Like other destructive operations, redactPdf() refuses signed documents unless you explicitly opt in via allowModifySigned: true.

Clone this wiki locally