Skip to content

Web Lock Doesn't Truly Lock/Unload Database on Lock #10228

Description

@stevesbrain

What happened?

With an app lock configured, on the web or desktop, on first app load, everything is encrypted correctly. After you unlock the app, and the app re-locks, the connection to the database is not unloaded properly, and your notes can still be queried.

I would expect an app lock would truly lock + unload.

Steps to reproduce the problem

To verify on first load that notes are encrypted/nothing retrievable:

  1. Load up fresh/Ctrl+Shift+R a logged in session, with app lock enabled
  2. Open dev console of your browser and run:
(async () => {
  const dbs = await indexedDB.databases();
  console.log("IndexedDB databases present:", dbs.map(d => d.name));

  // Dump the KeyStore's own secret store — this is where `databaseKey`,
  // `userEncryptionKey`, and `lockAfter` are kept (apps/web/src/interfaces/key-store.ts).
  const req = indexedDB.open("KeyChain-secrets");
  req.onsuccess = () => {
    const db = req.result;
    const tx = db.transaction("secrets", "readonly");
    const getAll = tx.objectStore("secrets").getAll();
    const getKeys = tx.objectStore("secrets").getAllKeys();
    getAll.onsuccess = () => {
      getKeys.onsuccess = () => {
        getKeys.result.forEach((k, i) => {
          console.log(`secret "${k}":`, getAll.result[i]);
        });
      };
    };
  };
})();
  1. Result should be all unreadable bytes. Unlock, then go Dev Tools -> sources
  2. Open wa-sqlite-kysely-drivers.ts and set a breakpoint on line 315 (currently - it's the executeQuery function of WaSqliteWorkerConnection)
  3. Do something like open a note to trigger the breakpoint
  4. Go to scope panel -> right click on variable "this" and store it as a global variable - like "temp1" or similar
  5. Resume app + remove breakpoint if needed
  6. Lock app
  7. In the console, run: await temp1.worker.run("query", "select id, noteId, data, locked, dateEdited from content limit 5", [])
  8. See all your notes/attachments data returned

Version

3.4.5-b5140d9-web

Platform/OS

Chrome/Chromium

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions