aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/storage/projectstore/httpprojectstore.cpp
diff options
context:
space:
mode:
authorLiam Mitchell <[email protected]>2026-01-19 17:33:34 -0800
committerLiam Mitchell <[email protected]>2026-01-19 17:33:34 -0800
commite17d802ab57190845bb471f9c7a980c850806369 (patch)
treea4cc2480608e7da0ec031cac6cbeba86a0f95351 /src/zenserver/storage/projectstore/httpprojectstore.cpp
parentzenserver API changes, some other minor changes (#720) (diff)
downloadzen-e17d802ab57190845bb471f9c7a980c850806369.tar.xz
zen-e17d802ab57190845bb471f9c7a980c850806369.zip
Restrict filesystem reads in snapshot to paths under project root
Diffstat (limited to 'src/zenserver/storage/projectstore/httpprojectstore.cpp')
-rw-r--r--src/zenserver/storage/projectstore/httpprojectstore.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/zenserver/storage/projectstore/httpprojectstore.cpp b/src/zenserver/storage/projectstore/httpprojectstore.cpp
index 4e947f221..8742ed75f 100644
--- a/src/zenserver/storage/projectstore/httpprojectstore.cpp
+++ b/src/zenserver/storage/projectstore/httpprojectstore.cpp
@@ -2900,8 +2900,24 @@ HttpProjectService::HandleRpcRequest(HttpRouterRequest& Req)
{
std::string_view ServerPath = View["serverpath"sv].AsString();
std::filesystem::path FilePath = Project->RootDir / ServerPath;
- BasicFile DataFile;
- std::error_code Ec;
+ if (!std::filesystem::exists(FilePath))
+ {
+ ZEN_WARN("Attempted to read non-existent file '{}' in 'snapshot'", FilePath);
+ AllOk = false;
+ continue;
+ }
+
+ std::filesystem::path CanonicalRoot = std::filesystem::canonical(Project->RootDir);
+
+ if (!std::filesystem::canonical(FilePath).string().starts_with(CanonicalRoot.string()))
+ {
+ ZEN_WARN("Unable to read file '{}' outside of project root '{}'", FilePath, CanonicalRoot);
+ AllOk = false;
+ continue;
+ }
+
+ BasicFile DataFile;
+ std::error_code Ec;
DataFile.Open(FilePath, BasicFile::Mode::kRead, Ec);
if (Ec)