mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-23 11:54:42 +00:00
Refuse a proxied path that does not start with a slash (#2638)
In absolute-form the path follows the authority, so a path such as "@evil.example/x" made the proxy connect to another host and forward the origin's credentials. Both handle_request and open_stream_ now refuse such a path before anything is written.
This commit is contained in:
1 parent
b4b24589ad
commit
276cf08e84
2 files changed
+42
-2
No files matched your search
@@ -15942,8 +15942,11 @@ inline ClientImpl::StreamHandle ClientImpl::open_stream_(Request &req) {
|
||||
{
|
||||
detail::BufferStream bstrm;
|
||||
|
||||
if (detail::write_request_line(bstrm, req.method,
|
||||
proxy_target_prefix() + req.path) < 0) {
|
||||
// The path follows the authority in absolute-form, so one that does not
|
||||
// begin with '/' (e.g. "@evil.example/x") would name another host.
|
||||
auto prefix = proxy_target_prefix();
|
||||
if ((!prefix.empty() && req.path[0] != '/') ||
|
||||
detail::write_request_line(bstrm, req.method, prefix + req.path) < 0) {
|
||||
handle.error = Error::Write;
|
||||
handle.response.reset();
|
||||
return handle;
|
||||
@@ -16248,6 +16251,13 @@ inline bool ClientImpl::handle_request(Stream &strm, Request &req,
|
||||
|
||||
auto prefix = proxy_target_prefix();
|
||||
if (!prefix.empty()) {
|
||||
// The path follows the authority in absolute-form, so one that does not
|
||||
// begin with '/' (e.g. "@evil.example/x") would name another host.
|
||||
if (req.path[0] != '/') {
|
||||
error = Error::Write;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto req2 = req;
|
||||
req2.path = prefix + req.path;
|
||||
ret = process_request(strm, req2, res, close_connection, error);
|
||||
|
||||
Reference in new issue
Block a user