Serve no file whose path cannot be resolved

When the real path of a file under a mount point could not be resolved,
the check that it stays inside the mount point was skipped and the file
was served. Do not serve it from there, and refuse a mount point whose
directory cannot be resolved.
This commit is contained in:
yhirose committed 2026-10-16 16:39:00 -04:00
1 parent 455166314b
commit eeaae4bc3c
2 files changed
+48 -17

No files matched your search

+26
View File
@@ -11720,6 +11720,32 @@ TEST(MountTest, Unmount) {
EXPECT_EQ(StatusCode::NotFound_404, res->status);
}
TEST(MountTest, MissingFileFallsThroughToHandlers) {
Server svr;
ASSERT_TRUE(svr.set_mount_point("/", "./www"));
svr.Get("/api/hello", [](const Request &, Response &res) {
res.set_content("api", "text/plain");
});
auto listen_thread = std::thread([&svr]() { svr.listen(HOST, PORT); });
auto se = detail::scope_exit([&] {
svr.stop();
listen_thread.join();
ASSERT_FALSE(svr.is_running());
});
svr.wait_until_ready();
Client cli(HOST, PORT);
auto res = cli.Get("/dir/test.html");
ASSERT_TRUE(res) << "Error: " << to_string(res.error());
EXPECT_EQ(StatusCode::OK_200, res->status);
res = cli.Get("/api/hello");
ASSERT_TRUE(res) << "Error: " << to_string(res.error());
EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ("api", res->body);
}
TEST(MountTest, PathSegmentBoundary) {
Server svr;