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.
This commit is contained in:
l0ng-ai
2026-11-16 18:30:06 +08:00
committed by GitHub
parent 39c0f6676e
commit 7cc100367d
2 changed files with 16 additions and 3 deletions
+5 -2
View File
@@ -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,
}))
+11 -1
View File
@@ -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<HttpExchange> {
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<HttpExchange> {
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<H
url: request.url.clone(),
status: response.as_ref().map(|r| r.status),
total_ms: response.as_ref().map(|r| r.total_ms),
file: input.file.map(IpcPath::from),
file: file.map(IpcPath::from),
error,
},
request,