From d3381a1dabe709a9477b0bedf956be491b1c6866 Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Thu, 19 Mar 2026 15:34:53 +0000 Subject: [PATCH] fix: Resolve proxy ip before processing any request (#3006) --- src/web/impl/HttpBase.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/web/impl/HttpBase.hpp b/src/web/impl/HttpBase.hpp index d054d953a..d85323f24 100644 --- a/src/web/impl/HttpBase.hpp +++ b/src/web/impl/HttpBase.hpp @@ -241,6 +241,16 @@ public: if (ec) return httpFail(ec, "read"); + if (auto resolvedIp = proxyIpResolver_->resolveClientIp(clientIp_, req_); + resolvedIp != clientIp_) { + LOG(log_.info()) << tag() + << "Detected a forwarded request from proxy. Proxy ip: " << clientIp_ + << ". Resolved client ip: " << resolvedIp; + dosGuard_.get().decrement(clientIp_); + clientIp_ = std::move(resolvedIp); + dosGuard_.get().increment(clientIp_); + } + if (req_.method() == http::verb::get and req_.target() == "/health") return sender_(httpResponse(http::status::ok, "text/html", kHEALTH_CHECK_HTML)); @@ -256,16 +266,6 @@ public: )); } - if (auto resolvedIp = proxyIpResolver_->resolveClientIp(clientIp_, req_); - resolvedIp != clientIp_) { - LOG(log_.info()) << tag() - << "Detected a forwarded request from proxy. Proxy ip: " << clientIp_ - << ". Resolved client ip: " << resolvedIp; - dosGuard_.get().decrement(clientIp_); - clientIp_ = std::move(resolvedIp); - dosGuard_.get().increment(clientIp_); - } - // Update isAdmin property of the connection ConnectionBase::isAdmin_ = adminVerification_->isAdmin(req_, clientIp_);