[model-gateway] fix WASM unbounded request/response body read vuln (#14612)

This commit is contained in:
Simo Lin
2025-12-07 20:47:25 -08:00
committed by GitHub
parent c08b780fe0
commit 2970f22917
3 changed files with 65 additions and 3 deletions
+3 -2
View File
@@ -612,7 +612,8 @@ pub async fn wasm_middleware(
let method = request.method().clone();
let uri = request.uri().clone();
let mut headers = request.headers().clone();
let body_bytes = match axum::body::to_bytes(request.into_body(), usize::MAX).await {
let max_body_size = wasm_manager.get_max_body_size();
let body_bytes = match axum::body::to_bytes(request.into_body(), max_body_size).await {
Ok(bytes) => bytes.to_vec(),
Err(e) => {
error!("Failed to read request body: {}", e);
@@ -708,7 +709,7 @@ pub async fn wasm_middleware(
// Extract response data once before processing modules
let mut status = response.status();
let mut headers = response.headers().clone();
let mut body_bytes = match axum::body::to_bytes(response.into_body(), usize::MAX).await {
let mut body_bytes = match axum::body::to_bytes(response.into_body(), max_body_size).await {
Ok(bytes) => bytes.to_vec(),
Err(e) => {
error!("Failed to read response body: {}", e);