fix(sharing): a shared note's history starts at the recipient's grant (privacy) #1039

Closed
kayg wants to merge 0 commits from fix/shared-history-after-grant into dev
Owner

Privacy fix. Someone a note was shared with could list every version of it through notes.history with owner_id, including the owner's drafts from before the share.

Fix

  • New NoteSharing::history_visible_from(caller, owner, note) returns None for the owner (all history), and for anyone else the moment their active grant began. That moment comes from the grant's own note_journal event (grant_start_seq → at_ms), in one indexed query. With no active grant it gives the same "not found" as every other sharing refusal. The default implementation allows only the owner.
  • Notes::history_authorized drops every history stretch that began before that moment (cut_before). A stretch spanning the grant is dropped too, because its summary covers earlier changes; this is the strict reading. Once an entry is too old the page loses its before link, so older pages can't be fetched.
  • The owner's history and the owner path are unchanged (no extra query for the owner). Old-version content isn't reachable by recipients at all: only notes.get and notes.history accept an owner reference (isolation::grants inventory test).

Tests

  • isolation::grants::shared_history_starts_at_the_grant: Alice writes a draft, then shares 20 ms later. Alice sees the draft's history; Bob's list holds no entry that began before the grant and has no older link.
  • ops::cut_tests (3): entries after the grant are kept, a spanning stretch is hidden, and a page fully after the grant keeps its older link.

Gates (head ce81c98aa)

gate result
cargo fmt --check / clippy -D warnings clean / clean
cargo test -p calternal-core -p calternal-auth -p calternal-notes -p calternal 897 passed, 0 failed
admin-sharing.spec --repeat-each=2 (it checks the history list after an edit) admin-chromium-1440 9 · admin-chromium-390 9 · admin-webkit-1440 9 · admin-webkit-390 9 passed
first paint no web change
perf owner notes.history path unchanged (returns before the new query); recipients pay one indexed auth.db read per history page. Not a hot path in the harness

🤖 Generated with Claude Code

**Privacy fix.** Someone a note was shared with could list *every* version of it through `notes.history` with `owner_id`, including the owner's drafts from before the share. ## Fix - New `NoteSharing::history_visible_from(caller, owner, note)` returns `None` for the owner (all history), and for anyone else the moment their **active** grant began. That moment comes from the grant's own `note_journal` event (`grant_start_seq` → `at_ms`), in one indexed query. With no active grant it gives the same "not found" as every other sharing refusal. The default implementation allows only the owner. - `Notes::history_authorized` drops every history stretch that **began** before that moment (`cut_before`). A stretch spanning the grant is dropped too, because its summary covers earlier changes; this is the strict reading. Once an entry is too old the page loses its `before` link, so older pages can't be fetched. - The owner's history and the owner path are unchanged (no extra query for the owner). Old-version *content* isn't reachable by recipients at all: only `notes.get` and `notes.history` accept an owner reference (`isolation::grants` inventory test). ## Tests - `isolation::grants::shared_history_starts_at_the_grant`: Alice writes a draft, then shares 20 ms later. Alice sees the draft's history; Bob's list holds no entry that began before the grant and has no older link. - `ops::cut_tests` (3): entries after the grant are kept, a spanning stretch is hidden, and a page fully after the grant keeps its older link. ## Gates (head `ce81c98aa`) | gate | result | |---|---| | `cargo fmt --check` / clippy `-D warnings` | clean / clean | | `cargo test -p calternal-core -p calternal-auth -p calternal-notes -p calternal` | 897 passed, 0 failed | | `admin-sharing.spec --repeat-each=2` (it checks the history list after an edit) | admin-chromium-1440 9 · admin-chromium-390 9 · admin-webkit-1440 9 · admin-webkit-390 9 passed | | first paint | no web change | | perf | owner `notes.history` path unchanged (returns before the new query); recipients pay one indexed auth.db read per history page. Not a hot path in the harness | 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A person a note is shared with could list every version of it, including
the owner's drafts from before the share. history_authorized now asks the
sharing service when the caller's active grant began (the grant's own
journal event) and drops every history stretch that began earlier; a
stretch spanning the grant is dropped too, and the page loses its older
link. The owner still sees everything. New NoteSharing method
history_visible_from (default: owner only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
style: rustfmt
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled
ce81c98aa3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Merged into dev locally (head ce81c98aa is in origin/dev); closing.

Merged into dev locally (head `ce81c98aa` is in origin/dev); closing.
kayg closed this pull request 2026-11-09 18:55:14 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
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!1039
No description provided.