Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Desktop: stop the loopback client following redirects (#8421)
Daniel Han501a6ac48e70
diff --git a/studio/src-tauri/src/loopback_http.rs b/studio/src-tauri/src/loopback_http.rsindex 2dec4a633d1..16536849057 100644--- a/studio/src-tauri/src/loopback_http.rs+++ b/studio/src-tauri/src/loopback_http.rs@@ -1,9 +1,15 @@use std::time::Duration;+/// Redirects are refused for the same reason `streaming_client` refuses them, and it matters+/// more here: this is the client that posts `.desktop_secret` to `/api/auth/desktop-login`.+/// reqwest follows up to 10 redirects by default, and its cross-host protection strips headers,+/// not bodies, so a responder answering 307 would carry the secret off-host after the loopback+/// URL had already been checked.pub(crate) fn client(timeout: Duration) -> Result<reqwest::Client, reqwest::Error> {reqwest::Client::builder().no_proxy().timeout(timeout)+ .redirect(reqwest::redirect::Policy::none()).build()}@@ -77,4 +83,39 @@ mod tests {assert!(response.status().is_success());server.join().unwrap();}++ /// The desktop secret rides this client to /api/auth/desktop-login. A 307+ /// preserves the method and body, so a followed redirect would hand the+ /// secret to whatever the Location header names. Refuse instead: the caller+ /// sees the 307 itself and treats it as a failed login.+ #[test]+ fn a_redirect_is_returned_not_followed() {+ let listener = TcpListener::bind("127.0.0.1:0").unwrap();+ let port = listener.local_addr().unwrap().port();+ let server = std::thread::spawn(move || {+ let (mut stream, _) = listener.accept().unwrap();+ let mut discard = [0_u8; 2048];+ let _ = stream.read(&mut discard);+ let _ = stream.write_all(+ b"HTTP/1.1 307 Temporary Redirect\r\nLocation: http://evil.test/collect\r\n\+ Content-Length: 0\r\nConnection: close\r\n\r\n",+ );+ });++ let runtime = tokio::runtime::Runtime::new().unwrap();+ let response = runtime.block_on(async {+ super::client(Duration::from_secs(2))+ .unwrap()+ .post(format!("http://127.0.0.1:{port}/api/auth/desktop-login"))+ .json(&serde_json::json!({ "secret": "desktop-not-a-real-secret" }))+ .send()+ .await+ .unwrap()+ });++ assert_eq!(response.status().as_u16(), 307);+ // Still the port we dialled: nothing was re-sent anywhere else.+ assert_eq!(response.url().port(), Some(port));+ server.join().unwrap();+ }}