diff --git a/src/RESTAPI/RESTAPI_subuser_handler.cpp b/src/RESTAPI/RESTAPI_subuser_handler.cpp index 13eb705..82dce45 100644 --- a/src/RESTAPI/RESTAPI_subuser_handler.cpp +++ b/src/RESTAPI/RESTAPI_subuser_handler.cpp @@ -150,9 +150,7 @@ namespace OpenWifi { } if(GetBoolParameter("resetMFA")) { - if(Request->getContentLength()>0) { - std::ignore = ParseStream(); - } + DrainBody(); if( (UserInfo_.userinfo.userRole == SecurityObjects::ROOT) || (UserInfo_.userinfo.userRole == SecurityObjects::ADMIN && Existing.userRole!=SecurityObjects::ROOT) || (UserInfo_.userinfo.id == Id)) { @@ -177,9 +175,7 @@ namespace OpenWifi { } if(GetBoolParameter("forgotPassword")) { - if(Request->getContentLength()>0) { - std::ignore = ParseStream(); - } + DrainBody(); Existing.changePassword = true; Logger_.information(fmt::format("FORGOTTEN-PASSWORD({}): Request for {}", Request->clientAddress().toString(), Existing.email)); diff --git a/src/RESTAPI/RESTAPI_user_handler.cpp b/src/RESTAPI/RESTAPI_user_handler.cpp index 62bf837..fe7e222 100644 --- a/src/RESTAPI/RESTAPI_user_handler.cpp +++ b/src/RESTAPI/RESTAPI_user_handler.cpp @@ -149,6 +149,7 @@ namespace OpenWifi { SecurityObjects::UserInfo Existing; if(!StorageService()->UserDB().GetUserById(Id,Existing)) { + DrainBody(); return NotFound(); } @@ -157,9 +158,7 @@ namespace OpenWifi { } if(GetBoolParameter("resetMFA")) { - if(Request->getContentLength()>0) { - std::ignore = ParseStream(); - } + DrainBody(); if( (UserInfo_.userinfo.userRole == SecurityObjects::ROOT) || (UserInfo_.userinfo.userRole == SecurityObjects::ADMIN && Existing.userRole!=SecurityObjects::ROOT) || (UserInfo_.userinfo.id == Id)) { @@ -184,9 +183,7 @@ namespace OpenWifi { } if(GetBoolParameter("forgotPassword")) { - if(Request->getContentLength()>0) { - std::ignore = ParseStream(); - } + DrainBody(); Existing.changePassword = true; Logger_.information(fmt::format("FORGOTTEN-PASSWORD({}): Request for {}", Request->clientAddress().toString(), Existing.email)); SecurityObjects::ActionLink NewLink; diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index f16908a..a02eb01 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -2011,7 +2011,13 @@ namespace OpenWifi { return false; } - inline void SetCommonHeaders(bool CloseConnection=false) { + void DrainBody() { + if (Request->getContentLength() > 0) { + std::ignore = ParseStream(); + } + } + + inline void SetCommonHeaders(bool CloseConnection=false) { Response->setVersion(Poco::Net::HTTPMessage::HTTP_1_1); Response->setChunkedTransferEncoding(true); Response->setContentType("application/json");