diff options
| author | Liam Mitchell <[email protected]> | 2026-01-19 17:33:34 -0800 |
|---|---|---|
| committer | Liam Mitchell <[email protected]> | 2026-01-19 17:33:34 -0800 |
| commit | e17d802ab57190845bb471f9c7a980c850806369 (patch) | |
| tree | a4cc2480608e7da0ec031cac6cbeba86a0f95351 /src/zenserver/storage/projectstore/httpprojectstore.cpp | |
| parent | zenserver API changes, some other minor changes (#720) (diff) | |
| download | zen-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.cpp | 20 |
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) |