From 7cc100367ded342c7b8cb2134c2e5bbd43a7b87d Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 16 Nov 2026 18:30:06 +0800 Subject: [PATCH] fix(mcp): http_run_request sends the request the user approved (#3733) The tool prepared the request to show its resolved URL in the confirmation, then prepared it again to send it, re-reading the environment files: changed in the meantime, they could send the private-environment headers to a destination the user never approved. ide_http::send now sends a prepared request as is, and the tool sends exactly the one it showed. --- crates/ide-host/src/mcp/http.rs | 7 +++++-- crates/ide-http/src/lib.rs | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/ide-host/src/mcp/http.rs b/crates/ide-host/src/mcp/http.rs index ead853482..4ed75b530 100644 --- a/crates/ide-host/src/mcp/http.rs +++ b/crates/ide-host/src/mcp/http.rs @@ -167,7 +167,10 @@ The `url` field in the result is as written in the file (unsubstituted); transpo } call.confirm(&subject, Some(detail)).await?; - let exchange = ide_http::run(input, &call.cancel).await?; + // Exactly the request the user approved: preparing it again would read the + // environment files again, which may name another destination by now. + let redact_url = prepared.url.clone(); + let exchange = ide_http::send(prepared, Some(&path), &call.cancel).await?; let history = call.project().http_history.clone(); let saved = exchange.clone(); let _ = call.host().blocking(move || history.add(&saved)).await; @@ -188,7 +191,7 @@ The `url` field in the result is as written in the file (unsubstituted); transpo "status": response.map(|r| r.status), "statusText": response.map(|r| r.status_text.clone()), "totalMs": response.map(|r| r.total_ms).or(exchange.entry.total_ms), - "error": redact_transport_error(exchange.entry.error.clone(), &prepared.url), + "error": redact_transport_error(exchange.entry.error.clone(), &redact_url), "body": body, "bodyTruncated": body_truncated, })) diff --git a/crates/ide-http/src/lib.rs b/crates/ide-http/src/lib.rs index 91e88473f..2ccfb7385 100644 --- a/crates/ide-http/src/lib.rs +++ b/crates/ide-http/src/lib.rs @@ -34,6 +34,16 @@ pub struct RunInput<'a> { /// variables, missing includes) fail; transport errors are part of the exchange. pub async fn run(input: RunInput<'_>, cancel: &CancellationToken) -> IdeResult { let request = prepare(&input)?; + send(request, input.file, cancel).await +} + +/// Sends an already prepared request (one the user approved as shown); `file` is the +/// request file it came from, for the history. +pub async fn send( + request: PreparedRequest, + file: Option<&Path>, + cancel: &CancellationToken, +) -> IdeResult { let time_ms = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .map(|d| d.as_secs_f64() * 1000.0) @@ -57,7 +67,7 @@ pub async fn run(input: RunInput<'_>, cancel: &CancellationToken) -> IdeResult