Skip to content

Open PDFs locked with a password - #414

Merged
Joost-8 merged 9 commits into
mainfrom
feat-pdf-password
Dec 4, 2026
Merged

Joost-8 merged 9 commits into
mainfrom
feat-pdf-password

Conversation

@Joost-8

@Joost-8 Joost-8 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

What changed and why

PDFs that ask for a password when opened (university handouts, for example) could not be opened in FineNotes: no PDF opening ever gave pdf.js a password, so it refused with "No password given". Now every PDF opening, on the main thread and in the PDF worker, goes through one opener. It first tries the passwords that opened a PDF before, then asks once with a small dialog titled with the file's name. The password that works is kept in Obsidian's keychain on this device. Only the notebook itself asks. Home covers, page embeds, the Companion PDF, the template list and background reads (search text, OCR, the outline) use kept passwords and never show the dialog. After Cancel, a tap on the locked page (a right-click on desktop) asks again, and making a notebook from the PDF always asks. Export, Ask AI's PDF and the Companion PDF draw a locked source's pages as pictures: pdf-lib cannot copy an encrypted page. The PDF on disk stays locked.

Proof

  • Reproduced first: a PDF locked with AES-256 (pikepdf, user password), opened with Obsidian's own pdf.js 5.3.34 in Node, failed with PasswordException 1 No password given. A PDF with only an owner password (printing and copying blocked) already opened.
  • Same PDF through the new opener, real pdf.js: a wrong then the right password opens it; the kept password opens it again under another name; the owner-only PDF opens unchanged; cancelling, or a background read, rejects with PdfLocked.
  • Real Obsidian 1.15.1 (rig):
    • Making a notebook from the locked PDF asks; "Wrong password" shows after a wrong one, and the right one opens the notebook with the PDF's pages.
    • A second PDF with the same password opens with no dialog.
    • After the keychain is emptied, reopening the notebook asks with the file's name; Cancel leaves "Locked PDF — name" on the page and nothing asks again.
    • The worker's round trip, driven directly: a kept password opens the PDF silently, a background open without one is PdfLocked with no dialog, and an interactive open asks, flags a wrong password and keeps the right one.
    • Export (Save page as template runs the same exporter) wrote an unencrypted one-page PDF with the lecture page drawn as a picture.
    • With no kept password, Home opened with blank covers and no dialog.
    • Tap to ask again: after Cancel, a finger tap (CDP touch) on the "Locked PDF — name" page showed the dialog; the password drew the page and was kept. A right-click did the same, with no press menu. Making the notebook again after a Cancel asked again (before the fix it failed silently until a notebook was opened).
  • Reviewer agent: two rounds, all findings fixed.
    1. Export of a locked-PDF notebook failed with pdf-lib's English error (reproduced with the repo's pdf-lib).
    2. Covers, embeds and the template list could ask.
    3. Imports from the device showed a nameless dialog.
    4. (Tap round) a PDF unlocked by another notebook's dialog kept its locked mark, so a tap dropped its rasters instead of following a link.
    5. (Tap round) a render still reading the file when the page was tapped could store its locked answer over the fresh read. forget now cancels the path's running renders, which also covers a PDF replaced on disk.
  • Tests:
    • tests/view/pdf-password-book.test.ts (11).
    • tests/view/pdf-password.test.ts (8, pdf.js's onPassword protocol played by a fake). They include three openings of one PDF at once asking only once, which failed before the fix to the dialog's turn.
    • pdf-composer.test.ts: "names a PDF locked with a password…", on a real AES-256 fixture.
    • pdf-backdrop.test.ts: the locked mark until forgotten; cleared when the worker unlocks it later; a forgotten PDF's running render stores nothing. The last two fail without their fixes.
    • pdf-password.test.ts: "asks again for one declined PDF only".
  • Screens: review page https://claude.ai/artifact/Ftbpvx4vBVvopnGm5gzrc1 (rig shots, and gallery scenes dialog-pdf-password and dialog-pdf-password-wrong in light and dark).
  • npm run gates: all 11 steps pass. check.mjs --changed ran every scene (shared files changed). Its 7 finding groups are the ones the nightly already reports on main (settings-advanced and 6 ellipsis groups); none are in the new dialog.

Test on the device

  1. Put a PDF that asks for a password when opened into the vault and make a notebook from it. A dialog with the file's name asks for the password. Type a wrong one first ("Wrong password" in red), then the right one: the notebook opens with the PDF's pages.
  2. Make a notebook from a second PDF with the same password: it opens without asking.
  3. Close and reopen the first notebook: no dialog, and the PDF's pages show. Write on a page and Export it as PDF: the export opens, with your ink over the page. (On a device that has not kept the password yet, Cancel the dialog, then tap the "Locked PDF" page with a finger: it asks again.)

Not verified

🤖 Generated with Claude Code

Joost-8 and others added 9 commits December 3, 2026 13:02
Every PDF open (this thread and the PDF worker) goes through one opener
that tries the passwords that opened a PDF before, then asks once, and
keeps the one that worked in Obsidian's keychain on this device.
Background reads never ask. The PDF on disk stays locked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Export, Ask AI's PDF and the Companion PDF: pdf-lib cannot read an
  encrypted source, so such a page is drawn as a picture through pdf.js.
- Only the notebook view's PDF cache may show the dialog; Home covers,
  embeds, previews, the Companion and the template list never ask.
- Imports from the device name the file in the dialog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After Cancel, a finger tap (or a right-click) on a page whose PDF stayed
locked asks for the password again and draws the page afresh. Making a
notebook from a PDF asks again even if its dialog was cancelled before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nder cannot store its old answer

Found by the reviewer agent: a PDF unlocked by another notebook's dialog
kept its locked mark, so a tap dropped its rasters instead of following a
link; and a render still reading the file when the page was tapped stored
its locked answer over the fresh read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/i18n/en/surface.ts
#	src/view/pdf-backdrop.ts
…iew only wires it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joost-8
Joost-8 marked this pull request as ready for review December 4, 2026 02:05
@Joost-8
Joost-8 merged commit c42f168 into main Dec 4, 2026
1 check passed
@Joost-8
Joost-8 deleted the feat-pdf-password branch December 4, 2026 02:05
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.

1 participant