Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(router): register MultipartFormConfig so per-field multipart limits are reachable (#13504)

Ayush Anandfffdd136b7ee
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 3dee3cb514..5e23f782dc 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -6589,7 +6589,7 @@
],
"operationId": "Upload a batch blocklist CSV",
"requestBody": {
- "description": "A multipart/form-data request with a `file` field containing a UTF-8 CSV (max 5 MB). The CSV must have a header row: `type,data,metadata`. `type`: one of `card_bin` (6 digits), `extended_card_bin` (8 digits), `fingerprint`. `metadata`: optional, `key=value` pairs separated by `;` (e.g. `reason=fraud;source=manual`). Maximum 100,000 data rows.",
+ "description": "A multipart/form-data request with a `file` field containing a UTF-8 CSV (max 5 MiB). The CSV must have a header row: `type,data,metadata`. `type`: one of `card_bin` (6 digits), `extended_card_bin` (8 digits), `fingerprint`. `metadata`: optional, `key=value` pairs separated by `;` (e.g. `reason=fraud;source=manual`). Maximum 100,000 data rows.",
"content": {
"multipart/form-data": {
"schema": {
@@ -6611,7 +6611,7 @@
}
},
"400": {
- "description": "CSV validation error or file exceeds 5 MB limit"
+ "description": "CSV validation error or file exceeds 5 MiB limit"
}
},
"security": [
diff --git a/crates/openapi/src/routes/blocklist.rs b/crates/openapi/src/routes/blocklist.rs
index 84462416f9..b71b3d865a 100644
--- a/crates/openapi/src/routes/blocklist.rs
+++ b/crates/openapi/src/routes/blocklist.rs
@@ -64,7 +64,7 @@ pub async fn list_blocked_payment_methods() {}
request_body(
content = String,
content_type = "multipart/form-data",
- description = "A multipart/form-data request with a `file` field containing a UTF-8 CSV (max 5 MB). \
+ description = "A multipart/form-data request with a `file` field containing a UTF-8 CSV (max 5 MiB). \
The CSV must have a header row: `type,data,metadata`. \
`type`: one of `card_bin` (6 digits), `extended_card_bin` (8 digits), `fingerprint`. \
`metadata`: optional, `key=value` pairs separated by `;` (e.g. `reason=fraud;source=manual`). \
@@ -72,7 +72,7 @@ pub async fn list_blocked_payment_methods() {}
),
responses(
(status = 202, description = "Batch blocklist job initiated", body = BatchBlocklistUploadResponse),
- (status = 400, description = "CSV validation error or file exceeds 5 MB limit"),
+ (status = 400, description = "CSV validation error or file exceeds 5 MiB limit"),
),
tag = "Blocklist",
operation_id = "Upload a batch blocklist CSV",
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 97135cea11..9d98f6f51d 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -41,6 +41,8 @@ pub const FINGERPRINT_SECRET_LENGTH: usize = 64;
pub const DEFAULT_LIST_API_LIMIT: u16 = 10;
+pub const MULTIPART_MEMORY_LIMIT: usize = 6 * 1024 * 1024;
+
// String literals
pub(crate) const UNSUPPORTED_ERROR_MESSAGE: &str = "Unsupported response type";
diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs
index 5eee82e495..c5e123b634 100644
--- a/crates/router/src/lib.rs
+++ b/crates/router/src/lib.rs
@@ -506,6 +506,9 @@ pub fn get_application_builder(
.content_type_required(true)
.error_handler(utils::error_parser::custom_json_error_handler);
+ let multipart_cfg = actix_multipart::form::MultipartFormConfig::default()
+ .memory_limit(consts::MULTIPART_MEMORY_LIMIT);
+
let request_identifier = router_env::RequestIdentifier::new(&trace_header.header_name)
.use_incoming_id({
#[cfg(feature = "deja")]
@@ -530,6 +533,7 @@ pub fn get_application_builder(
actix_web::App::new()
.app_data(json_cfg)
+ .app_data(multipart_cfg)
.wrap(ErrorHandlers::new().handler(
StatusCode::NOT_FOUND,
errors::error_handlers::custom_error_handlers,
diff --git a/crates/router/src/routes/blocklist.rs b/crates/router/src/routes/blocklist.rs
index 84c15c398b..3c9b72c927 100644
--- a/crates/router/src/routes/blocklist.rs
+++ b/crates/router/src/routes/blocklist.rs
@@ -208,7 +208,9 @@ pub async fn toggle_blocklist_guard(
#[derive(Debug, MultipartForm)]
pub struct BatchBlocklistUploadForm {
- #[multipart(limit = "5MB")]
+ // Also charged against `consts::MULTIPART_MEMORY_LIMIT`, the global in-memory budget for
+ // multipart fields. That global must stay >= this limit, or this one is unreachable.
+ #[multipart(limit = "5MiB")]
pub file: MultipartBytes,
}
@@ -218,7 +220,7 @@ pub struct BatchBlocklistUploadForm {
request_body(
content = String,
content_type = "multipart/form-data",
- description = "A multipart/form-data request with a `file` field containing a UTF-8 CSV (max 5 MB). \
+ description = "A multipart/form-data request with a `file` field containing a UTF-8 CSV (max 5 MiB). \
The CSV must have a header row: `type,data,metadata`. \
`type`: one of `card_bin` (6 digits), `extended_card_bin` (8 digits), `fingerprint`. \
`metadata`: optional, `key=value` pairs separated by `;` (e.g. `reason=fraud;source=manual`). \
@@ -226,7 +228,7 @@ pub struct BatchBlocklistUploadForm {
),
responses(
(status = 202, description = "Batch blocklist job initiated", body = BatchBlocklistUploadResponse),
- (status = 400, description = "CSV validation error or file exceeds 5 MB limit"),
+ (status = 400, description = "CSV validation error or file exceeds 5 MiB limit"),
),
tag = "Blocklist",
operation_id = "Upload a batch blocklist CSV",