Skip to content

Limit ingress HTTP request body size#4751

Open
muhamadazmy wants to merge 1 commit into
mainfrom
pr4751
Open

Limit ingress HTTP request body size#4751
muhamadazmy wants to merge 1 commit into
mainfrom
pr4751

Conversation

@muhamadazmy
Copy link
Copy Markdown
Contributor

Limit ingress HTTP request body size

Adds a RequestBodyLimitLayer to the ingress HTTP server so oversized
request bodies are rejected with 413 Payload Too Large rather than being
streamed in full.

Introduces a new ingress.request-size-limit config option. It defaults
to (and is clamped at) networking.message-size-limit, since requests
larger than that cap cannot be transmitted over the cluster-internal
network.

Fixes #4153

@muhamadazmy muhamadazmy marked this pull request as ready for review May 18, 2026 14:03
Copy link
Copy Markdown

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

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: d190507bde

ℹ️ 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".

),
)
.layer(NormalizePathLayer::trim_trailing_slash())
.layer(RequestBodyLimitLayer::new(request_size_limit))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Move the body-limit layer inside CORS

When browser clients send an oversized request with a Content-Length header, RequestBodyLimitLayer returns the 413 immediately without calling its inner service. Because CorsLayer::very_permissive() is added after this line (server.rs:180), it is inside the limit layer and never gets a chance to add CORS headers to those early 413 responses, so browser callers cannot observe the intended Payload Too Large response. Place the limit layer inside the CORS layer (or otherwise apply CORS to the early response).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This unfortunately requires this change to be accepted and merged to mainstream tower-http tower-rs/tower-http#679

We can also switch to using my fork for now. But since the chances of sending such a large payload from the browser are minimal, we can just keep using this mainstream tower-http until the PR is approved and merged.

I will leave a todo in code so we keep track of this

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

Test Results

  8 files  ±0    8 suites  ±0   5m 47s ⏱️ +57s
 60 tests ±0   59 ✅  - 1  0 💤 ±0  0 ❌ ±0  1 🔥 +1 
267 runs  ±0  266 ✅  - 1  0 💤 ±0  0 ❌ ±0  1 🔥 +1 

For more details on these errors, see this check.

Results for commit 2d202e8. ± Comparison against base commit 9da7b1a.

♻️ This comment has been updated with latest results.

Adds a `RequestBodyLimitLayer` to the ingress HTTP server so oversized
request bodies are rejected with 413 Payload Too Large rather than being
streamed in full.

Introduces a new `ingress.request-size-limit` config option. It defaults
to (and is clamped at) `networking.message-size-limit`, since requests
larger than that cap cannot be transmitted over the cluster-internal
network.

Fixes #4153
Copy link
Copy Markdown
Contributor

@tillrohrmann tillrohrmann left a comment

Choose a reason for hiding this comment

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

Thanks for enforcing request limits at the ingress @muhamadazmy. The changes look really nice :-) +1 for merging after checking why the e2e tests are failing with this PR.

use restate_types::journal_v2::Signal;
use restate_types::net::address::SocketAddress;

pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you use GenericError, instead?

Comment on lines +1230 to +1232
req.extensions_mut()
.insert(ConnectInfo::new(SocketAddress::Anonymous));
req.extensions_mut().insert(opentelemetry::Context::new());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity: Why are those extensions needed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume the RequestBodyLimitLayer needs those?

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.

Reject ingress messages that are exceeding the message size limit

2 participants