Refuse a bare host:port Location in ClientImpl::redirect (#2684)

ClientImpl::redirect() resolved a Location with resolve_relative_location(), which hands a value with a ':' in its first segment back unchanged as having a scheme, and then parsed it with parse_url(), which also accepts a bare host[:port] so that Client("localhost:8080") works. A Location such as "internal:8080" or "127.0.0.1:6379" therefore came out with an empty scheme and a host, slipped past the http/https check, and was followed as a cross-host redirect to that host and port. A value such as "localhost:8080/x" was sent to the same host as a path without a leading '/'.

Follow only http/https URLs and references starting with '/', and refuse anything else, as an unsupported scheme already was. Network-path references such as "//host:port/x" are still followed.
This commit is contained in:
metsw24-max authored and GitHub committed 2026-11-19 16:32:58 -05:00
1 parent 3544f47edd
commit e7a004f509
2 files changed
+67 -7

No files matched your search

+6 -7
View File
@@ -16601,14 +16601,13 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
auto location = res.get_header_value("location");
if (location.empty()) { return false; }
detail::UrlComponents uc;
if (!detail::parse_url(detail::resolve_relative_location(location, req.path),
uc)) {
return false;
}
auto next_url = detail::resolve_relative_location(location, req.path);
// Only follow http/https redirects
if (!uc.scheme.empty() && uc.scheme != "http" && uc.scheme != "https") {
detail::UrlComponents uc;
if (!detail::parse_url(next_url, uc)) { return false; }
// Follow only http/https URLs and references starting with '/'
if (next_url[0] != '/' && uc.scheme != "http" && uc.scheme != "https") {
return false;
}