diff --git a/I2PControl.cpp b/I2PControl.cpp index 5e58bb63..30efc9bd 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -125,8 +125,20 @@ namespace client { try { + bool isHtml = !memcmp (buf->data (), "POST", 4); std::stringstream ss; ss.write (buf->data (), bytes_transferred); + if (isHtml) + { + std::string header; + while (!ss.eof () && header != "\r") + std::getline(ss, header); + if (ss.eof ()) + { + LogPrint (eLogError, "Malformed I2PControl request. HTTP header expected"); + return; // TODO: + } + } boost::property_tree::ptree pt; boost::property_tree::read_json (ss, pt); std::string method = pt.get(I2P_CONTROL_PROPERTY_METHOD); @@ -142,7 +154,7 @@ namespace client } std::map results; (this->*(it->second))(params, results); - SendResponse (socket, buf, pt.get(I2P_CONTROL_PROPERTY_ID), results); + SendResponse (socket, buf, pt.get(I2P_CONTROL_PROPERTY_ID), results, isHtml); } else LogPrint (eLogWarning, "Unknown I2PControl method ", method); @@ -160,7 +172,7 @@ namespace client void I2PControlService::SendResponse (std::shared_ptr socket, std::shared_ptr buf, const std::string& id, - const std::map& results) + const std::map& results, bool isHtml) { boost::property_tree::ptree ptr; for (auto& result: results) diff --git a/I2PControl.h b/I2PControl.h index 59aff07b..007ac00e 100644 --- a/I2PControl.h +++ b/I2PControl.h @@ -72,7 +72,7 @@ namespace client std::shared_ptr socket, std::shared_ptr buf); void SendResponse (std::shared_ptr socket, std::shared_ptr buf, const std::string& id, - const std::map& results); + const std::map& results, bool isHtml); void HandleResponseSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, std::shared_ptr socket, std::shared_ptr buf);