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 --- plugins/static-files/static-files.cpp | 3 ++- plugins/webbox/webbox.cpp | 33 ++------------------------------- 2 files changed, 4 insertions(+), 32 deletions(-) (limited to 'plugins') 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"; } }; -- cgit v1.2.3