fix: verify that file names queried from the store do not allow path traversal (#1277)
This commit is contained in:
parent
235f4e39b4
commit
c2fe9f0966
@ -260,11 +260,18 @@ namespace hex::plugin::builtin {
|
||||
|
||||
bool ViewStore::download(fs::ImHexPath pathType, const std::string &fileName, const std::string &url, bool update) {
|
||||
bool downloading = false;
|
||||
for (const auto &path : fs::getDefaultPaths(pathType)) {
|
||||
if (!fs::isPathWritable(path))
|
||||
for (const auto &folderPath : fs::getDefaultPaths(pathType)) {
|
||||
if (!fs::isPathWritable(folderPath))
|
||||
continue;
|
||||
|
||||
auto fullPath = path / std::fs::path(fileName);
|
||||
// verify that we write the file to the right folder
|
||||
// this is to prevent the filename from having elements like ../
|
||||
auto fullPath = std::fs::weakly_canonical(folderPath / std::fs::path(fileName));
|
||||
auto [folderIter, pathIter] = std::mismatch(folderPath.begin(), folderPath.end(), fullPath.begin());
|
||||
if(folderIter != folderPath.end()) {
|
||||
log::warn("The destination file name '{}' is invalid", fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!update || wolv::io::fs::exists(fullPath)) {
|
||||
downloading = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user