Version restore checks /home/<username>/ while paths are /home/... (latent bug) #902

Closed
opened 2026-10-15 02:18:25 +00:00 by Cordy · 3 comments
Owner

Found during the #897 code research (2026-10-14). Not fixed in #897.

internal/api/versions.go (~89-123): versionRestore requires the path to start with /home/<username>/, but the virtual paths users send are /home/.... This looks like the restore of a personal file's older version can never match. No test covers it.

To do: reproduce with a test through the real stack (scope + versions), fix the prefix check, check the space path variant, live-check on a dogfood.

Found during the #897 code research (2026-10-14). Not fixed in #897. `internal/api/versions.go` (~89-123): `versionRestore` requires the path to start with `/home/<username>/`, but the virtual paths users send are `/home/...`. This looks like the restore of a personal file's older version can never match. No test covers it. To do: reproduce with a test through the real stack (scope + versions), fix the prefix check, check the space path variant, live-check on a dogfood.
Author
Owner

Research (2026-10-15)

Full file: cairn-work/scratch/b7e/batch907/902-research.md. Confirmed with a throwaway Go test against the real storage stack.

Worse than reported. On every default deployment (per-user homes on), version restore has never worked for personal files since versioning shipped (858e86ca, v0.6.223):

  • List is always empty ("No previous versions"), so the Restore button never shows.
  • Restore for space files is also always 403, even though the button shows for writers.
  • Space files after a rename or via an alias: the list is empty.
  • Download works.
  • Wrong-file write: with a folder named after the user inside their home, a restore overwrites the wrong file and answers 200.

Root cause: the browser sends /home/a.txt, while the versions engine reads the raw backend (/home/anna/a.txt).

  • List: internal/api/versions.go:66 and versions/versions.go:201 look in the wrong place.
  • Restore: the /home/<username>/ check at versions.go:110 never matches.
  • Download is the only endpoint that maps the path.
  • Tests: only the engine is tested, with backend paths; there is no API or scope-level test.
  • Docs: admin-policy.md:211 and file-browser.md:110 claim restore works.

Restore also bypasses locks, quota and max size, the change journal (sync clients miss it) and the audit layer, and it allows a restore under a legal hold.

Market:

  • Nextcloud: rollback needs write permission, saves the current file as a version first and locks it.
  • Known holes elsewhere: read-only users could restore (Nextcloud CVE-2024-37315, ownCloud CVE-2016-9462).

Recommended fix (size S, about 4-6 h plus a live check):

  1. Map paths: map the browser path to the backend path with Resolve for list and restore.
  2. Restore as a normal write: open the version through the scoped store and write it over the file, so roles, device limits, holds, locks, quota, journal, audit and activity all apply. Tried in /tmp: it works for personal and space files and refuses read-only members.
  3. Keep every restore undoable:
    • fail the restore if saving the current content as a version fails;
    • stop editor autosaves within the 10-minute merge window from replacing the pre-restore version.
  4. Record it once: one audit and one activity event with a distinct version-restore verb.
  5. Update docs.

Decisions (my recommendation in brackets):

  • D1 Who may restore [anyone who can edit the file: personal files and space writers].
  • D2 Restore under legal hold [refused, like every other overwrite].
  • D3 How restore writes [through the normal store].
  • D4 Error messages [specific texts for read-only, held, locked and over quota].
  • D5 Activity label ["version restored"].

Mockup: none (strings only). Side finding, not #902: old versions are pruned with no check of the deletion retention window (#63).

## Research (2026-10-15) Full file: `cairn-work/scratch/b7e/batch907/902-research.md`. Confirmed with a throwaway Go test against the real storage stack. **Worse than reported.** On every default deployment (per-user homes on), version restore has never worked for personal files since versioning shipped (858e86ca, v0.6.223): - **List** is always empty ("No previous versions"), so the Restore button never shows. - **Restore** for space files is also always 403, even though the button shows for writers. - **Space files after a rename or via an alias:** the list is empty. - **Download** works. - **Wrong-file write:** with a folder named after the user inside their home, a restore overwrites the wrong file and answers 200. **Root cause:** the browser sends `/home/a.txt`, while the versions engine reads the raw backend (`/home/anna/a.txt`). - **List:** `internal/api/versions.go:66` and `versions/versions.go:201` look in the wrong place. - **Restore:** the `/home/<username>/` check at `versions.go:110` never matches. - **Download** is the only endpoint that maps the path. - **Tests:** only the engine is tested, with backend paths; there is no API or scope-level test. - **Docs:** admin-policy.md:211 and file-browser.md:110 claim restore works. **Restore also bypasses** locks, quota and max size, the change journal (sync clients miss it) and the audit layer, and it allows a restore under a legal hold. **Market:** - **Nextcloud:** rollback needs write permission, saves the current file as a version first and locks it. - **Known holes elsewhere:** read-only users could restore (Nextcloud CVE-2024-37315, ownCloud CVE-2016-9462). **Recommended fix** (size S, about 4-6 h plus a live check): 1. **Map paths:** map the browser path to the backend path with `Resolve` for list and restore. 2. **Restore as a normal write:** open the version through the scoped store and write it over the file, so roles, device limits, holds, locks, quota, journal, audit and activity all apply. Tried in /tmp: it works for personal and space files and refuses read-only members. 3. **Keep every restore undoable:** - fail the restore if saving the current content as a version fails; - stop editor autosaves within the 10-minute merge window from replacing the pre-restore version. 4. **Record it once:** one audit and one activity event with a distinct `version-restore` verb. 5. **Update docs.** **Decisions** (my recommendation in brackets): - D1 Who may restore [anyone who can edit the file: personal files and space writers]. - D2 Restore under legal hold [refused, like every other overwrite]. - D3 How restore writes [through the normal store]. - D4 Error messages [specific texts for read-only, held, locked and over quota]. - D5 Activity label ["version restored"]. Mockup: none (strings only). Side finding, not #902: old versions are pruned with no check of the deletion retention window (#63).
Author
Owner

Decisions (Nikola, 2026-10-15): all recommendations accepted (comment 9162): D1 anyone who can edit the file, D2 refused under legal hold, D3 restore as a normal write through the scoped store, D4 specific messages, D5 "version restored" activity label. Built in batch A.

**Decisions (Nikola, 2026-10-15): all recommendations accepted** (comment 9162): D1 anyone who can edit the file, D2 refused under legal hold, D3 restore as a normal write through the scoped store, D4 specific messages, D5 "version restored" activity label. Built in batch A.
Cordy closed this issue 2026-10-15 16:08:14 +00:00
Author
Owner

Shipped in v0.6.343 (PR #910), follow-up fixes in v0.6.344 (PR #912). Both dogfoods run v0.6.344.

Restore now goes through the scoped store, so the hold, lock, quota, the version mint, audit, activity and the change journal all apply. List and restore work for:

  • personal files;
  • spaces you can write to;
  • renamed and aliased spaces;
  • flat mode.

The Versions panel shows a specific message for each refusal. /shared/... still answers 404.

Tests: TestVersionRestoreMatrix, on posix and s3, with and without encryption. It covers homonym folders, autosave-marked ids, aliased spaces, and exactly one audit, activity and journal entry per restore.

Live check (local instance, v0.6.343): all PASS.

  • Restoring the oldest version answers 200, restores the content, and the version list grows by one.
  • anna can restore in a space.
  • bob (read-only member) gets 403 read-only.
  • A held file gets 403 legal-hold; a locked file gets 423 locked.
  • One audit version-restore and one Activity "version restored".

Closing. The browser click-through on the dogfoods is part of the batch A dogfood check with Nikola.

## Shipped in v0.6.343 (PR #910), follow-up fixes in v0.6.344 (PR #912). Both dogfoods run v0.6.344. Restore now goes through the scoped store, so the hold, lock, quota, the version mint, audit, activity and the change journal all apply. List and restore work for: - personal files; - spaces you can write to; - renamed and aliased spaces; - flat mode. The Versions panel shows a specific message for each refusal. `/shared/...` still answers 404. **Tests:** `TestVersionRestoreMatrix`, on posix and s3, with and without encryption. It covers homonym folders, autosave-marked ids, aliased spaces, and exactly one audit, activity and journal entry per restore. **Live check (local instance, v0.6.343): all PASS.** - Restoring the oldest version answers 200, restores the content, and the version list grows by one. - anna can restore in a space. - bob (read-only member) gets 403 `read-only`. - A held file gets 403 `legal-hold`; a locked file gets 423 `locked`. - One audit `version-restore` and one Activity "version restored". Closing. The browser click-through on the dogfoods is part of the batch A dogfood check with Nikola.
Sign in to join this conversation.
No labels
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: Cordy/Cairn#902
No description provided.