From 9a40db34cd48b776023e3558a855458fa4f9d264 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 24 Sep 2021 11:02:21 +0200 Subject: webserver version 1.14: Bugfix: URL decode in static files --- LICENSE.txt | 2 +- Makefile | 2 ++ debian/changelog | 6 ++++++ debian/copyright | 2 +- libcommon/Makefile | 3 ++- libcommon/url.cpp | 32 ++++++++++++++++++++++++++++++++ libcommon/url.h | 6 ++++++ plugins/static-files/static-files.cpp | 3 ++- plugins/webbox/webbox.cpp | 33 ++------------------------------- webserver.1 | 2 +- webserver.conf | 8 ++++++++ 11 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 libcommon/url.cpp create mode 100644 libcommon/url.h diff --git a/LICENSE.txt b/LICENSE.txt index b868bb7..89ed2c4 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2020 Roland Reichwein +Copyright 2021 Roland Reichwein Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/Makefile b/Makefile index 0f214b1..8db9403 100644 --- a/Makefile +++ b/Makefile @@ -165,6 +165,8 @@ DISTFILES= \ libcommon/stringutil.cpp \ libcommon/tempfile.h \ libcommon/tempfile.cpp \ + libcommon/url.h \ + libcommon/url.cpp \ plugins/cgi/cgi.h \ plugins/cgi/Makefile \ plugins/cgi/cgi.cpp \ diff --git a/debian/changelog b/debian/changelog index cb34ab9..ba76792 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +webserver (1.14) unstable; urgency=medium + + * Bugfix: URL decoding in static files plugin + + -- Roland Reichwein Fri, 24 Sep 2021 10:47:07 +0200 + webserver (1.13) unstable; urgency=medium * Code cleanup (Boost tests instead of google tests) diff --git a/debian/copyright b/debian/copyright index 4b3a1b3..8e3ebb6 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,4 +1,4 @@ -This package is Copyright 2020 by Roland Reichwein +This package is Copyright 2021 by Roland Reichwein Both upstream source code and Debian packaging is licensed under the BSD license: diff --git a/libcommon/Makefile b/libcommon/Makefile index d3d781d..ddff9fc 100644 --- a/libcommon/Makefile +++ b/libcommon/Makefile @@ -10,7 +10,8 @@ PROGSRC=\ file.cpp \ mime.cpp \ stringutil.cpp \ - tempfile.cpp + tempfile.cpp \ + url.cpp SRC=$(PROGSRC) diff --git a/libcommon/url.cpp b/libcommon/url.cpp new file mode 100644 index 0000000..5baf603 --- /dev/null +++ b/libcommon/url.cpp @@ -0,0 +1,32 @@ +#include "url.h" + +std::string urlDecode(std::string s) +{ + std::string result; + + size_t pos = 0; + while (pos < s.size()) { + char c {s[pos]}; + if (c == '+') { + result += ' '; + } else if (c == '%' && pos + 2 < s.size()) { + try { + int i = stoi(s.substr(pos + 1, 2), 0, 16); + if (i < 0 || i > 255) + return result; + + result += static_cast(i); + } catch (...) { + return result; + } + + pos += 2; + } else { + result += c; + } + pos++; + } + + return result; +} + diff --git a/libcommon/url.h b/libcommon/url.h new file mode 100644 index 0000000..bd60616 --- /dev/null +++ b/libcommon/url.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +std::string urlDecode(std::string s); + diff --git a/plugins/static-files/static-files.cpp b/plugins/static-files/static-files.cpp index b2dcdca..ad78e48 100644 --- a/plugins/static-files/static-files.cpp +++ b/plugins/static-files/static-files.cpp @@ -1,6 +1,7 @@ #include "static-files.h" #include "libcommon/mime.h" +#include "libcommon/url.h" #include @@ -81,7 +82,7 @@ std::string static_files_plugin::generate_page( if (pos != target.npos) target = target.substr(0, pos); - std::string rel_target{GetRequestParam("rel_target")}; + std::string rel_target{urlDecode(GetRequestParam("rel_target"))}; pos = rel_target.find('?'); if (pos != rel_target.npos) rel_target = rel_target.substr(0, pos); diff --git a/plugins/webbox/webbox.cpp b/plugins/webbox/webbox.cpp index 26d49c8..c8e4b38 100644 --- a/plugins/webbox/webbox.cpp +++ b/plugins/webbox/webbox.cpp @@ -4,6 +4,7 @@ #include "libcommon/tempfile.h" #include "libcommon/file.h" #include "libcommon/stringutil.h" +#include "libcommon/url.h" #include #include @@ -45,36 +46,6 @@ namespace { { "500", "Internal Server Error" } }; - std::string urlDecode(std::string s) - { - std::string result; - - size_t pos = 0; - while (pos < s.size()) { - char c {s[pos]}; - if (c == '+') { - result += ' '; - } else if (c == '%' && pos + 2 < s.size()) { - try { - int i = stoi(s.substr(pos + 1, 2), 0, 16); - if (i < 0 || i > 255) - return result; - - result += static_cast(i); - } catch (...) { - return result; - } - - pos += 2; - } else { - result += c; - } - pos++; - } - - return result; - } - std::unordered_map ParseQueryString(const std::string& s, const std::string& webboxPath) { std::unordered_map result; @@ -376,7 +347,7 @@ protected: virtual std::string start(CommandParameters& p) { p.m_SetResponseHeader("content_type", "text/plain"); - return p.m_GetServerParam("version") + "
(C) 2020 Reichwein.IT"; + return p.m_GetServerParam("version") + "
(C) 2021 Reichwein.IT"; } }; diff --git a/webserver.1 b/webserver.1 index 39da1eb..c1c4245 100644 --- a/webserver.1 +++ b/webserver.1 @@ -1,4 +1,4 @@ -.TH webserver 1 "30 April 2020" "Version 1.3" "Webserver Manual" +.TH webserver 1 "30 April 2021" "Version 1.14" "Webserver Manual" .SH NAME webserver \- A small webserver diff --git a/webserver.conf b/webserver.conf index 9ff0b0e..5e97cd2 100644 --- a/webserver.conf +++ b/webserver.conf @@ -16,6 +16,8 @@ ip6-localhost 127.0.0.1 [::1] + reichwein.mooo.com + [2001:a61:410:c001:5e51:4fff:fea2:ec7f] static-files @@ -133,6 +135,12 @@ marx + +
2001:a61:410:c001:5e51:4fff:fea2:ec7f
+ 80 + http + antcom.de +
::1
8080 -- cgit v1.2.3