Reject userinfo and backslashes in a URL authority

parse_url took http://user@evil.com/ for the host "user@evil.com", where
parsers that honour userinfo, or read a backslash as '/', see evil.com.
userinfo is not supported, so reject both.
This commit is contained in:
yhirose committed 2026-10-16 16:39:00 -04:00
1 parent eeaae4bc3c
commit aaccde2122
2 files changed
+14 -5

No files matched your search

+6
View File
@@ -889,6 +889,12 @@ inline bool parse_url(const std::string &url, UrlComponents &uc) {
auto has_authority = has_authority_prefix || (!url.empty() && url[0] != '/' &&
url[0] != '?' && url[0] != '#');
if (has_authority) {
// userinfo is not supported, and a backslash that some parsers take for
// '/' would leave them seeing another host than this one.
if (url.find_first_of("@\\", pos) < url.find_first_of("/?#", pos)) {
return false;
}
if (pos < url.size() && url[pos] == '[') {
auto close = url.find(']', pos);
if (close == std::string::npos) { return false; }