Deleting a space whose folder still has its old name leaves its files on disk outside the trash #935

Closed
opened 2026-10-15 23:56:41 +00:00 by Cordy · 5 comments
Owner

Found by the fix-923 final review (2026-10-16). Confirmed with a probe; this predates fix-923.

What happens: deleteSpace (internal/api/spaces_lifecycle.go ~259) deletes /spaces/<name>, not the space's backend folder. A space renamed but not yet converged (for example name Lag, folder LagOld) leaves LagOld/... on disk when deleted. The files are not in the trash and nobody owns them.

Why it matters:

  • Data: the deletion did not happen; the files sit outside the trash and retention rules.
  • Access: once the dead identity is gone, an IdP group named LagOld can read those files (confirmed in the probe).
  • On main, before fix-923: recreating Lag inherited BackendDir LagOld, so the new creator got the old files. fix-923 removed that path, but not the root cause.

To do:

  • Delete through the space's backend folder (resolve by space ID).
  • Test before and after convergence, on posix and s3.
  • Check both dogfoods for such leftover folders. This relates to #932 and #918.
Found by the fix-923 final review (2026-10-16). Confirmed with a probe; this predates fix-923. **What happens:** `deleteSpace` (`internal/api/spaces_lifecycle.go` ~259) deletes `/spaces/<name>`, not the space's backend folder. A space renamed but not yet converged (for example name `Lag`, folder `LagOld`) leaves `LagOld/...` on disk when deleted. The files are not in the trash and nobody owns them. **Why it matters:** - **Data:** the deletion did not happen; the files sit outside the trash and retention rules. - **Access:** once the dead identity is gone, an IdP group named `LagOld` can read those files (confirmed in the probe). - **On main, before fix-923:** recreating `Lag` inherited `BackendDir LagOld`, so the new creator got the old files. fix-923 removed that path, but not the root cause. **To do:** - Delete through the space's backend folder (resolve by space ID). - Test before and after convergence, on posix and s3. - Check both dogfoods for such leftover folders. This relates to #932 and #918.
Author
Owner

Related, from the v0.6.346 live check (Finding 5, older behaviour): the owner restored a deleted space's trash entry while the space name was still reserved. The restore recreated /spaces/gone as a folder that no space holds. The owner gets 404 on it, so only an admin take-over can reach those files.

Restoring onto a name that was already reused is refused (409), so nothing lands in another person's space. The fix here should cover what restore does for entries of a deleted space: refuse with a clear reason, or restore into the owner's home.

**Related, from the v0.6.346 live check (Finding 5, older behaviour):** the owner restored a deleted space's trash entry while the space name was still reserved. The restore recreated `/spaces/gone` as a folder that no space holds. The owner gets 404 on it, so only an admin take-over can reach those files. Restoring onto a name that was already reused is refused (409), so nothing lands in another person's space. The fix here should cover what restore does for entries of a deleted space: refuse with a clear reason, or restore into the owner's home.
Author
Owner

Deep research (2026-10-18)

The full write-up is in ~/cairn-work/scratch/b7e/backlog/research-935.md.

Fix with no decision needed

Delete through the space's own folder. Two related problems turned up:

  • Second code path: deleting an app-owned group together with its space (groups.go:512) has the same name-path delete.
  • Legal holds: the bug also skips the legal-hold check, so held files stay on disk under a deleted space.

What other products do

  • oCIS, OpenCloud, SharePoint, Google Shared Drives, Dropbox, Box and Seafile all restore the space itself. None of them restores a team space into a person's home.
  • Nextcloud's silent restore-to-home is reported by users as data loss (nextcloud/server#31200).

Cairn-specific constraint

Space files are encrypted to the space's group key, and moving a folder does not re-encrypt it (encrypt/group.go). After a restore into the owner's home, the owner could not read the files without a full re-encryption.

Recommendation (option C)

"Restore space" un-deletes the space: same id, name, owner, settings and storage limit, in the folder it was deleted from.

  • Deactivated on return: the space comes back deactivated, so the owner or an admin reviews it before members get access.
  • Members: their list is snapshotted at delete and restored with the space.
  • Refusal: if the entry names no space, or its name now belongs to another space, the restore is refused with 409 and a clear reason. Cairn never creates a bare folder and never restores into a home.

Found on the way

  • Name reservation: the name is freed after 90 days, but the trash never auto-purges by default, and the delete dialog promises the name stays reserved "until the contents are finally purged". Proposed fix: the name stays reserved while the entry exists.

Leftover folders on the dogfoods

Administration > Spaces does not show this kind of leftover, because the former name hides the folder. Read-only check steps are in §6.2 of the research file.

Decisions needed (asked now)

  1. Option C (restore the space itself, deactivated, with members), or admin-only restore (D), or refuse only (A)?
  2. Who may restore: the person who deleted it plus admins?
  3. Should the name stay reserved while the entry exists?

C adds a visible "Restore space" action, so it needs a mockup before any UI work.

## Deep research (2026-10-18) The full write-up is in `~/cairn-work/scratch/b7e/backlog/research-935.md`. ### Fix with no decision needed Delete through the space's own folder. Two related problems turned up: - **Second code path:** deleting an app-owned group together with its space (`groups.go:512`) has the same name-path delete. - **Legal holds:** the bug also skips the legal-hold check, so held files stay on disk under a deleted space. ### What other products do - oCIS, OpenCloud, SharePoint, Google Shared Drives, Dropbox, Box and Seafile all restore the space itself. None of them restores a team space into a person's home. - Nextcloud's silent restore-to-home is reported by users as data loss (nextcloud/server#31200). ### Cairn-specific constraint Space files are encrypted to the space's group key, and moving a folder does not re-encrypt it (`encrypt/group.go`). After a restore into the owner's home, the owner could not read the files without a full re-encryption. ### Recommendation (option C) "Restore space" un-deletes the space: same id, name, owner, settings and storage limit, in the folder it was deleted from. - **Deactivated on return:** the space comes back deactivated, so the owner or an admin reviews it before members get access. - **Members:** their list is snapshotted at delete and restored with the space. - **Refusal:** if the entry names no space, or its name now belongs to another space, the restore is refused with 409 and a clear reason. Cairn never creates a bare folder and never restores into a home. ### Found on the way - **Name reservation:** the name is freed after 90 days, but the trash never auto-purges by default, and the delete dialog promises the name stays reserved "until the contents are finally purged". Proposed fix: the name stays reserved while the entry exists. ### Leftover folders on the dogfoods Administration > Spaces does not show this kind of leftover, because the former name hides the folder. Read-only check steps are in §6.2 of the research file. ### Decisions needed (asked now) 1. Option C (restore the space itself, deactivated, with members), or admin-only restore (D), or refuse only (A)? 2. Who may restore: the person who deleted it plus admins? 3. Should the name stay reserved while the entry exists? C adds a visible "Restore space" action, so it needs a mockup before any UI work.
Author
Owner

Decision (Nikola, 2026-10-18):

  • Option C. Restoring the trash entry un-deletes the space: same id, name, owner, settings, limit and folder, deactivated, with the members from delete time. The restore is refused with 409 and a reason when the name now belongs to another space or the entry names no space. Never restore into a home.
  • Who may restore: the person who deleted the space, its owner, and admins.
  • The name stays reserved as long as the trash entry exists, which replaces the 90-day release.
  • The UI waits for a mockup. The "Restore space" action and its messages need one before UI code. The backend part, including #962 (legal-hold check, delete through the space's own folder), can start now.
**Decision (Nikola, 2026-10-18):** - **Option C.** Restoring the trash entry un-deletes the space: same id, name, owner, settings, limit and folder, deactivated, with the members from delete time. The restore is refused with 409 and a reason when the name now belongs to another space or the entry names no space. Never restore into a home. - **Who may restore:** the person who deleted the space, its owner, and admins. - **The name stays reserved** as long as the trash entry exists, which replaces the 90-day release. - **The UI waits for a mockup.** The "Restore space" action and its messages need one before UI code. The backend part, including #962 (legal-hold check, delete through the space's own folder), can start now.
Author
Owner

Mockup approved by Nikola (2026-10-19), as drawn (batch3-mockups.html, scenes 1a-5), with these answers:

  • After Restore space: the person stays in Deleted files. The status line says "Space Lag restored. It is deactivated: reactivate it to give members access." with an "Open Spaces ›" link.
  • Delete forever on a space row frees the name and the former names (the identity is retired). The confirm says so.
  • Owner's view: an administrator's deletion of an owner's space shows in the owner's Deleted files ("Space · Admin Anna").
**Mockup approved by Nikola (2026-10-19), as drawn** (batch3-mockups.html, scenes 1a-5), with these answers: - **After Restore space:** the person stays in Deleted files. The status line says "Space Lag restored. It is deactivated: reactivate it to give members access." with an "Open Spaces ›" link. - **Delete forever** on a space row frees the name and the former names (the identity is retired). The confirm says so. - **Owner's view:** an administrator's deletion of an owner's space shows in the owner's Deleted files ("Space · Admin Anna").
Author
Owner

Shipped in v0.6.350 (PR #970). Both dogfoods run it. Live check on files-bao (S3 + OpenBao), 2026-10-19: PASS.

Steps run on a throwaway space B3live:

  1. Create the space, upload a file, then rename the space to B3live2. After the folder converged, both the old file and one uploaded after the move read back correctly.
  2. Deactivate the space, then delete it. Deleted files shows the new space row: the space icon, B3live2, "Space · nikola-test", Restore space and Delete forever. The entry carries the space id.
  3. The Restore space confirm matches mockup scene 2.
  4. After the restore, the status line reads "Space B3live2 restored. It is deactivated: reactivate it to give members access." with an Open Spaces › link (scene 3a). The link opens the overview with B3live2 deactivated (scene 3b). The log line was spaces: deleted space restored, deactivated.
  5. Reactivated the space. Both files read back under the new name, and under the former name too.
  6. Deleted it again. The Delete forever confirm matches scene 5 ("The name … and any former names become free").
    • Before the purge, creating B3live2 again was refused with 409 name-in-use: the name stays reserved while the entry exists.
    • After the purge, both B3live2 and the former name B3live answer 404.

Everything I created was removed again.

Not exercised live: the refusals space-name-taken, space-gone and space-copies-left, and recovery from an interrupted restore. They can only be produced with crashes, rollbacks or planted folders, so they are covered by the tests in the PR.

Follow-ups: #964 (a purged space's settings stay stored under its retired id), #968, and the multi-instance notes on #742.

**Shipped in v0.6.350 (PR #970). Both dogfoods run it. Live check on files-bao (S3 + OpenBao), 2026-10-19: PASS.** Steps run on a throwaway space B3live: 1. Create the space, upload a file, then rename the space to B3live2. After the folder converged, both the old file and one uploaded after the move read back correctly. 2. Deactivate the space, then delete it. Deleted files shows the new space row: the space icon, B3live2, "Space · nikola-test", **Restore space** and **Delete forever**. The entry carries the space id. 3. The **Restore space** confirm matches mockup scene 2. 4. After the restore, the status line reads "Space B3live2 restored. It is deactivated: reactivate it to give members access." with an **Open Spaces ›** link (scene 3a). The link opens the overview with B3live2 deactivated (scene 3b). The log line was `spaces: deleted space restored, deactivated`. 5. Reactivated the space. Both files read back under the new name, and under the former name too. 6. Deleted it again. The **Delete forever** confirm matches scene 5 ("The name … and any former names become free"). - Before the purge, creating B3live2 again was refused with 409 `name-in-use`: the name stays reserved while the entry exists. - After the purge, both B3live2 and the former name B3live answer 404. Everything I created was removed again. **Not exercised live:** the refusals `space-name-taken`, `space-gone` and `space-copies-left`, and recovery from an interrupted restore. They can only be produced with crashes, rollbacks or planted folders, so they are covered by the tests in the PR. **Follow-ups:** #964 (a purged space's settings stay stored under its retired id), #968, and the multi-instance notes on #742.
Cordy closed this issue 2026-10-19 20:13:01 +00:00
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#935
No description provided.