Repository navigation
Fix PDF unlock failing for RC4 files that deny accessibility - #4
Merged
Merged
Conversation
Removing only the open password re-encrypts with AES-256 and then verifies that every denied permission is still denied. R2/R3 (RC4) files can deny the accessibility permission; PDF 2.0 deprecates that bit and qpdf neither writes nor reports it for R >= 4. The verification therefore always failed and the user saw "file is corrupt or could not be read". The policy now ignores the accessibility permission when deciding whether a file has restrictions and when verifying the re-encrypted copy. All other restrictions are still preserved and verified. Adds R3 (accessibility denied) and R2 fixtures with regression tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DBSwp8dMkpVxCSR4ArHAU5
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.
Problem
Unlocking certain PDFs with the correct open password failed with "Die Datei ist beschädigt oder konnte nicht gelesen werden." (
corrupt, internally:re-encryption could not be verified).Affected: PDFs with RC4 encryption (R2/R3) that have an open password plus permission restrictions, where the accessibility permission ("text access for screen readers") is denied. For R2 this is every file that denies copying, because R2 ties accessibility to the extract bit.
Root cause
Without the owner password,
unlockPdfre-encrypts with AES-256 (R6) and then verifies that every permission denied in the original is still denied (restrictionsPreserved). PDF 2.0 deprecates the accessibility bit and requires readers to ignore it. qpdf 12 therefore ignores--accessibility=nfor current encryption formats and always reportsaccessibility: truefor R ≥ 4 (qpdf --help=--accessibility: "ignored except with very old encryption formats"). The verification compared a permission that the target format cannot express, so it could never succeed.A matrix of R2/R3/R4/R4-AES/R6 files × every single permission denied, plus a large file with object streams, reproduced the failure in exactly four cases. All four had accessibility denied on R2/R3.
Fix
web/src/core/pdf/policy.ts:hasRestrictionsandrestrictionsPreservednow consider only enforceable permissions and leave outaccessibility. Every other denied permission is still carried over and verified after re-encryption. A file whose only restriction is accessibility is now fully decrypted, which matches how PDF 2.0 readers treat it anyway.Considered instead: re-encrypt R2/R3 inputs as RC4-128 (R3), which could keep the bit. Not chosen: it needs qpdf's
--allow-weak-crypto, and it would keep a permission the current spec tells readers to ignore.Tests
restricted-rc4-noaccess.pdf(R3, accessibility denied) andrestricted-rc4-40.pdf(R2), generated withscripts/gen-fixtures.py.pdf.test.tsand policy table tests inpdf-policy.test.ts. All four fail without the fix and pass with it.vitest,tsc --noEmit,eslint/prettierpass. Docs drift check: no drift.Documentation
README (PDF permissions),
docs/SECURITY.md(anti-misuse table) and the fixtures README describe the accessibility exception. No legal texts changed.🤖 Generated with Claude Code
https://claude.ai/code/session_01DBSwp8dMkpVxCSR4ArHAU5
Generated by Claude Code