feat(security): stream uploads end to end, bound request bodies (#258) #299

Merged
sharang merged 1 commits from feat/streamed-uploads into main 2026-09-21 11:37:19 +00:00
1 Commits
Author SHA1 Message Date
Sharang ParnerkarandClaude Opus 5 3a4919f0f6 feat(security): stream uploads end to end, bound request bodies (#258)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m9s
The second half of #258. A file upload of up to 512 MiB used to be held in
memory about five times over: the browser read it into WASM memory, sent it to
the dashboard as a JSON byte array inside a server function (roughly 4x the
file), the dashboard copied it into a multipart request, and the agent buffered
the whole field before writing it. Several concurrent uploads could exhaust an
8 GB node.

Now nothing holds the file:

- Browser: the wizard keeps the picked file's handle, not its bytes, and passes
  it as a Dioxus `FileStream`, which sends the `File` itself as the request body
  (browser-native streaming from disk).
- Dashboard: `POST /api/uploads/{id}?kind&plc_format` forwards that body to the
  agent as the multipart `file` part via `reqwest::Body::wrap_stream`.
- Agent: the `file` field is written to disk chunk by chunk, refused with 413
  past 512 MiB, and owned by a guard that deletes it on any early return — an
  oversized, malformed or kind-less upload leaves nothing behind.

Request bodies: the 512 MiB limit applied to every route on both services, so
any JSON endpoint could be made to buffer half a gigabyte. It is now scoped:
the upload route (streamed) and the runner's job-result route (32 MiB) on the
agent, the webhook proxy (25 MB, GitHub's cap) on the dashboard; everything
else keeps axum's 2 MiB default.

Also fixes the two `manual_checked_ops` lints in `attack_chain/view.rs` that
newer clippy reports, so dashboard clippy runs clean locally.

Verified end to end in a real browser (agent + dashboard + Chromium): a 3 MiB
firmware image went through the wizard as `application/octet-stream` with no
JSON encoding and landed on disk byte-identical (SHA-256 match).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
2026-09-21 13:18:36 +02:00