From a1be047e7db01c0948f04b5881bc698cc3896fdd Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Fri, 24 Jan 2025 13:36:04 +0530 Subject: [PATCH 1/2] fix: limit JSON payload size to 10MB --- src/handlers/http/modal/ingest_server.rs | 4 +++- src/handlers/http/modal/query_server.rs | 3 ++- src/handlers/http/modal/server.rs | 11 ++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/handlers/http/modal/ingest_server.rs b/src/handlers/http/modal/ingest_server.rs index 215f79478..4c7c09eb7 100644 --- a/src/handlers/http/modal/ingest_server.rs +++ b/src/handlers/http/modal/ingest_server.rs @@ -30,6 +30,7 @@ use crate::handlers::http::logstream; use crate::handlers::http::middleware::DisAllowRootUser; use crate::handlers::http::middleware::RouteExt; use crate::handlers::http::role; +use crate::handlers::http::MAX_EVENT_PAYLOAD_SIZE; use crate::metrics; use crate::migration; use crate::migration::metadata_migration::migrate_ingester_metadata; @@ -249,7 +250,8 @@ impl IngestServer { web::put() .to(ingestor_logstream::put_stream) .authorize_for_stream(Action::CreateStream), - ), + ) + .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), // Required to restrict `PUT /logstream/{logstream}` ) .service( // GET "/logstream/{logstream}/info" ==> Get info for given log stream diff --git a/src/handlers/http/modal/query_server.rs b/src/handlers/http/modal/query_server.rs index 1f375c04b..bef943253 100644 --- a/src/handlers/http/modal/query_server.rs +++ b/src/handlers/http/modal/query_server.rs @@ -275,7 +275,8 @@ impl QueryServer { .to(querier_logstream::delete) .authorize_for_stream(Action::DeleteStream), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), + .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)) // Required to restrict `PUT /logstream/{logstream}` + .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), ) .service( // GET "/logstream/{logstream}/info" ==> Get info for given log stream diff --git a/src/handlers/http/modal/server.rs b/src/handlers/http/modal/server.rs index f26723361..f254e7727 100644 --- a/src/handlers/http/modal/server.rs +++ b/src/handlers/http/modal/server.rs @@ -318,7 +318,8 @@ impl Server { .to(logstream::delete) .authorize_for_stream(Action::DeleteStream), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), + .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)) // Required to restrict `PUT /logstream/{logstream}` + .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), ) .service( // GET "/logstream/{logstream}/info" ==> Get info for given log stream @@ -404,7 +405,7 @@ impl Server { .to(ingest::ingest) .authorize_for_stream(Action::Ingest), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)) + .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)) } // /v1/logs endpoint to be used for OTEL log ingestion only @@ -417,7 +418,7 @@ impl Server { .to(ingest::handle_otel_logs_ingestion) .authorize_for_stream(Action::Ingest), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), + .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), ) .service( web::resource("/metrics") @@ -426,7 +427,7 @@ impl Server { .to(ingest::handle_otel_metrics_ingestion) .authorize_for_stream(Action::Ingest), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), + .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), ) .service( web::resource("/traces") @@ -435,7 +436,7 @@ impl Server { .to(ingest::handle_otel_traces_ingestion) .authorize_for_stream(Action::Ingest), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), + .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), ) } From b952aa6465d898c86939596fe60711ccc668dba5 Mon Sep 17 00:00:00 2001 From: Devdutt Shenoi Date: Fri, 24 Jan 2025 15:18:44 +0530 Subject: [PATCH 2/2] fix: `JsonConfig` set only for ingestion events --- src/handlers/http/modal/ingest_server.rs | 2 -- src/handlers/http/modal/query_server.rs | 1 - src/handlers/http/modal/server.rs | 1 - 3 files changed, 4 deletions(-) diff --git a/src/handlers/http/modal/ingest_server.rs b/src/handlers/http/modal/ingest_server.rs index 4c7c09eb7..ce7ec20b2 100644 --- a/src/handlers/http/modal/ingest_server.rs +++ b/src/handlers/http/modal/ingest_server.rs @@ -30,7 +30,6 @@ use crate::handlers::http::logstream; use crate::handlers::http::middleware::DisAllowRootUser; use crate::handlers::http::middleware::RouteExt; use crate::handlers::http::role; -use crate::handlers::http::MAX_EVENT_PAYLOAD_SIZE; use crate::metrics; use crate::migration; use crate::migration::metadata_migration::migrate_ingester_metadata; @@ -251,7 +250,6 @@ impl IngestServer { .to(ingestor_logstream::put_stream) .authorize_for_stream(Action::CreateStream), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), // Required to restrict `PUT /logstream/{logstream}` ) .service( // GET "/logstream/{logstream}/info" ==> Get info for given log stream diff --git a/src/handlers/http/modal/query_server.rs b/src/handlers/http/modal/query_server.rs index bef943253..7f58622a3 100644 --- a/src/handlers/http/modal/query_server.rs +++ b/src/handlers/http/modal/query_server.rs @@ -275,7 +275,6 @@ impl QueryServer { .to(querier_logstream::delete) .authorize_for_stream(Action::DeleteStream), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)) // Required to restrict `PUT /logstream/{logstream}` .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), ) .service( diff --git a/src/handlers/http/modal/server.rs b/src/handlers/http/modal/server.rs index f254e7727..f9654d757 100644 --- a/src/handlers/http/modal/server.rs +++ b/src/handlers/http/modal/server.rs @@ -318,7 +318,6 @@ impl Server { .to(logstream::delete) .authorize_for_stream(Action::DeleteStream), ) - .app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)) // Required to restrict `PUT /logstream/{logstream}` .app_data(web::JsonConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)), ) .service(