transfer: enhance secure check

Introduce `Curl_xfer_is_secure(data)` that returns TRUE for transfers
that happen(ed) over a end-to-end secured connection, e.g. SSL.

Add test1586 to verify behaviour for http: transfers via a https: proxy.

Reported-by: lg_oled77c5pua on hackerone

Closes #20951
This commit is contained in:
Stefan Eissing 2026-03-17 11:40:13 +01:00 committed by Daniel Stenberg
parent f4c0590b1c
commit adda11330b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 104 additions and 6 deletions

View file

@ -903,3 +903,25 @@ CURLcode Curl_xfer_pause_recv(struct Curl_easy *data, bool enable)
Curl_pgrsRecvPause(data, enable);
return result;
}
bool Curl_xfer_is_secure(struct Curl_easy *data)
{
const struct Curl_scheme *scheme = NULL;
if(data->conn) {
scheme = data->conn->scheme;
/* if we are connected, but not use SSL, the transfer is not secure.
* This covers an insecure http:// proxy that is not tunneling.
* We enforce tunneling for such cases, but better be sure here. */
if(Curl_conn_is_connected(data->conn, FIRSTSOCKET) &&
!Curl_conn_is_ssl(data->conn, FIRSTSOCKET))
return FALSE;
}
else if(data->info.conn_scheme) { /* was connected once */
scheme = Curl_get_scheme(data->info.conn_scheme);
}
else { /* never connected (yet?) */
DEBUGASSERT(0); /* not implemented, would need to parse URL */
}
return scheme ? (scheme->flags & PROTOPT_SSL) : FALSE;
}