Sharing and cross-user isolation: audit + grill #409

Open
opened 2026-10-15 05:08:00 +00:00 by kayg · 4 comments
Owner

kayg, 2026-10-15 (on #312 V9): "we do need to grill sharing soon as protection against cross-user leaks would be huge and I think we started out designing the app with the multi-user protection in mind?"

What exists today, by design: ADR 0027 gives each user their own Home, plus a per-user index.db and history.db; only auth.db is shared. ADR 0011 has one action pipeline with a per-user change journal. ADR 0007 has every API change attacked. B6 dedupe is per user ("Already uploaded" only for your own files; cross-user disk dedupe was to be designed).

Before the grill:

  1. Audit: check the code against the per-user isolation promise. Every action and HTTP route is scoped to the session's user; IDs can't be guessed across users; there's no cross-user path in search, file serving, thumbnails, backdrops, history or websockets; caches are keyed by user; and dedupe doesn't reveal whether another user has a file (a timing or "already uploaded" oracle). Add an automated two-user leak test suite (user B tries every action and route on user A's ids) as a merge gate under ADR 0007.
  2. Draft the sharing grill: what can be shared (a note, a View, an attachment, a whole tag); with whom (another user on the server, or a public link); read or edit; live collaboration in the same room; revocation; how shares appear in the recipient's Home (a link? a mounted shared folder? "file over app"?); and the audit trail.
kayg, 2026-10-15 (on #312 V9): "we do need to grill sharing soon as protection against cross-user leaks would be huge and I think we started out designing the app with the multi-user protection in mind?" What exists today, by design: ADR 0027 gives each user their own Home, plus a per-user `index.db` and `history.db`; only `auth.db` is shared. ADR 0011 has one action pipeline with a per-user change journal. ADR 0007 has every API change attacked. B6 dedupe is per user ("Already uploaded" only for your own files; cross-user disk dedupe was to be designed). Before the grill: 1. **Audit:** check the code against the per-user isolation promise. Every action and HTTP route is scoped to the session's user; IDs can't be guessed across users; there's no cross-user path in search, file serving, thumbnails, backdrops, history or websockets; caches are keyed by user; and dedupe doesn't reveal whether *another* user has a file (a timing or "already uploaded" oracle). Add an automated two-user leak test suite (user B tries every action and route on user A's ids) as a merge gate under ADR 0007. 2. **Draft the sharing grill:** what can be shared (a note, a View, an attachment, a whole tag); with whom (another user on the server, or a public link); read or edit; live collaboration in the same room; revocation; how shares appear in the recipient's Home (a link? a mounted shared folder? "file over app"?); and the audit trail.
Author
Owner

kayg, 2026-10-15 (W22): agreed. 'Hidden' means decluttering, not protection, so the UI always says Hide, never Private or Lock. Truly protected notes (encrypted, unlocked with a passkey) are a separate feature, to be grilled alongside sharing in #409.

**kayg, 2026-10-15 (W22):** agreed. 'Hidden' means decluttering, not protection, so the UI always says Hide, never Private or Lock. Truly protected notes (encrypted, unlocked with a passkey) are a separate feature, to be grilled alongside sharing in #409.
Author
Owner

Audit: cross-user isolation (PR #419)

Checked: server routes and websocket, auth, notes, search, store, fsio, backdrops, daily, prefs, engine and live rooms. I found four real problems. Each is fixed in its own commit with a regression test, and I checked that each test fails without its fix.

Severe

F1 (critical): Trash ids could reach another person's Home. notes.restore and notes.forget built Trash/<id>.md straight from the client's id. An id like ../../<other user>/Notes/<name> reached outside your own Home. Restore moved that person's note (live or trashed) into your Notes, and forget deleted it. It also worked outside the data folder. Fix: every function in notes/src/trash.rs that turns an id into a path now checks it first, using the same rule as note ids. Test: trash_ids_never_reach_another_home.

F2 (high): a session cookie from another site's page was accepted. The API, the journal, the live websocket and backdrops relied only on SameSite=Lax. Lax still sends the cookie to requests from sibling hosts on the same site, such as the planned preview. and next.. A page there could open the live websocket, read everything and act as the person. Fix: a cookie only counts when the request has no Origin header or its Origin is this server's own. Bearer tokens are unaffected. This needs --origin to match the address people use; prod and e2e already do. Test: a_cookie_sent_from_another_sites_page_does_not_count.

Medium

F3: a refused account.revoke still signed someone out. Revoke marked the device id as revoked in memory before checking it belonged to the caller. So revoking someone else's device id answered "not found" but signed that device out until the next restart. Fix: the in-memory mark now happens only after the database confirms the device is the caller's.

Low

F4: another person could cancel your add-passkey prompt. passkey-add-finish removed the prompt before checking whose it was. Prompt ids are 128-bit random, so this is hard to exploit. Fix: only the owner can take the prompt.

Checked and clean

  • Every action resolves data through caller.user. The engine, notes Homes, list stores, search indexes, prefs, daily notes and backdrop uploads all key their caches and rooms by user, never by id alone. Rooms live inside each person's Home.
  • Sync tokens carry a random epoch for each person's journal, so another person's token gets the same "expired" answer as a made-up one.
  • Upload dedupe is per user (users/<id>/backdrops/<hash>). Nothing reveals that another person has a file, and there is no cross-user lookup that could leak through timing.
  • Error messages give no hint whether something exists for someone else. The suite checks this for every action.
  • The admin socket is a 0600 Unix socket that also checks the peer's uid; nothing admin is reachable over the network. The setup token works once, expires in 24 hours and is rate-limited.
  • Low-risk notes, no fix: the Unsplash cache and search cache are shared because they hold public content. Their speed shows whether someone fetched a given public photo recently. The open passkey-prompt table is shared and capped, so a signed-in person could fill it and slow down others' sign-ins for a few minutes.
  • No attachments exist yet besides backdrops. When cross-user disk dedupe arrives (B6), it must keep this suite passing.

Leak suite (merge gate, ADR 0007)

  • crates/calternal/src/isolation.rs: Alice seeds notes, a daily log, a tag job, prefs and search content, all carrying a marker. Bob runs every action from engine.actions() with Alice's ids, and again with a random id of the same shape. No answer may contain the marker, and the two runs must give the same kind of answer. New actions are covered automatically. A second test checks that Bob joining notes/<alice id> never loads her text.
  • crates/auth/tests/isolation.rs: two people with real passkey sessions. Covers devices, passkeys, add prompts and the cookie Origin check.
  • backdrops: two-user upload read, list and delete, plus per-user dedupe.
  • Results: fmt and clippy -D warnings clean; cargo test --workspace 412 passed, 0 failed.
  • Gap: routes outside the action pipeline (auth, backdrops) are covered by hand-written tests, because axum can't list its routes. A new HTTP route needs its own two-user test.
## Audit: cross-user isolation (PR #419) Checked: server routes and websocket, auth, notes, search, store, fsio, backdrops, daily, prefs, engine and live rooms. I found four real problems. Each is fixed in its own commit with a regression test, and I checked that each test fails without its fix. ### Severe **F1 (critical): Trash ids could reach another person's Home.** `notes.restore` and `notes.forget` built `Trash/<id>.md` straight from the client's id. An id like `../../<other user>/Notes/<name>` reached outside your own Home. Restore moved that person's note (live or trashed) into your Notes, and forget deleted it. It also worked outside the data folder. Fix: every function in `notes/src/trash.rs` that turns an id into a path now checks it first, using the same rule as note ids. Test: `trash_ids_never_reach_another_home`. **F2 (high): a session cookie from another site's page was accepted.** The API, the journal, the live websocket and backdrops relied only on `SameSite=Lax`. Lax still sends the cookie to requests from sibling hosts on the same site, such as the planned `preview.` and `next.`. A page there could open the live websocket, read everything and act as the person. Fix: a cookie only counts when the request has no `Origin` header or its `Origin` is this server's own. Bearer tokens are unaffected. This needs `--origin` to match the address people use; prod and e2e already do. Test: `a_cookie_sent_from_another_sites_page_does_not_count`. ### Medium **F3: a refused `account.revoke` still signed someone out.** Revoke marked the device id as revoked in memory before checking it belonged to the caller. So revoking someone else's device id answered "not found" but signed that device out until the next restart. Fix: the in-memory mark now happens only after the database confirms the device is the caller's. ### Low **F4: another person could cancel your add-passkey prompt.** `passkey-add-finish` removed the prompt before checking whose it was. Prompt ids are 128-bit random, so this is hard to exploit. Fix: only the owner can take the prompt. ### Checked and clean - Every action resolves data through `caller.user`. The engine, notes Homes, list stores, search indexes, prefs, daily notes and backdrop uploads all key their caches and rooms by user, never by id alone. Rooms live inside each person's Home. - Sync tokens carry a random epoch for each person's journal, so another person's token gets the same "expired" answer as a made-up one. - Upload dedupe is per user (`users/<id>/backdrops/<hash>`). Nothing reveals that another person has a file, and there is no cross-user lookup that could leak through timing. - Error messages give no hint whether something exists for someone else. The suite checks this for every action. - The admin socket is a 0600 Unix socket that also checks the peer's uid; nothing admin is reachable over the network. The setup token works once, expires in 24 hours and is rate-limited. - Low-risk notes, no fix: the Unsplash cache and search cache are shared because they hold public content. Their speed shows whether someone fetched a given public photo recently. The open passkey-prompt table is shared and capped, so a signed-in person could fill it and slow down others' sign-ins for a few minutes. - No attachments exist yet besides backdrops. When cross-user disk dedupe arrives (B6), it must keep this suite passing. ### Leak suite (merge gate, ADR 0007) - `crates/calternal/src/isolation.rs`: Alice seeds notes, a daily log, a tag job, prefs and search content, all carrying a marker. Bob runs **every action from `engine.actions()`** with Alice's ids, and again with a random id of the same shape. No answer may contain the marker, and the two runs must give the same kind of answer. New actions are covered automatically. A second test checks that Bob joining `notes/<alice id>` never loads her text. - `crates/auth/tests/isolation.rs`: two people with real passkey sessions. Covers devices, passkeys, add prompts and the cookie Origin check. - backdrops: two-user upload read, list and delete, plus per-user dedupe. - Results: fmt and clippy `-D warnings` clean; `cargo test --workspace` 412 passed, 0 failed. - Gap: routes outside the action pipeline (auth, backdrops) are covered by hand-written tests, because axum can't list its routes. A new HTTP route needs its own two-user test.
Author
Owner

Sharing grill (10 questions)

S1. What can be shared?
Recommended: a single note, and a View (a saved search/filter). Not a raw attachment on its own, not a whole tag, for v1.
Reason: a note is the one thing with a stable id, a room and history already; tags and whole-Home shares multiply the isolation surface we just audited.

S2. Who can it be shared with?
Recommended: another user on the same server by name, or an unguessable public read link; no "anyone who has the server URL" default.
Reason: both are first-class in ADR 0027's per-user model, and a capability-style link token keeps public sharing off the auth path entirely.

S3. Read or edit?
Recommended: per-share role, viewer or editor, defaulting to viewer; public links are viewer-only.
Reason: edit must flow through the same action pipeline and journal as the owner, so an editor is a real Caller with their own request ids; a public editor would be an unauthenticated writer, which we don't want.

S4. Live co-editing in the same room?
Recommended: yes for named editor shares — they join the note's existing notes/<id> room; public/viewer links get a read-only snapshot stream, not the room.
Reason: the room is already multi-writer; the only new rule is "may this Caller join", which belongs next to the per-user home() check, not in a second code path.

S5. How is a share authorized on every call?
Recommended: a shares table in the shared auth.db keyed by (owner, note_id, grantee|link_token, role); every note action and room join consults it when caller.user != owner.
Reason: isolation today is "resource is under users/<caller>"; sharing needs one explicit, audited exception point rather than per-action ad-hoc checks.

S6. Revoking access?
Recommended: owner revokes a grant or kills a link instantly; open rooms and live sockets for that grantee are dropped the same way a signed-out device is (the account.installation-revoked pattern).
Reason: we already have live revocation plumbing for sign-out; reuse it so a revoked share can't keep streaming.

S7. How do shares appear in the recipient's Home ("file over app")?
Recommended: a read-only "Shared with me" surface, not files mounted inside their Notes/; the shared note stays in the owner's Home and the recipient sees a reference.
Reason: file-over-app means each note lives as one file under exactly one owner; copying it into the grantee's folder would fork it and break the single-id/single-room promise.

S8. The audit trail?
Recommended: record share.granted, share.revoked, share.visited (link opened) and every shared edit's author in the owner's change journal; the grantee's edits are stamped with their own user id.
Reason: the journal is already per-owner and append-only; sharing just adds who-touched-what, which is exactly what an owner needs to trust a share.

S9. What do links inside a shared note expose?
Recommended: [[wikilinks]] to the owner's other notes render as plain text (no navigation, no preview) unless that target is itself shared with the same grantee; backlinks and unlinked-mentions panels are hidden for non-owners.
Reason: a shared note must not become a window into the rest of the owner's Home via link previews or the backlink graph.

S10. Attachments and search inside shares?
Recommended: attachments embedded in a shared note are served to the grantee through a scoped, per-share URL (not the owner's users/<owner>/... path); a grantee's global search never returns the owner's notes, and search within an open shared note is in-note only.
Reason: attachment serving and search are the two places this audit found keyed strictly by caller.user; a share must widen them by explicit grant only, one note at a time, never by making the owner's store searchable.

## Sharing grill (10 questions) **S1. What can be shared?** Recommended: a single note, and a View (a saved search/filter). Not a raw attachment on its own, not a whole tag, for v1. Reason: a note is the one thing with a stable id, a room and history already; tags and whole-Home shares multiply the isolation surface we just audited. **S2. Who can it be shared with?** Recommended: another user on the same server by name, or an unguessable public read link; no "anyone who has the server URL" default. Reason: both are first-class in ADR 0027's per-user model, and a capability-style link token keeps public sharing off the auth path entirely. **S3. Read or edit?** Recommended: per-share role, `viewer` or `editor`, defaulting to viewer; public links are viewer-only. Reason: edit must flow through the same action pipeline and journal as the owner, so an editor is a real Caller with their own request ids; a public editor would be an unauthenticated writer, which we don't want. **S4. Live co-editing in the same room?** Recommended: yes for named `editor` shares — they join the note's existing `notes/<id>` room; public/viewer links get a read-only snapshot stream, not the room. Reason: the room is already multi-writer; the only new rule is "may this Caller join", which belongs next to the per-user `home()` check, not in a second code path. **S5. How is a share authorized on every call?** Recommended: a `shares` table in the shared `auth.db` keyed by `(owner, note_id, grantee|link_token, role)`; every note action and room join consults it when `caller.user != owner`. Reason: isolation today is "resource is under `users/<caller>`"; sharing needs one explicit, audited exception point rather than per-action ad-hoc checks. **S6. Revoking access?** Recommended: owner revokes a grant or kills a link instantly; open rooms and live sockets for that grantee are dropped the same way a signed-out device is (the `account.installation-revoked` pattern). Reason: we already have live revocation plumbing for sign-out; reuse it so a revoked share can't keep streaming. **S7. How do shares appear in the recipient's Home ("file over app")?** Recommended: a read-only "Shared with me" surface, not files mounted inside their `Notes/`; the shared note stays in the owner's Home and the recipient sees a reference. Reason: file-over-app means each note lives as one file under exactly one owner; copying it into the grantee's folder would fork it and break the single-id/single-room promise. **S8. The audit trail?** Recommended: record `share.granted`, `share.revoked`, `share.visited` (link opened) and every shared edit's author in the owner's change journal; the grantee's edits are stamped with their own user id. Reason: the journal is already per-owner and append-only; sharing just adds who-touched-what, which is exactly what an owner needs to trust a share. **S9. What do links inside a shared note expose?** Recommended: `[[wikilinks]]` to the owner's other notes render as plain text (no navigation, no preview) unless that target is itself shared with the same grantee; backlinks and unlinked-mentions panels are hidden for non-owners. Reason: a shared note must not become a window into the rest of the owner's Home via link previews or the backlink graph. **S10. Attachments and search inside shares?** Recommended: attachments embedded in a shared note are served to the grantee through a scoped, per-share URL (not the owner's `users/<owner>/...` path); a grantee's global search never returns the owner's notes, and search within an open shared note is in-note only. Reason: attachment serving and search are the two places this audit found keyed strictly by `caller.user`; a share must widen them by explicit grant only, one note at a time, never by making the owner's store searchable.
Author
Owner

kayg's sharing answers (2026-10-16):

  • SH1: share notes and Views. Multi-select notes, then Share, automatically creates a View with those notes and shares it. This needs Views that hold hand-picked notes, as well as query-based ones (see #312).
  • SH2: Drive-style, multi-faceted grants. Anyone with the link can read or edit; named people on the server can read or edit. One share carries several grants. Every link has a QR view. Only admins can set custom links. Link shortening on separate domains comes later.
  • SH5: every share is easy to remove or change, and reachable from the search palette. Links can have names.
  • SH6, SH8, SH9: yes. SH10: Share sits left of ⋯ in the top-right pill group.
  • SH7: authorship lives in version history. Still open: whether to show link opens, and whether people editing through a link must give a name.
**kayg's sharing answers (2026-10-16):** - **SH1:** share notes and Views. Multi-select notes, then Share, automatically creates a View with those notes and shares it. This needs Views that hold hand-picked notes, as well as query-based ones (see #312). - **SH2:** Drive-style, multi-faceted grants. Anyone with the link can read or edit; named people on the server can read or edit. One share carries several grants. Every link has a QR view. Only admins can set custom links. Link shortening on separate domains comes later. - **SH5:** every share is easy to remove or change, and reachable from the search palette. Links can have names. - **SH6, SH8, SH9:** yes. SH10: Share sits left of ⋯ in the top-right pill group. - **SH7:** authorship lives in version history. Still open: whether to show link opens, and whether people editing through a link must give a name.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#409
No description provided.