Skip to content

Bug: Chat attachment 10-file cap can be bypassed when rapid sequential uploads overlap in-flight #2026

Closed

Description

@yannickmonney

Area

Chat file attachments — `services/platform/app/features/chat/hooks/use-convex-file-upload.ts`

Steps to reproduce

  1. Start a new chat thread.
  2. Rapidly drop two batches of 6 files each in quick succession (before the first batch finishes uploading).
  3. The slot-count check runs at the start of `uploadFiles` and reads `attachmentsRef.current.length`, which only reflects settled uploads — not in-flight ones.
  4. Both calls see `length = 0` and each approve their full 6-file batch.
  5. Both batches upload in parallel; the chat ends up with 12 attached files, exceeding the 10-file cap.

Expected

Each subsequent `uploadFiles` call should account for in-flight uploads and reject overflow files before they are uploaded.

Actual

The slot check at line 230 reads `attachmentsRef.current.length`, which is backed by React state updated only when each individual upload completes (line 335: `setAttachments((prev) => [...prev, attachment])`). Files still uploading are tracked in `uploadingFiles` (string IDs) but their count is never subtracted from the available slots. Two rapid drops (or paste + drop) before any upload settles both see the stale count and both pass the guard, resulting in up to 2 × 10 = 20 uploads.

Evidence

  • `services/platform/app/features/chat/hooks/use-convex-file-upload.ts:230-231` — slot check reads `attachmentsRef.current.length` (settled only)
  • `services/platform/app/features/chat/hooks/use-convex-file-upload.ts:283` — in-flight IDs added to `uploadingFiles` string array, never counted against slots
  • `services/platform/app/features/chat/hooks/use-convex-file-upload.ts:335` — `setAttachments` called only after successful upload (too late for the guard)
  • `services/platform/lib/shared/file-types.ts:521` — `CHAT_MAX_FILE_COUNT = 10`

Notes

Fix: add an `inFlightCountRef` that is incremented before upload starts and decremented on settle, then use `attachmentsRef.current.length + inFlightCountRef.current` as the slot-check denominator. Alternatively, gate the slot check under an async lock/semaphore. The deduplication and total-size checks have the same stale-ref exposure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedbugpriority: mediumservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions