Skip to content

Commit 27cfb62

Browse files
committed
lexically_normal-ize path before testing
1 parent 8eca70d commit 27cfb62

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/sagemaker_server.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "sagemaker_server.h"
2828

29+
#include <filesystem>
30+
2931
namespace triton { namespace server {
3032

3133
#define HTTP_RESPOND_IF_ERR(REQ, X) \
@@ -292,8 +294,12 @@ SagemakerAPIServer::ParseSageMakerRequest(
292294
}
293295
}
294296

295-
if (url_string.find("/dev/") == 0 || url_string.find("/proc/") == 0 ||
296-
url_string.find("/sys/") == 0) {
297+
std::filesystem::path url_path(url_string);
298+
url_path = std::filesystem::absolute(url_path.lexically_normal()); // Normalize the path to remove any redundant components.
299+
auto repo_path = url_path.string();
300+
301+
if (repo_path.find("/dev/") == 0 || repo_path.find("/proc/") == 0
302+
|| repo_path.find("/sys/") == 0) {
297303
LOG_ERROR << "Invalid URL: " << url_string
298304
<< ". \"url\" property value cannot start with /dev/, /proc/, or "
299305
"/sys/." << std::endl;
@@ -901,13 +907,17 @@ SagemakerAPIServer::SageMakerMMELoadModel(
901907
evhtp_request_t* req,
902908
const std::unordered_map<std::string, std::string> parse_map)
903909
{
904-
std::string repo_path = parse_map.at("url");
910+
std::string url_string = parse_map.at("url");
905911
std::string model_name_hash = parse_map.at("model_name_hash");
906912
std::string target_model = parse_map.at("target_model");
907913

908-
if (repo_path.find("/dev/") == 0 || repo_path.find("/proc/") == 0 ||
909-
repo_path.find("/sys/") == 0) {
910-
LOG_ERROR << "Invalid repository path: " << repo_path
914+
std::filesystem::path url_path(url_string);
915+
url_path = std::filesystem::absolute(url_path.lexically_normal()); // Normalize the path to remove any redundant components.
916+
std::string repo_path = url_path.string();
917+
918+
if (repo_path.find("/dev/") == 0 || repo_path.find("/proc/") == 0
919+
|| repo_path.find("/sys/") == 0) {
920+
LOG_ERROR << "Invalid repository path: " << url_string
911921
<< ". \"url\" property of `parse_map`cannot start with /dev/, "
912922
"/proc/, or /sys/." << std::endl;
913923
evhtp_send_reply(req, EVHTP_RES_BADREQ);

0 commit comments

Comments
 (0)