Skip to content

fix(blaze): bound HTTP request bodies - #2293

Draft
WeissonHan wants to merge 1 commit into
alibaba:mainfrom
WeissonHan:fix/blaze/bound-http-request-bodies-main
Draft

fix(blaze): bound HTTP request bodies#2293
WeissonHan wants to merge 1 commit into
alibaba:mainfrom
WeissonHan:fix/blaze/bound-http-request-bodies-main

Conversation

@WeissonHan

@WeissonHan WeissonHan commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Why

Blaze already limits the HTTP envelope used by guest exec, read, and write operations, but every other daemon route could still buffer an arbitrary request body before dispatch. Ordinary API requests need a predictable per-request memory boundary without reducing the larger envelope required for guest file transfer.

What changed

Before:

  • Guest exec/read/write routes stopped collecting above their existing 22 MiB envelope.
  • Other routes passed no limit to the collector and buffered until the peer finished sending.
  • Ordinary routes had no dedicated size error or configuration boundary.

After:

  • Routes without a specialized envelope use the new positive api.max_body_bytes setting, which defaults to 1 MiB.
  • A shared collector rejects an oversized declared Content-Length before polling the body and stops when streamed bytes first cross the selected route limit.
  • Invalid, empty, or conflicting length values return HTTP 400. Ordinary size violations return HTTP 413 with request_too_large.
  • Guest exec/read/write retain their existing 22 MiB envelope and guest_request_too_large response.
  • The example configuration, English and Chinese README files, and English and Chinese user guide describe the same route-specific behavior.

Commit

  1. 9c43a28d83b9bound daemon HTTP request bodies. Adds the configuration contract, shared collector, error mapping, focused tests, example, and bilingual documentation.

These changes belong in one PR because they implement one request-collection boundary at the daemon entry point. The configuration selects that boundary, the collector enforces it, the API maps its result, and the tests and documentation define the same observable behavior. Removing this commit restores the previous unbounded ordinary-route behavior without changing sandbox lifecycle, storage, guest protocol, or backend contracts.

Related issue

fixes #2292

User / Agent impact

Existing configurations remain valid and receive the 1 MiB ordinary-route default. An ordinary request above that limit now receives HTTP 413 instead of being fully buffered; operators that intentionally send larger ordinary payloads can set a larger positive api.max_body_bytes value.

Guest command and file routes remain capped at 22 MiB independently of this setting, so their existing 16 MiB decoded file limit and error code do not change. The new boundary is per request; it does not cap aggregate memory across concurrent requests.

Risk and compatibility

  • Public CLI, API, configuration, or documented behavior changed
  • Privileged or security-sensitive behavior changed
  • Cross-component contract changed
  • Migration or rollback guidance is needed

The new configuration field is optional and defaults through serde, so existing files continue to parse. The observable compatibility change is that ordinary bodies above 1 MiB are rejected by default. Raise api.max_body_bytes before deployment when an existing caller requires a larger ordinary payload. The value must be greater than zero.

Validation

Exact commit: 9c43a28d83b98a3a2dee419dfdc6ad2e9d601d8a

The Git archive was copied to a fresh Linux x86_64 source directory. Its local and remote SHA-256 matched:

252cb5cf374634e4ca65b939108b9ae2336acc826f208688e7022067c3cb24f0

The following checks passed with Rust/Cargo 1.93.1:

  • cargo fmt --all -- --check
  • cargo metadata --locked --format-version 1 --no-deps
  • cargo build --workspace --all-targets --locked
  • cargo build --workspace --all-targets --all-features --locked
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --locked — 54 library + 119 daemon tests
  • cargo test --workspace --all-features --locked — 54 library + 129 daemon tests
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features --locked
  • request-body collector tests — 10/10
  • ordinary-route handler limit — 1/1
  • guest envelope regression — 1/1
  • configuration tests — 5/5
  • bash scripts/docs-lint.sh
  • python3 scripts/docs-link-check.py
  • commitlint 19.8.1, trailer parsing, parent-to-head git diff --check, and public-boundary scan

All listed tests completed with zero failures. Hosted checks are reported by GitHub separately.

Documentation and rollback

The example configuration, component README in English and Chinese, and Blaze user guide in English and Chinese now document the default, override, response status, and guest-route exception. CHANGELOG aggregation remains reserved for a release version-bump PR.

To retain larger ordinary requests, set api.max_body_bytes to a suitable positive byte count. Revert this commit to restore the previous ordinary-route collection behavior.

Copy link
Copy Markdown
Collaborator Author

@codex review This PR bounds ordinary Blaze HTTP request bodies with a configurable default while preserving the existing guest-operation envelope.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a59f4fbd83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

#[serde(default)]
pub listen: ListenSection,
#[serde(default)]
pub api: ApiSection,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the public API limit field

DaemonConfig::api is a newly introduced public configuration field but has no rustdoc, leaving generated blaze-core API documentation without the field's ordinary-route limit and guest-envelope contract. Add a /// comment to this significant public field as required by the repository's Rust documentation rules.

AGENTS.md reference: AGENTS.md:L111-L115

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9c43a28d83b9. DaemonConfig::api now documents that this section applies to routes without a dedicated protocol envelope and that guest-operation routes retain their protocol-specific limit. Strict rustdoc passed for both default and all-feature builds on this exact commit.

Guest operation routes already used a bounded request envelope, but every
other daemon route could still buffer an arbitrary body before dispatch.

Add a validated api.max_body_bytes default for ordinary routes. Collect
every request through a shared limit-aware reader. Reject malformed or
conflicting Content-Length values before polling, and stop when streamed
bytes first cross the selected route boundary.

This gives ordinary requests a configurable 1 MiB default while preserving
the existing 22 MiB guest envelope and its stable error code. Body format
failures return 400, and size violations return 413. Document the
route-specific behavior in the example and bilingual guides.

Fixes: 4ec67cf ("feat(blaze): implement sandbox guest operations (alibaba#2217)")

Signed-off-by: Weisson Han <wenshu.hx@linux.alibaba.com>
@WeissonHan
WeissonHan force-pushed the fix/blaze/bound-http-request-bodies-main branch from a59f4fb to 9c43a28 Compare August 6, 2026 21:30

Copy link
Copy Markdown
Collaborator Author

@codex review Please re-review the current head 9c43a28d83b9, including the public DaemonConfig::api documentation added in response to the previous finding.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 9c43a28d83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

blaze: bound HTTP request body collection

1 participant