Skip to content

Fix PDF unlock failing for RC4 files that deny accessibility - #4

Merged
t11z merged 1 commit into
mainfrom
claude/loving-rubin-v3a5ho
Oct 7, 2026
Merged

t11z merged 1 commit into
mainfrom
claude/loving-rubin-v3a5ho

Conversation

@t11z

@t11z t11z commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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, unlockPdf re-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=n for current encryption formats and always reports accessibility: true for 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: hasRestrictions and restrictionsPreserved now consider only enforceable permissions and leave out accessibility. 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

  • New fixtures restricted-rc4-noaccess.pdf (R3, accessibility denied) and restricted-rc4-40.pdf (R2), generated with scripts/gen-fixtures.py.
  • New integration tests in pdf.test.ts and policy table tests in pdf-policy.test.ts. All four fail without the fix and pass with it.
  • vitest, tsc --noEmit, eslint/prettier pass. 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

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
@t11z t11z self-assigned this Oct 7, 2026
@t11z t11z added the enhancement New feature or request label Oct 7, 2026
@t11z
t11z merged commit 004bd14 into main Oct 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants