mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
reject trailing bytes after IPv6 host literal in parse_url (#2536)
This commit is contained in:
1 parent
1e9d6f0b0b
commit
2d8e49dd9b
2 files changed
+26
No files matched your search
@@ -851,6 +851,15 @@ inline bool parse_url(const std::string &url, UrlComponents &uc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos = close + 1;
|
pos = close + 1;
|
||||||
|
|
||||||
|
// The IPv6 literal is the whole host, so ']' must be followed by a port,
|
||||||
|
// path, query or fragment delimiter (or the end of input). Otherwise the
|
||||||
|
// trailing bytes would be folded into the path while the connection
|
||||||
|
// still targets the bracketed address.
|
||||||
|
if (pos < url.size() && url[pos] != ':' && url[pos] != '/' &&
|
||||||
|
url[pos] != '?' && url[pos] != '#') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
auto end = url.find_first_of(":/?#", pos);
|
auto end = url.find_first_of(":/?#", pos);
|
||||||
if (end == std::string::npos) { end = url.size(); }
|
if (end == std::string::npos) { end = url.size(); }
|
||||||
|
|||||||
@@ -15563,6 +15563,23 @@ TEST(ParseUrlTest, VariousPatterns) {
|
|||||||
detail::UrlComponents uc;
|
detail::UrlComponents uc;
|
||||||
ASSERT_FALSE(detail::parse_url("http://[::1/path", uc));
|
ASSERT_FALSE(detail::parse_url("http://[::1/path", uc));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// Bytes after the IPv6 literal must be a delimiter, not folded into
|
||||||
|
// the path while the connection still targets the bracketed host.
|
||||||
|
detail::UrlComponents uc;
|
||||||
|
ASSERT_FALSE(detail::parse_url("http://[::1]evil.com/", uc));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
detail::UrlComponents uc;
|
||||||
|
ASSERT_FALSE(detail::parse_url("http://[::1]evil", uc));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
detail::UrlComponents uc;
|
||||||
|
ASSERT_TRUE(detail::parse_url("http://[::1]/path", uc));
|
||||||
|
EXPECT_EQ("::1", uc.host);
|
||||||
|
EXPECT_TRUE(uc.port.empty());
|
||||||
|
EXPECT_EQ("/path", uc.path);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
detail::UrlComponents uc;
|
detail::UrlComponents uc;
|
||||||
ASSERT_TRUE(detail::parse_url("//example.com/path?q=1", uc));
|
ASSERT_TRUE(detail::parse_url("//example.com/path?q=1", uc));
|
||||||
|
|||||||
Reference in new issue
Block a user