cookie: use origin scheme for secure context check

`Curl_secure_context()` checked `conn->scheme` to determine if Secure
cookies may be sent. Since 73daec6, `conn->scheme` is set to the proxy's
scheme when using an HTTPS forwarding proxy, causing the function to
return TRUE for HTTP origins. This leaked Secure cookies over the
plaintext connection between proxy and origin.

Use `data->state.origin->scheme` instead, which always reflects the
origin's scheme regardless of proxy configuration.

Not an approved vulnerability because the regression was introduced
after the last release and is not present in any released version.

Verified by test 3401

Follow-up to 73daec6620
Reported-by: daviey on hackerone
URL: https://hackerone.com/reports/3803415
Closes #22024
This commit is contained in:
Dave Walker 2026-06-15 12:57:42 +01:00 committed by Daniel Stenberg
parent 50ffc359e9
commit b9702f8c48
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 64 additions and 11 deletions

View file

@ -29,6 +29,7 @@
#include "cookie.h"
#include "psl.h"
#include "curl_trc.h"
#include "transfer.h"
#include "slist.h"
#include "curl_share.h"
#include "strcase.h"
@ -1268,9 +1269,9 @@ static int cookie_sort_ct(const void *p1, const void *p2)
return (c2->creationtime > c1->creationtime) ? 1 : -1;
}
bool Curl_secure_context(const struct connectdata *conn, const char *host)
bool Curl_secure_context(struct Curl_easy *data, const char *host)
{
return conn->scheme->protocol & (CURLPROTO_HTTPS | CURLPROTO_WSS) ||
return Curl_xfer_is_secure(data) ||
curl_strequal("localhost", host) ||
!strcmp(host, "127.0.0.1") ||
!strcmp(host, "::1");
@ -1280,15 +1281,13 @@ bool Curl_secure_context(const struct connectdata *conn, const char *host)
* Curl_cookie_getlist
*
* For a given host and path, return a linked list of cookies that the client
* should send to the server if used now. The secure boolean informs the cookie
* if a secure connection is achieved or not.
* should send to the server if used now.
*
* It shall only return cookies that have not expired.
*
* 'okay' is TRUE when there is a list returned.
*/
CURLcode Curl_cookie_getlist(struct Curl_easy *data,
const struct connectdata *conn,
bool *okay,
const char *host,
struct Curl_llist *list)
@ -1297,7 +1296,7 @@ CURLcode Curl_cookie_getlist(struct Curl_easy *data,
const bool is_ip = Curl_host_is_ipnum(host);
const size_t myhash = cookiehash(host);
struct Curl_llist_node *n;
const bool secure = Curl_secure_context(conn, host);
const bool secure = Curl_secure_context(data, host);
struct CookieInfo *ci = data->cookies;
const char *path = data->state.up.path;
CURLcode result = CURLE_OK;