Skip to content

fix(pdf): accept owner-password PDFs that open with an empty user password (Fixes #3303) - #3350

Open
ssmurfgg04-gif wants to merge 1 commit into
documenso:mainfrom
ssmurfgg04-gif:fix/owner-password-pdfs
Open

ssmurfgg04-gif wants to merge 1 commit into
documenso:mainfrom
ssmurfgg04-gif:fix/owner-password-pdfs

Conversation

@ssmurfgg04-gif

Copy link
Copy Markdown

Fixes #3303.

What changed

normalizePdf no longer rejects every PDF that carries an encryption dictionary. It now separates the two cases the old blanket isEncrypted check lumped together:

  1. Document opened with an empty user password (owner-password protection, the common government-form case). The pages get rebuilt into a fresh document via extractPages, which drops the encryption dictionary without needing owner access, and normalization continues. This is the approach verified in the issue; PDF.merge and removeProtection() were ruled out there already.
  2. Document did not authenticate (a real user password). Rejected with a message that says the file is password protected, instead of the generic "The document is encrypted" both cases used to share (Show error message about encrypted PDFs #1371 asked for exactly this).

The rebuild does not carry the AcroForm over, so case 1 is gated on shouldFlattenForm. Today flattenForm: false is only the TEMPLATE path (create-envelope-items), so every signing path gets the fix and templates keep refusing rather than silently losing fields. If #2853 lands and a path stops flattening, that gate should follow it.

Also switched pdfDoc from const to let for the reassignment.

Verification

I reproduced the whole thing locally against @libpdf/core 0.4.2 (the version pinned in package.json) with qpdf-built fixtures:

  • Owner-password PDF (AES-256, empty user password, permissions-only): loads, isEncrypted=true, isAuthenticated=true, rebuild produces a file that reloads with isEncrypted=false, page content intact.
  • Unencrypted PDF: identical output to before, no behavior change.
  • Same owner-password PDF with flattenForm: false: throws the new "would discard its form fields" message.
  • User-password PDF: on 0.4.2 PDF.load itself throws before my branch is reached, so it keeps the existing "not a valid PDF" error. The isAuthenticated backstop is there for paths and versions where load succeeds unauthenticated, which the issue observed on 0.4.0.

One follow-up worth tracking, noticed while testing: for a genuinely locked file, libpdf 0.4.2 surfaces a misleading parse error ("Root Pages object is not a dictionary") rather than anything password-related, so the load-failure catch cannot reliably tell corruption from a password prompt. That is a @libpdf/core issue more than a Documenso one.

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
prd-docs Ignored Ignored Sep 8, 2026 5:43pm UTC
prd-openpage-api Ignored Ignored Sep 8, 2026 5:43pm UTC
stg-docs Skipped Skipped Sep 8, 2026 5:43pm UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – stg-docs September 8, 2026 17:43 Inactive
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • coderabbit

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: d4e91100-fea5-4a27-9469-14f77e5baec7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Mythie

Mythie commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Hey there, it looks like you haven't accepted our contributor license agreement yet. In order for us to accept your pull request we ask that you please fill out the CLA:

https://documen.so/cla

@ssmurfgg04-gif

Copy link
Copy Markdown
Author

Signed the CLA just now, the check should clear shortly. Thanks for the pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

normalizePdf rejects owner-password PDFs it can already open, blocking government forms

2 participants