From d577b23c9c5b796161d6eec275dd9afd8163a24d Mon Sep 17 00:00:00 2001 From: Daniel Voshart <205798369+voshart@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:53:07 -0500 Subject: [PATCH] Preserve bounded URLs and query-safe error messages --- crates/http-url/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/http-url/src/lib.rs b/crates/http-url/src/lib.rs index 3babf1b13..bae96da5b 100644 --- a/crates/http-url/src/lib.rs +++ b/crates/http-url/src/lib.rs @@ -10,7 +10,10 @@ pub struct Url { impl Url { pub fn parse(s: &str) -> Result { - let bad = |why: &str| HttpError::BadUrl(format!("{s}: {why}")); + let bad = |why: &str| HttpError::BadUrl(why.to_string()); + if s.len() > 16 * 1024 { + return Err(bad("URL exceeds 16 KiB")); + } let s = s.trim(); if s.chars().any(|c| c.is_control() || c == ' ') { return Err(bad("contains spaces or control characters")); @@ -98,6 +101,12 @@ impl Url { mod tests { use super::*; + #[test] + fn rejects_oversized_and_control_character_urls() { + assert!(Url::parse(&format!("https://example.com/{}", "x".repeat(16 * 1024))).is_err()); + assert!(Url::parse("https://example.com/x?secret=abc\r\nInjected: 1").is_err()); + } + #[test] fn parses_urls() { let u = Url::parse("https://cdn.example.com/models/sam3/model.safetensors?sig=1#x").unwrap();