Skip to content

id(web): delete/restore file handlers bypass FileOps canonical name validation #10573

Closed

Description

@dezren39

Problem

The web file-management handlers delete_handler and restore_handler (soft-delete / restore) accept req.name and operate on it with only an emptiness check (req.name.trim().is_empty()), then use the original, unvalidated req.name as the tag/metadata key. They never apply the canonical name validation that FileOps enforces for every FileOps entry point (FileOps::validate_name). This lets the web API soft-delete/restore under names that the CLI/REPL/meta protocol reject, diverging behavior across entry points and allowing padded, rooted, ..-containing, or reserved archive-shaped names to enter the tag namespace via the web surface.

This is the delete/restore sibling of the already-tracked save/new gap (#10549); hard_delete_handler delegates to FileOps::delete (which at least emptiness-checks), and rename/copy go through FileOps, but the soft-delete and restore paths bypass FileOps entirely.

Evidence

  • pkgs/id/crates/id-web/src/routes/file_handlers.rs:1167-1215 (delete_handler): rejects only when req.name.trim().is_empty() (line ~1173), then looks up state.store.tags().get(&req.name) and calls state.tag_store.set_singleton(..., req.name.as_bytes(), b"deleted", ...) using the original untrimmed req.name — no FileOps::validate_name (or equivalent) check before the side effect.
  • pkgs/id/crates/id-web/src/routes/file_handlers.rs:1218-1262 (restore_handler): same emptiness-only check (line ~1224), then state.store.tags().get(&req.name) and state.tag_store.del_by_key(..., req.name.as_bytes(), b"deleted") on the original untrimmed name — no canonical validation.
  • pkgs/id/crates/id-sync/src/fileops.rs:267-296 (FileOps::validate_name): documents "The single canonical-name rule for every FileOps entry point" and rejects names that are not exactly trimmed (name != name.trim()), rooted / \-prefixed / Windows drive-prefixed, containing empty/./.. path components, or matching the reserved archive-tag shape (is_archive_tag_name -> ReservedArchiveName). FileOps::put/rename/copy all validate via this rule.
  • Contrast: hard_delete_handler (file_handlers.rs:1268+) delegates to FileOps::delete (fileops.rs:638+), and rename/copy handlers route through FileOps; only soft delete + restore operate on the raw tag store with the canonical rule absent.

Concrete bypass examples under current code:

  • A name with leading/trailing whitespace (e.g. " notes.md") passes the emptiness check but is used verbatim as the tag key, while FileOps::validate_name rejects it (not exactly trimmed).
  • Reserved archive-shaped names (e.g. doc.md.archive.1234567890, matched by is_archive_tag_name) would be rejected as ReservedArchiveName by FileOps but can receive a deleted tag / have it removed through the web handlers.
  • Names containing .. components or other shapes forbidden by the canonical rule are not rejected by delete/restore, unlike FileOps-backed paths, and the deleted tag then lives under a non-canonical key.

Why it matters

Suggested fix / acceptance criteria

  • Apply the canonical name rule to web soft-delete/restore paths: validate req.name in delete_handler and restore_handler with FileOps::validate_name (or the same semantics, after any intended forgiving normalization such as trimming is applied consistently and the stored name is the normalized one) before the existence lookup and before any tag write (set_singleton/del_by_key).
  • Reject EmptyName, InvalidName (untrimmed, rooted/drive-prefixed, empty/./.. components), and ReservedArchiveName with clear 4xx responses (and preserve existing behavior for valid names).
  • Keep behavior consistent with hard_delete_handler/FileOps paths (same error mapping style) where applicable.
  • Consider the same validation for other web entry points that accept user-controlled file names outside FileOps (e.g. upload naming, rename/copy request prechecks) for consistency, if not already covered.
  • Add regression tests covering: delete and restore reject reserved archive-shaped names; reject names with ../invalid path components; reject untrimmed/whitespace-padded names (or normalize-then-validate consistently); valid ordinary names still soft-delete/restore successfully.

Related

Activity

  1. developing-today commented on Nov 16, 2026

    @developing-today
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions