Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increase DefaultBodyLimit to prevent large payload failures #409

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion crates/pop-cli/src/wallet_integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use axum::{
extract::DefaultBodyLimit,
http::HeaderValue,
response::Html,
routing::{get, post},
Expand All @@ -13,6 +14,8 @@ use tokio::{
};
use tower_http::{cors::Any, services::ServeDir};

const MAX_PAYLOAD_SIZE: usize = 15 * 1024 * 1024;

/// Make frontend sourcing more flexible by allowing a custom route to be defined.
pub trait Frontend {
/// Serves the content via a [Router].
Expand Down Expand Up @@ -116,7 +119,8 @@ impl WalletIntegrationManager {
.route("/error", post(routes::error_handler).with_state(state.clone()))
.route("/terminate", post(routes::terminate_handler).with_state(state.clone()))
.merge(frontend.serve_content()) // Custom route for serving frontend.
.layer(cors);
.layer(cors)
.layer(DefaultBodyLimit::max(MAX_PAYLOAD_SIZE));

let url_owned = server_url.to_string();

Expand Down Expand Up @@ -546,6 +550,33 @@ mod tests {
assert_eq!(actual_payload.chain_rpc, expected_payload.chain_rpc);
assert_eq!(actual_payload.call_data, call_data_5mb);

let encoded_payload: String = call_data_5mb.iter().map(|b| format!("{:02x}", b)).collect();
let client = reqwest::Client::new();
let response = client
.post(&format!("{}/submit", addr))
.json(&encoded_payload)
.send()
.await
.expect("Failed to send large payload");

assert!(response.status().is_success());
let error = wim.take_error().await;
assert!(error.is_none());

let call_data_15mb = vec![99u8; MAX_PAYLOAD_SIZE + 1];
let encoded_oversized_payload: String =
call_data_15mb.iter().map(|b| format!("{:02x}", b)).collect();
let response = client
.post(&format!("{}/submit", addr))
.json(&encoded_oversized_payload)
.send()
.await;

assert!(
response.is_err() ||
response.unwrap().status() == reqwest::StatusCode::PAYLOAD_TOO_LARGE
);

wim.terminate().await.expect("Termination should not fail.");
assert!(wim.task_handle.await.is_ok());
}
Expand Down
Loading