Skip to content

Commit 906218c

Browse files
committed
feat: zip-slip vulnerability in import function
1 parent c6ebacc commit 906218c

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://github.com/Snyk/snyk-todo-list-demo-app/"
99
},
1010
"scripts": {
11-
"start": "node app.js",
11+
"start": "node --inspect app.js",
1212
"build": "browserify -r jquery > public/js/bundle.js",
1313
"cleanup": "mongo express-todo --eval 'db.todos.remove({});'"
1414
},
@@ -39,7 +39,9 @@
3939
"optional": "^0.1.3",
4040
"st": "0.2.4",
4141
"stream-buffers": "^3.0.1",
42-
"tap": "^5.7.0"
42+
"tap": "^5.7.0",
43+
"adm-zip": "0.4.7",
44+
"file-type": "^8.1.0"
4345
},
4446
"devDependencies": {
4547
"browserify": "^13.1.1"

routes/index.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ var readline = require('readline');
1010
var moment = require('moment');
1111
var exec = require('child_process').exec;
1212

13+
// zip-slip
14+
var fileType = require('file-type');
15+
var AdmZip = require('adm-zip');
16+
1317
exports.index = function (req, res, next) {
1418
Todo.
1519
find({}).
@@ -162,8 +166,27 @@ exports.import = function (req, res, next) {
162166
}
163167

164168
var importFile = req.files.importFile;
165-
var data = importFile.data.toString('ascii');
166-
169+
var data;
170+
var importedFileType = fileType(importFile.data);
171+
var zipFileExt = { ext: "zip", mime: "application/zip" };
172+
if (importedFileType === null) {
173+
importedFileType = { ext: "txt", mime: "text/plain" };
174+
}
175+
if (importedFileType["mime"] === zipFileExt["mime"]) {
176+
var zip = AdmZip(importFile.data);
177+
var extracted_path = "/tmp/extracted_files";
178+
zip.extractAllTo(extracted_path, true);
179+
var zipEntries = zip.getEntries();
180+
zipEntries.forEach(function (zipEntry) {
181+
if (zipEntry.entryName === "backup.txt") {
182+
data = zipEntry.getData().toString('ascii');
183+
} else {
184+
data = "No backup.txt file found";
185+
}
186+
});
187+
} else {
188+
data = importFile.data.toString('ascii');
189+
}
167190
var lines = data.split('\n');
168191
lines.forEach(function (line) {
169192
var parts = line.split(',');

0 commit comments

Comments
 (0)