Administrators can write into a space's .trash through the REST API (bypasses trash records) #906

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

Found while fixing the trash folders in pickers (fix-897b, v0.6.342).

A throwaway test through the real storage stack showed that a session administrator can mkdir, upload, move and copy INTO /spaces/<x>/.trash through the REST API. This bypasses the trash records (sidecars), so such entries can confuse Deleted files, restore and purge. Non-admins and WebDAV are refused.

Cause: internal/storage/trash/trash.go, the check is deny = isAnyTrashPath && !isAdmin (admins keep raw access to trash trees by design).

Since v0.6.342 no picker offers trash folders any more, so it now takes a hand-made API call.

To decide (research first): should admins keep raw write access into trash trees at all? Read access for recovery tooling may be needed; writes probably not. Then four guards (mkdir, write, rename-into, copy-into) and tests.

Found while fixing the trash folders in pickers (fix-897b, v0.6.342). A throwaway test through the real storage stack showed that a **session administrator** can mkdir, upload, move and copy INTO `/spaces/<x>/.trash` through the REST API. This bypasses the trash records (sidecars), so such entries can confuse Deleted files, restore and purge. Non-admins and WebDAV are refused. Cause: `internal/storage/trash/trash.go`, the check is `deny = isAnyTrashPath && !isAdmin` (admins keep raw access to trash trees by design). Since v0.6.342 no picker offers trash folders any more, so it now takes a hand-made API call. To decide (research first): should admins keep raw write access into trash trees at all? Read access for recovery tooling may be needed; writes probably not. Then four guards (mkdir, write, rename-into, copy-into) and tests.
Author
Owner

Research (2026-10-15)

Full file: cairn-work/scratch/b7e/batch907/906-research.md. Throwaway Go tests confirmed the findings below; the repo is untouched.

Wider than reported. Three worse holes in the same area:

  • P1 (admin bypasses a legal hold): a session admin's raw DELETE of /.trash/<user>/<id>.data succeeds even when the original path is held. The admin branch in trash.go:146-152 checks retention but not holds, and the audit shows a plain delete.
  • P2 (any user bypasses a legal hold): Driver.Purge (trash.go:325-344) checks retention but never holds. A hold placed after deletion does not stop the owner purging, which breaks admin-policy.md:157-163. The sweeper and AdminPurge do check holds.
  • P3 (forged trash records): an admin can write a .meta/.data pair into a space trash.
    • It shows in members' Deleted files with a fake "deleted by".
    • On restore it lands wherever the record says, including another user's home, because restoreFrom trusts the stored path.
    • Overwriting a .meta also changes which retention period or hold applies.
  • Files without records never appear in Deleted files, are never swept and don't count against quota.
  • The report-folder finding is confirmed, with a second route: a trash folder can be saved while that report (or share reviews) is off, then switched on unchanged. The run is still refused, so the report fails every time but nothing is written into trash.

History: raw admin access dates from #23, when it was the only way to empty trash. Retention and holds (#63), the sweeper (#77) and the admin Deleted files APIs (#278-#281) replaced that use. Nothing depends on raw admin access now; only two unit tests assert it.

Market and standards:

  • Market: Nextcloud, ownCloud and oCIS expose trash only through a dedicated API, never as a writable folder. Their top complaint is records and files drifting apart.
  • CVE-2025-66545: the lesson is to check the restore target.
  • Standards: NIST AC-6/AC-6(9) and ISO 27002 5.33 and 8.10.

Recommendation:

  • Refuse for everyone, admins included: writes, uploads, mkdir and copies into trash; moves into or out of it; raw deletes inside it (403 trash-managed for admins, the current 404 for others).
  • Keep for admins: read and copy-out, for recovery and forensics. System paths already sit below the guard.
  • Same change:
    • add the hold check to user purge;
    • validate the stored path in restoreFrom;
    • always apply the report trash rule, exempting a stored value only if that report was already enabled;
    • update ARCHITECTURE.md and the handbook.

Decisions (my recommendation in brackets):

  1. Refuse admin writes into trash [yes].

  2. Refuse admin raw deletes inside trash and point to Manual purge [yes].

  3. Keep admin read access [yes, for now].

  4. Fix user purge ignoring holds here [yes].

  5. Report-folder rule as above [yes].

  6. Separate follow-ups:

    • restore records naming an old space folder after a rename (unverified);
    • reserving the .trash name for user folders;
    • user purges audited as trash:<id> instead of the path.

    [file them].

Mockup: none. Size: about 1 day.

## Research (2026-10-15) Full file: `cairn-work/scratch/b7e/batch907/906-research.md`. Throwaway Go tests confirmed the findings below; the repo is untouched. **Wider than reported. Three worse holes in the same area:** - **P1 (admin bypasses a legal hold):** a session admin's raw `DELETE` of `/.trash/<user>/<id>.data` succeeds even when the original path is held. The admin branch in `trash.go:146-152` checks retention but not holds, and the audit shows a plain `delete`. - **P2 (any user bypasses a legal hold):** `Driver.Purge` (`trash.go:325-344`) checks retention but never holds. A hold placed after deletion does not stop the owner purging, which breaks admin-policy.md:157-163. The sweeper and AdminPurge do check holds. - **P3 (forged trash records):** an admin can write a `.meta`/`.data` pair into a space trash. - It shows in members' Deleted files with a fake "deleted by". - On restore it lands wherever the record says, including another user's home, because `restoreFrom` trusts the stored path. - Overwriting a `.meta` also changes which retention period or hold applies. - **Files without records** never appear in Deleted files, are never swept and don't count against quota. - **The report-folder finding is confirmed, with a second route:** a trash folder can be saved while that report (or share reviews) is off, then switched on unchanged. The run is still refused, so the report fails every time but nothing is written into trash. **History:** raw admin access dates from #23, when it was the only way to empty trash. Retention and holds (#63), the sweeper (#77) and the admin Deleted files APIs (#278-#281) replaced that use. Nothing depends on raw admin access now; only two unit tests assert it. **Market and standards:** - **Market:** Nextcloud, ownCloud and oCIS expose trash only through a dedicated API, never as a writable folder. Their top complaint is records and files drifting apart. - **CVE-2025-66545:** the lesson is to check the restore target. - **Standards:** NIST AC-6/AC-6(9) and ISO 27002 5.33 and 8.10. **Recommendation:** - **Refuse for everyone, admins included:** writes, uploads, mkdir and copies into trash; moves into or out of it; raw deletes inside it (403 `trash-managed` for admins, the current 404 for others). - **Keep for admins:** read and copy-out, for recovery and forensics. System paths already sit below the guard. - **Same change:** - add the hold check to user purge; - validate the stored path in `restoreFrom`; - always apply the report trash rule, exempting a stored value only if that report was already enabled; - update ARCHITECTURE.md and the handbook. **Decisions** (my recommendation in brackets): 1. Refuse admin writes into trash [yes]. 2. Refuse admin raw deletes inside trash and point to Manual purge [yes]. 3. Keep admin read access [yes, for now]. 4. Fix user purge ignoring holds here [yes]. 5. Report-folder rule as above [yes]. 6. Separate follow-ups: - restore records naming an old space folder after a rename (unverified); - reserving the `.trash` name for user folders; - user purges audited as `trash:<id>` instead of the path. [file them]. Mockup: none. Size: about 1 day.
Author
Owner

Decisions (Nikola, 2026-10-15): all recommendations accepted (comment 9152): refuse writes/moves/raw deletes into trash for everyone incl. admins (403 trash-managed for admins), keep admin read/copy-out, hold check in user purge, validate the restore target in restoreFrom, report-folder rule (exempt a stored value only if that report was already enabled), follow-ups filed. Built in batch A.

**Decisions (Nikola, 2026-10-15): all recommendations accepted** (comment 9152): refuse writes/moves/raw deletes into trash for everyone incl. admins (403 `trash-managed` for admins), keep admin read/copy-out, hold check in user purge, validate the restore target in `restoreFrom`, report-folder rule (exempt a stored value only if that report was already enabled), follow-ups filed. Built in batch A.
Author
Owner

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

  • Trash trees are system-managed. A session admin gets 403 trash-managed for write, mkdir, delete, rename in or out, and copy in. Everyone else gets 404. Admins keep read and copy-out.
  • A person's own purge respects legal holds. It answers 403 legal-hold, and since v0.6.344 the admin purge answers the same.
  • The restore target is validated. NFC-tolerant, and safe across space renames.
  • Restore when the name is taken: the item comes back as "{name} 2". Since v0.6.344 the answer gives the person's own path.
  • Report folders: the trash rule applies to them as decided.

Live check (local instance):

  • PASS:
    • Admin upload, mkdir, move in/out, copy in, delete and TUS into a space trash all get 403 trash-managed.
    • Personal restore and purge work.
    • A held entry can't be purged by its owner.
  • Minor (fixed in v0.6.344): a non-admin TUS upload into a trash tree answered 500 instead of 404.
  • Pre-existing bug (not from this batch), filed as #911: members of app-managed spaces don't see the space's Deleted files.

Closing.

## Shipped in v0.6.343 (PR #910), follow-up fixes in v0.6.344 (PR #912). Both dogfoods run v0.6.344. - **Trash trees are system-managed.** A session admin gets 403 `trash-managed` for write, mkdir, delete, rename in or out, and copy in. Everyone else gets 404. Admins keep read and copy-out. - **A person's own purge respects legal holds.** It answers 403 `legal-hold`, and since v0.6.344 the admin purge answers the same. - **The restore target is validated.** NFC-tolerant, and safe across space renames. - **Restore when the name is taken:** the item comes back as "{name} 2". Since v0.6.344 the answer gives the person's own path. - **Report folders:** the trash rule applies to them as decided. **Live check (local instance):** - **PASS:** - Admin upload, mkdir, move in/out, copy in, delete and TUS into a space trash all get 403 `trash-managed`. - Personal restore and purge work. - A held entry can't be purged by its owner. - **Minor (fixed in v0.6.344):** a non-admin TUS upload into a trash tree answered 500 instead of 404. - **Pre-existing bug (not from this batch), filed as #911:** members of app-managed spaces don't see the space's Deleted files. Closing.
Cordy closed this issue 2026-10-15 16:56:54 +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#906
No description provided.