Fix path traversal on mod upload

Fix possibility of a maliciously crafted mod being written outside of
the mods directory and thus possibily overwriting unrelated files.
This commit is contained in:
Hornwitser committed 2023-12-03 19:59:14 +01:00
1 parent 94cb607930
commit 1095d2466d
4 files changed
+27 -2

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
{
"name": "../bad_path_mod",
"version": "1.0.0",
"title": "Path Traversing Mod",
"author": "Me",
"description": "A mod who's name traverses the filesystem",
"factorio_version": "1.1",
"dependencies": []
}
+15
View File
@@ -934,6 +934,21 @@ describe("Integration of Clusterio", function() {
"mod not present in mods directory"
);
});
it("rejects path traversing mods", async function() {
await libBuildMod.build({
build: true,
pack: true,
sourceDir: path.join("test", "file", "path_traversing_mod"),
outputDir: path.join("temp", "test"),
modName: "path_traversing_mod_1.0.0",
});
await fs.remove(path.join("temp", "test", "bad_path_mod_1.0.0.zip"));
await assert.rejects(execCtl("mod upload path_traversing_mod_1.0.0.zip"));
assert(
!await fs.pathExists(path.join("temp", "test", "bad_path_mod_1.0.0.zip")),
"mod executed a path traversal attack",
);
});
});
describe("mod show", function() {