From 50fa95b452b48d3890825f79c863abd8f3556dd2 Mon Sep 17 00:00:00 2001 From: alexcastgonz <82875882+pcbeingused333@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:26:33 -0400 Subject: [PATCH] fix(http): do not send Secure cookies over plain http (#840) --- crates/yaak-http/src/cookies.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/yaak-http/src/cookies.rs b/crates/yaak-http/src/cookies.rs index efdddc6f0..c2090b0fe 100644 --- a/crates/yaak-http/src/cookies.rs +++ b/crates/yaak-http/src/cookies.rs @@ -107,6 +107,11 @@ impl CookieStore { return false; } + // Secure cookies are only sent over https (loopback hosts count as secure contexts) + if cookie.secure && url.scheme() != "https" && !is_localhost(&url_host) { + return false; + } + // Check path let url_path = url.path(); @@ -378,6 +383,25 @@ mod tests { assert_eq!(header, Some("session=abc123".to_string())); } + #[test] + fn test_secure_cookie_not_sent_over_http() { + let store = CookieStore::new(); + let https_url = Url::parse("https://example.com/").unwrap(); + store.store_cookies_from_response(&https_url, &["token=abc; Secure".to_string()]); + + // Sent over https + assert_eq!(store.get_cookie_header(&https_url), Some("token=abc".to_string())); + + // Never sent over plain http + let http_url = Url::parse("http://example.com/").unwrap(); + assert!(store.get_cookie_header(&http_url).is_none()); + + // Loopback hosts are treated as a secure context + let local_url = Url::parse("http://localhost:3000/").unwrap(); + store.store_cookies_from_response(&local_url, &["local=1; Secure".to_string()]); + assert_eq!(store.get_cookie_header(&local_url), Some("local=1".to_string())); + } + #[test] fn test_cookie_domain_matching() { let store = CookieStore::new();