Skip to content

Commit

Permalink
✅ fix: apply http header error
Browse files Browse the repository at this point in the history
  • Loading branch information
maro5397 committed Dec 17, 2021
1 parent c25891c commit 7375c26
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/captiveportal/captiveportal.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
QT -= gui

CONFIG += c++17
CONFIG += c++2a
TEMPLATE = app
CONFIG += qt

Expand Down
28 changes: 28 additions & 0 deletions app/captiveportal/weuiserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ void WEUIServer::setHttpResponse() {
int size = 0;
DLOG(INFO) << "request path:" << path;

if(path.ends_with(".css")) {
uiresponse_.setHTTPHeader("Content-Type", "text/css;charset=UTF-8");
}
else if(path.ends_with(".js")) {
uiresponse_.setHTTPHeader("Content-Type", "text/javascript;charset=UTF-8");
}
else {
uiresponse_.setHTTPHeader("Content-Type", "text/html");
}

if(denyDotDotPacket(path)) {
return;
}

if(path == "/") {
size = getWebUIData("/index.html");
uiresponse_.setResponseBody(ui_);
Expand Down Expand Up @@ -105,3 +119,17 @@ std::string WEUIServer::getDateTime() {
return dateheader;
}

bool WEUIServer::denyDotDotPacket(std::string path)
{
if(path.find("..") != std::string::npos) {
DLOG(INFO) << "there is .. string from path:" << path;
uiresponse_.setProtocol(HTTP1_1);
uiresponse_.setStatusCode(403);
uiresponse_.setReasonPhrase();
uiresponse_.setHTTPHeader("Date", getDateTime());
uiresponse_.setHTTPHeader("Server", "UIServer");
uiresponse_.makeResponse();
return true;
}
return false;
}
1 change: 1 addition & 0 deletions app/captiveportal/weuiserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ class WEUIServer : public TcpServer
void setHttpResponse();
int getWebUIData(std::string path);
std::string getDateTime();
bool denyDotDotPacket(std::string path);
};
2 changes: 1 addition & 1 deletion app/uiserver-test/uiserver-test.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
QT -= gui

CONFIG += c++20
CONFIG += c++2a
TEMPLATE = app
CONFIG += qt

Expand Down
18 changes: 9 additions & 9 deletions app/uiserver-test/uiserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ void UIServer::setHttpResponse() {
int size = 0;
DLOG(INFO) << "request path:" << path;

// if(path.ends_with(".css")) {
// uiresponse_.setHTTPHeader("Content-Type", "text/css;charset=UTF-8");
// }
// else if(path.ends_with(".js")) {
// uiresponse_.setHTTPHeader("Content-Type", "text/javascript;charset=UTF-8");
// }
// else {
// uiresponse_.setHTTPHeader("Content-Type", "text/html");
// }
if(path.ends_with(".css")) {
uiresponse_.setHTTPHeader("Content-Type", "text/css;charset=UTF-8");
}
else if(path.ends_with(".js")) {
uiresponse_.setHTTPHeader("Content-Type", "text/javascript;charset=UTF-8");
}
else {
uiresponse_.setHTTPHeader("Content-Type", "text/html");
}

if(denyDotDotPacket(path)) {
return;
Expand Down

0 comments on commit 7375c26

Please sign in to comment.