feat: scrub PDF metadata after redaction - #11
Open
federicodeponte wants to merge 1 commit into
Open
Conversation
Add scrubMetadata() helper that clears all standard info dictionary fields (Title, Author, Subject, Keywords, Creator, Producer, CreationDate, ModDate) and removes XMP metadata from the PDF catalog. Called in both applyRedactions and applyPseudonymisation right before saveToBuffer, so redacted documents no longer leak identifying metadata. Closes Siddharth-Khattar#4 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scrubMetadata()helper infrontend/src/engine/pdf.tsthat clears all standard PDF info dictionary fields (Title, Author, Subject, Keywords, Creator, Producer, CreationDate, ModDate) using MuPDF'sDocument.setMetaData()APIMetadatastream from the PDF catalog viaPDFDocument.getTrailer()low-level accessscrubMetadata()in bothapplyRedactionsandapplyPseudonymisationright beforesaveToBuffer, ensuring all redacted output is metadata-cleanCloses #4
Implementation details
MuPDF's WASM TypeScript bindings expose:
Document.setMetaData(key, value)for clearing info dictionary entriesPDFDocument.getTrailer()andPDFObject.delete()for removing the XMP metadata stream from the catalogBoth operations are wrapped in try/catch for graceful degradation if specific keys or low-level operations are unsupported in a given MuPDF build.
Test plan
pdfinfoor a PDF metadata viewertsc --noEmit(verified locally)