From 57b543806c8a602a6d5d71360fc905619ea5b997 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Thu, 3 Sep 2026 23:19:31 +0200 Subject: [PATCH] fix: an opened file's password becomes the document's only once the file is loaded Declining to replace the current document, or an import that throws, left the foreign password on the document that stayed open, and an unprotected file kept the previous document's password. Both now travel with the load. --- src/App.svelte | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index ffd7837..b9e6b21 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -654,7 +654,7 @@ } // Ask until the password fits or the user gives up; null means give up. - async function unprotect(bytes: Uint8Array): Promise { + async function unprotect(bytes: Uint8Array): Promise<{ bytes: Uint8Array; password: string } | null> { for (;;) { const password = await new Promise((resolve) => { askResolve = resolve; @@ -663,9 +663,8 @@ if (password === null) return null; try { const plain = await decryptPackage(bytes, password); - docPassword = password; passwordWrong = false; - return plain; + return { bytes: plain, password }; } catch (err) { if ((err as Error)?.message !== WRONG_PASSWORD) throw err; passwordWrong = true; @@ -677,10 +676,11 @@ if (!editor) return; try { // Before anything reads the archive: an encrypted file is not one yet. + let password: string | null = null; if (isProtected(bytes)) { const opened = await unprotect(bytes); if (!opened) return; - bytes = opened; + ({ bytes, password } = opened); } const name = sourceName?.toLowerCase() ?? ''; let isDocx = name.endsWith('.docx') || name.endsWith('.dotx'); @@ -761,6 +761,9 @@ }; fileHandle = isTemplate ? null : handle; documentFormat = isDocx ? 'docx' : 'odt'; + // The file's password belongs to the document once it is actually the open one, + // and an unprotected file drops the previous document's. + docPassword = password; if (sourceName) recentFiles = await rememberRecentFile(sourceName, isTemplate ? null : handle); // Warn about fonts the document uses but the browser can't render, so text