Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(image_proxy_service): max content length (#1727)

Will Hutchinson0b38e6ee4351
diff --git a/rust/cloud-storage/image_proxy_service/src/api/proxy/mod.rs b/rust/cloud-storage/image_proxy_service/src/api/proxy/mod.rs
index bf82a9cb55..2126316dc6 100644
--- a/rust/cloud-storage/image_proxy_service/src/api/proxy/mod.rs
+++ b/rust/cloud-storage/image_proxy_service/src/api/proxy/mod.rs
@@ -7,6 +7,9 @@ use reqwest::StatusCode;
use serde::Deserialize;
use utoipa::ToSchema;
+/// 5 MB max image size
+const MAX_IMAGE_SIZE: u64 = 5 * 1024 * 1024;
+
#[derive(Debug, ToSchema, Deserialize)]
pub struct ProxyParams {
pub url: String,
@@ -49,9 +52,24 @@ pub async fn proxy_request_handler(
.unwrap_or("application/octet-stream")
.to_string();
+ let content_length = response
+ .headers()
+ .get(reqwest::header::CONTENT_LENGTH)
+ .and_then(|v| v.to_str().ok())
+ .and_then(|v| v.parse::<u64>().ok());
+
+ tracing::info!(content_length=?content_length.unwrap_or(0), content_type=%content_type, "image content length");
+
+ if content_length.is_some_and(|len| len > MAX_IMAGE_SIZE) {
+ return Err((
+ StatusCode::UNPROCESSABLE_ENTITY,
+ format!("image exceeds max size of {MAX_IMAGE_SIZE} bytes"),
+ ));
+ }
+
if !content_type.starts_with("image/") {
return Err((
- StatusCode::BAD_REQUEST,
+ StatusCode::UNSUPPORTED_MEDIA_TYPE,
format!("upstream content-type is not an image: {content_type}"),
));
}