recognize more startswith sanitizers for path-injection queries

This commit is contained in:
Erik Krogh Kristensen
2022-02-07 14:19:13 +01:00
parent 55e69d421c
commit ca5f91e587
2 changed files with 33 additions and 3 deletions

View File

@@ -25,6 +25,7 @@ fs.createReadStream('archive.zip')
const JSZip = require('jszip');
const zip = new JSZip();
const path = require('path');
function doZipSlip() {
for (const name in zip.files) {
fs.createWriteStream(name);
@@ -33,4 +34,22 @@ function doZipSlip() {
zip.forEach((name, file) => {
fs.createWriteStream(name);
});
}
const extractTo = path.resolve("/some/path/to/extract/to");
var files = [];
for (var name in zip.files) {
var entry = zip.files[name];
var targetPath = path.resolve(
path.join(extractTo, name)
);
if (!targetPath.startsWith(extractTo)) {
throw new Error("Entry is outside the extraction path");
}
files.push(name);
}
for (const file of files) {
fs.createWriteStream(path.join(extractTo, file)); // OK
}
}