shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[Task] Add response body size limit in SwaggerImportServiceImpl.fetchSwaggerDoc()

Open Aias00 opened this issue 5 months ago β€’ 2 comments

Description

SwaggerImportServiceImpl.fetchSwaggerDoc() uses response.body().string() to read the full HTTP response into memory without any size constraint. On the MCP import path, the response is subsequently parsed three times (Gson + OpenAPIV3Parser + JsonParser), multiplying memory usage. An authenticated Admin user can supply a URL pointing to a large file, causing JVM heap exhaustion and crashing the Admin process. Affected File:

shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SwaggerImportServiceImpl.java Proposed Change:

Replace the unbounded response.body().string() call with a size-limited counted read: javaprivate static final long MAX_SWAGGER_BODY_BYTES = 10L * 1024 * 1024; // 10 MB

private String fetchSwaggerDoc(final String swaggerUrl) throws IOException { // Check Content-Length header first, then count bytes during streaming read // Throw IllegalArgumentException if limit exceeded } Acceptance Criteria:

Requests to /swagger/import or /swagger/import/mcp with a URL pointing to a file larger than the configured limit return a 400 Bad Request response. The size limit is configurable via application.yml. Legitimate Swagger/OpenAPI documents within the size limit are imported without issue.

Task List

No response

Aias00 avatar Jun 26 '26 10:06 Aias00

πŸ‘‹ Hello @Aias00

A new issue has been opened by @Aias00:

  • Title: [Task] Add response body size limit in SwaggerImportServiceImpl.fetchSwaggerDoc()
  • Link: https://github.com/apache/shenyu/issues/6401

Please review when you have time. Thank you! πŸ™

github-actions[bot] avatar Jun 26 '26 11:06 github-actions[bot]

Hello, I'd like to handle this taskπŸ˜„

SouthwestAsiaFloat avatar Jun 26 '26 15:06 SouthwestAsiaFloat