Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Fix request parameters are url-decoded twice.
Fix post form request not handled correctly.
  • Loading branch information
tindy2013 committed Dec 6, 2023
1 parent 043c1fd commit 13623d6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/handler/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,12 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
readConf();

/// string values
std::string argUrl = urlDecode(getUrlArg(argument, "url"));
std::string argGroupName = urlDecode(getUrlArg(argument, "group")), argUploadPath = getUrlArg(argument, "upload_path");
std::string argIncludeRemark = urlDecode(getUrlArg(argument, "include")), argExcludeRemark = urlDecode(getUrlArg(argument, "exclude"));
std::string argCustomGroups = urlSafeBase64Decode(getUrlArg(argument, "groups")), argCustomRulesets = urlSafeBase64Decode(getUrlArg(argument, "ruleset")), argExternalConfig = urlDecode(getUrlArg(argument, "config"));
std::string argDeviceID = getUrlArg(argument, "dev_id"), argFilename = urlDecode(getUrlArg(argument, "filename")), argUpdateInterval = getUrlArg(argument, "interval"), argUpdateStrict = getUrlArg(argument, "strict");
std::string argRenames = urlDecode(getUrlArg(argument, "rename")), argFilterScript = urlDecode(getUrlArg(argument, "filter_script"));
std::string argUrl = getUrlArg(argument, "url");
std::string argGroupName = getUrlArg(argument, "group"), argUploadPath = getUrlArg(argument, "upload_path");
std::string argIncludeRemark = getUrlArg(argument, "include"), argExcludeRemark = getUrlArg(argument, "exclude");
std::string argCustomGroups = urlSafeBase64Decode(getUrlArg(argument, "groups")), argCustomRulesets = urlSafeBase64Decode(getUrlArg(argument, "ruleset")), argExternalConfig = getUrlArg(argument, "config");
std::string argDeviceID = getUrlArg(argument, "dev_id"), argFilename = getUrlArg(argument, "filename"), argUpdateInterval = getUrlArg(argument, "interval"), argUpdateStrict = getUrlArg(argument, "strict");
std::string argRenames = getUrlArg(argument, "rename"), argFilterScript = getUrlArg(argument, "filter_script");

/// switches with default value
tribool argUpload = getUrlArg(argument, "upload"), argEmoji = getUrlArg(argument, "emoji"), argAddEmoji = getUrlArg(argument, "add_emoji"), argRemoveEmoji = getUrlArg(argument, "remove_emoji");
Expand Down Expand Up @@ -701,7 +701,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)

ProxyGroupConfigs dummy_group;
std::vector<RulesetContent> dummy_ruleset;
std::string managed_url = base64Decode(urlDecode(getUrlArg(argument, "profile_data")));
std::string managed_url = base64Decode(getUrlArg(argument, "profile_data"));
if(managed_url.empty())
managed_url = global.managedConfigPrefix + "/sub?" + joinArguments(argument);

Expand Down Expand Up @@ -1160,7 +1160,7 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
auto &argument = request.argument;
int *status_code = &response.status_code;

std::string name = urlDecode(getUrlArg(argument, "name")), token = urlDecode(getUrlArg(argument, "token"));
std::string name = getUrlArg(argument, "name"), token = getUrlArg(argument, "token");
string_array profiles = split(name, "|");
if(token.empty() || profiles.empty())
{
Expand Down Expand Up @@ -1440,7 +1440,7 @@ std::string renderTemplate(RESPONSE_CALLBACK_ARGS)
auto &argument = request.argument;
int *status_code = &response.status_code;

std::string path = urlDecode(getUrlArg(argument, "path"));
std::string path = getUrlArg(argument, "path");
writeLog(0, "Trying to render template '" + path + "'...", LOG_LEVEL_INFO);

if(!startsWith(path, global.templatePath) || !fileExist(path))
Expand Down
2 changes: 1 addition & 1 deletion src/server/webserver_httplib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static httplib::Server::Handler makeHandler(const responseRoute &rr)
req.argument = request.params;
if (request.get_header_value("Content-Type") == "application/x-www-form-urlencoded")
{
req.postdata = urlDecode(req.postdata);
req.postdata = urlDecode(request.body);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/utils/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ std::string getUrlArg(const std::string &url, const std::string &request)
return "";
}

std::string getUrlArg(const string_multimap &url, const std::string &request)
std::string getUrlArg(const string_multimap &args, const std::string &request)
{
auto it = url.find(request);
if(it != url.end())
auto it = args.find(request);
if(it != args.end())
return it->second;
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::string join(InputIt first, InputIt last, const std::string &delimiter)
}

std::string getUrlArg(const std::string &url, const std::string &request);
std::string getUrlArg(const string_multimap &url, const std::string &request);
std::string getUrlArg(const string_multimap &args, const std::string &request);
std::string replaceAllDistinct(std::string str, const std::string &old_value, const std::string &new_value);
std::string trimOf(const std::string& str, char target, bool before = true, bool after = true);
std::string trim(const std::string& str, bool before = true, bool after = true);
Expand Down

0 comments on commit 13623d6

Please sign in to comment.