Repository navigation
True Redaction
SIDHARTH SINGH edited this page Dec 3, 2026
·
1 revision
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.
- 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,',") andDoimage draw call. - Matches targets across three flexible inputs:
-
Built-in PII categories (
detect):aadhaar,pan,gstin(validated withisValidGstin()),phone,ifsc,email, and Luhn-checkedcreditCard. -
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).
-
Built-in PII categories (
- Surgically removes offending characters (splitting
TJarrays 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. - Scrubs
/Infoand/MetadatawhenscrubMetadata !== falseand draws isolatedq ... Qblack burn-in boxes. -
Fail-Closed Verification Pass: Re-extracts text from the final compacted PDF via
extractText()and fails withONEX_REDACTION_VERIFICATION_FAILEDif 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.
- Home
- Architecture & Render Pipeline
- PDF Internals & Extraction
- Unicode 16, Fonts & Legacy Indic
- Security & SSRF Model
- Digital Signing (
signPdf) - True Redaction (
redactPdf) - Semantic Diff & Redlines (
diffPdfs) - Self-Auditing Renders (
renderVerified) - PDF/A-3b & E-Invoices (
renderEInvoice) - HTTP, MCP, CLI & Puppeteer
Handbook & Deep Analysis: bahubalisid.github.io/onex