Skip to content

id(web): upload handler stores non-canonical multipart filenames verbatim when the extension matches #10585

Closed

Description

@dezren39

Evidence (origin/main)

reconcile_upload_filename (pkgs/id/crates/id-web/src/routes.rs:1077-1095) returns the caller's multipart filename verbatim whenever its extension already agrees with the validated content type (:1088-1090):

if current.as_deref().is_some_and(|c| acceptable.contains(&c)) {
    return name.to_owned();
}

Only the mismatch branch canonicalizes (via file_stem, which drops directory components, :1091-1094 — the comment at :1092-1093 even claims upload names are plain file names, but the early return above it does not enforce that).

The upload path then stores that name unchecked:

  • pkgs/id/crates/id-web/src/routes/file_handlers.rs:453-454 — only rejects blank-after-trim filenames, then calls reconcile_upload_filename.
  • file_handlers.rs:388-407 (uniquify_upload_name) — returns the intended name verbatim when free or already naming the same blob.
  • file_handlers.rs:551-552 — state.store.tags().set(Tag::from(filename), hash) stores it as-is, plus filename-keyed metadata tags below.

FileOps::validate_name (pkgs/id/crates/id-sync/src/fileops.rs:275-296) — documented as "the single canonical-name rule for every FileOps entry point" — rejects exactly these shapes (.. components, rooted names, leading/trailing padding), but the upload path never calls it.

Repro (code-level, verified against the function)

With validated type image/png:

multipart filename stored tag name validate_name says
../../x.png ../../x.png verbatim InvalidName (.. components)
/abs.png /abs.png verbatim InvalidName (rooted)
foo.png (leading space) foo.png verbatim InvalidName (padding)
evil.html evil.png (mismatch branch, fine) ok

(Any HTTP client can set an arbitrary multipart filename; browsers sending basenames does not constrain the server-side contract.)

Why it matters

  • Stored tag names that no forgiving surface can re-specify identically (CLI/REPL trim before calling in): padded twins ( foo.png vs foo.png) and path-shaped names (../../x.png, /abs.png) enter the blob-tag and metadata-tag namespaces, defeating the canonical-name invariant every FileOps entry point enforces.
  • Path-shaped stored names are a latent traversal input for any current or future consumer that joins a tag name onto a filesystem path (export/backup/sync flows).

Sibling cluster (not duplicates)

Acceptance criteria

  • An upload whose multipart filename carries .. components, a rooted path, or leading/trailing padding is rejected (400) or normalized to the canonical plain file name before any tag/metadata write — no non-canonical name is stored.
  • The mismatch branch keeps its type-reconciliation behavior (evil.html + PNG bytes -> evil.png).
  • Regression tests pin the verbatim-passthrough cases above (matching extension + ../rooted/padded name) alongside the existing reconcile_upload_filename_matches_validated_type cases.

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

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions