From ab084e7319c7c4a3438c811d0c74b5e180bacb50 Mon Sep 17 00:00:00 2001 From: safa Date: Thu, 19 Nov 2026 03:32:12 +0530 Subject: [PATCH] lib/fetch: don't forward credentials on cross-host redirects http_request copied the user and password of the current URL into any redirect target without credentials of its own, so a redirect to another host received them, and a redirect to ftp:// sent them as USER/PASS. Only copy them if the host matches, like FreeBSD's libfetch does. --- lib/fetch/http.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fetch/http.c b/lib/fetch/http.c index 2e48a736..baae1820 100644 --- a/lib/fetch/http.c +++ b/lib/fetch/http.c @@ -1107,7 +1107,9 @@ http_request(struct url *URL, const char *op, struct url_stat *us, /* XXX should set an error code */ goto ouch; } - if (!*new->user && !*new->pwd) { + /* Only copy credentials if the host matches */ + if (strcmp(new->host, url->host) == 0 && + !*new->user && !*new->pwd) { strcpy(new->user, url->user); strcpy(new->pwd, url->pwd); }