fix(admin): enforce response body size limit on automatic swagger doc pull - #6458
Merged
dengliming merged 7 commits intoJul 30, 2026
Merged
Conversation
wy471x
force-pushed
the
fix_SwaggerImportNoResponseBodySizeLimt
branch
from
July 26, 2026 11:50
668dbff to
6ed5455
Compare
Contributor
|
hi, sorry to bother. i forget have you ever add my wechat: aias00? |
Aias00
previously approved these changes
Jul 27, 2026
Member
|
@wy471x Could you please resolve this conflict? |
…ResponseBodySizeLimt # Conflicts: # shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImplTest.java
Contributor
Author
I have resolved the conflict. |
dengliming
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PullSwaggerDocServiceImpl previously called response.body().string() with no size limit, allowing a malicious upstream to exhaust admin memory. Extract readLimitedResponseBody to a public static method in HttpUtils with Content-Length pre-check and streaming byte-count enforcement, reuse it in both SwaggerImportServiceImpl and PullSwaggerDocServiceImpl, and gate it with the existing shenyu.swagger.max-body-size property (default 10 MB).
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary of all changes:
Problem
PullSwaggerDocServiceImpl called response.body().string() directly, loading the entire
upstream API document response into memory with no size limit. A malicious or
misconfigured upstream could cause excessive memory usage in shenyu-admin.
Solution
3 production files changed, 2 test files changed:
(moved from SwaggerImportServiceImpl where it was private). Implements two-layer
defense: early rejection via Content-Length header check, and streaming byte-count
enforcement. Pre-allocates ByteArrayOutputStream when contentLength is known to avoid
repeated buffer resizing.
instead of the removed private method. Removed unused imports, the READ_BUFFER_SIZE
constant, and the dead DEFAULT_MAX_SWAGGER_BODY_SIZE constant.
@value("${shenyu.swagger.max-body-size:10485760}") injection and replaced
response.body().string() with HttpUtils.readLimitedResponseBody(response.body(),
maxSwaggerBodySize). Oversized responses are caught by the existing catch (Exception
e) block and logged gracefully.
exact-limit boundary, Content-Length rejection, streaming rejection, null body,
negative max size, charset handling (ISO-8859-1), and default UTF-8 fallback.
the now-deleted private method (covered by HttpUtilsTest). Moved service creation to
@beforeeach with ReflectionTestUtils.setField to simulate Spring injection of the
default 10 MB limit.
close #6444