Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 84ceb60

Browse files
committed
Improve the checking by using std::filesystem::equivalent
1 parent 3561e1b commit 84ceb60

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

engine/repositories/file_fs_repository.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ std::filesystem::path SanitizePath(const std::filesystem::path & user_input,
1717
std::filesystem::path resolved_path = std::filesystem::weakly_canonical(
1818
std::filesystem::path(basedir) / std::filesystem::path(user_input));
1919
/* Ensure the resolved path is within our basedir */
20-
if (resolved_path.string().find(abs_base.string()) != 0) {
21-
return {};
20+
for (auto p = resolved_path; !p.empty(); p = p.parent_path()) {
21+
if (std::filesystem::equivalent(p, abs_base)) {
22+
return resolved_path;
23+
}
2224
}
2325

2426
return resolved_path;

0 commit comments

Comments
 (0)