handle invalid chars
Some checks reported errors
BlockStorage/repertory/pipeline/head Build started...
BlockStorage/repertory/pipeline/pr-v2.0.5-rc-develop Something is wrong with the build of this commit

This commit is contained in:
2025-03-03 19:49:27 -06:00
parent f1bf4f961b
commit eeec1969ba
2 changed files with 16 additions and 5 deletions

View File

@@ -62,7 +62,7 @@ private:
void handle_put_set_value_by_name(auto &&req, auto &&res);
auto launch_process(provider_type prov, std::string_view name,
std::string_view command, bool background = false) const
std::string_view args, bool background = false) const
-> std::vector<std::string>;
};
} // namespace repertory::ui

View File

@@ -31,7 +31,12 @@
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "boost/process.hpp"
namespace {
[[nodiscard]] constexpr auto is_restricted(std::string_view data) -> bool {
constexpr std::string_view invalid_chars = "&;|><$()`{}!*?";
return data.find_first_of(invalid_chars) != std::string_view::npos;
}
} // namespace
namespace repertory::ui {
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
@@ -286,10 +291,17 @@ void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) {
}
auto handlers::launch_process(provider_type prov, std::string_view name,
std::string_view command, bool background) const
std::string_view args, bool background) const
-> std::vector<std::string> {
REPERTORY_USES_FUNCTION_NAME();
if (is_restricted(name) || is_restricted(args)) {
throw utils::error::create_exception(function_name,
{
"invalid data detected",
});
}
std::string str_type;
switch (prov) {
case provider_type::encrypt:
@@ -318,8 +330,7 @@ auto handlers::launch_process(provider_type prov, std::string_view name,
});
}
auto cmd_line =
fmt::format(R"({} {} {})", repertory_binary_, str_type, command);
auto cmd_line = fmt::format(R"({} {} {})", repertory_binary_, str_type, args);
if (background) {
#if defined(_WIN32)