Skip to content

fix: enforce request body size limit during buffering in AiProxyPlugin - #6897

Open
wy471x wants to merge 2 commits into
apache:masterfrom
wy471x:fix_AiProxyPlugin-validates-body-size
Open

fix: enforce request body size limit during buffering in AiProxyPlugin#6897
wy471x wants to merge 2 commits into
apache:masterfrom
wy471x:fix_AiProxyPlugin-validates-body-size

Conversation

@wy471x

@wy471x wy471x commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Use DataBufferUtils.join with maxSize to prevent OOM from large request bodies. Previously the full body was buffered into memory before the size check ran, allowing a multi-GB payload to exhaust heap. Now DataBufferLimitException is raised during buffering and returned as 413.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

Summary

  • Replaced DataBufferUtils.join(exchange.getRequest().getBody()) (no max size) with DataBufferUtils.join(exchange.getRequest().getBody(), MAX_REQUEST_BODY_SIZE_BYTES). This makes
    Spring's DataBufferUtils enforce the 5 MB limit during buffering — a DataBufferLimitException is thrown immediately when the limit is exceeded, rather than buffering the entire
    multi-GB body into heap first. Added .onErrorResume(DataBufferLimitException.class, ...) to catch that exception and return HTTP 413. Removed the now-redundant post-buffer size
    check.
  • Added testRequestBodyExceedsMaxSize which mocks DataBufferUtils.join to return Mono.error(new DataBufferLimitException(...)) and asserts the response status is 413
    PAYLOAD_TOO_LARGE.

close #6837

wy471x and others added 2 commits August 6, 2026 22:45
Use DataBufferUtils.join with maxSize to prevent OOM from large request
bodies. Previously the full body was buffered into memory before the
size check ran, allowing a multi-GB payload to exhaust heap. Now
DataBufferLimitException is raised during buffering and returned as 413.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

[BUG] AiProxyPlugin validates body size AFTER unbounded DataBufferUtils.join — OOM before 413

1 participant