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.

fix(image_proxy): allow octet stream (#3628)

Will Hutchinsonfeaa46a2cc08
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 bdb35f731a..c8e7230473 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
@@ -202,13 +202,24 @@ fn extract_content_type(response: &reqwest::Response) -> Result<String, ProxyErr
.unwrap_or("application/octet-stream")
.to_string();
- if !content_type.starts_with("image/") {
+ if !is_allowed_content_type(&content_type) {
return Err(ProxyError::NotAnImage(content_type));
}
Ok(content_type)
}
+fn is_allowed_content_type(content_type: &str) -> bool {
+ let media_type = content_type
+ .split(';')
+ .next()
+ .unwrap_or(content_type)
+ .trim()
+ .to_ascii_lowercase();
+
+ media_type.starts_with("image/") || media_type == "application/octet-stream"
+}
+
fn check_content_length(
response: &reqwest::Response,
original_url: &str,
diff --git a/rust/cloud-storage/image_proxy_service/src/api/proxy/test.rs b/rust/cloud-storage/image_proxy_service/src/api/proxy/test.rs
index af45aa98b4..5f2737ff1a 100644
--- a/rust/cloud-storage/image_proxy_service/src/api/proxy/test.rs
+++ b/rust/cloud-storage/image_proxy_service/src/api/proxy/test.rs
@@ -45,6 +45,27 @@ fn test_validate_url_strips_fragment() {
assert_eq!(result.unwrap().as_str(), "https://example.com/image.png");
}
+#[test]
+fn test_allows_image_content_types() {
+ assert!(is_allowed_content_type("image/png"));
+ assert!(is_allowed_content_type("image/jpeg; charset=utf-8"));
+}
+
+#[test]
+fn test_allows_octet_stream_content_type() {
+ assert!(is_allowed_content_type("application/octet-stream"));
+ assert!(is_allowed_content_type(
+ "application/octet-stream; charset=binary"
+ ));
+ assert!(is_allowed_content_type("APPLICATION/OCTET-STREAM"));
+}
+
+#[test]
+fn test_rejects_non_image_content_types() {
+ assert!(!is_allowed_content_type("text/html"));
+ assert!(!is_allowed_content_type("application/json"));
+}
+
#[test]
fn test_is_private_ip_loopback() {
assert!(is_private_ip(&"127.0.0.1".parse().unwrap()));