Skip to content

Commit 62f6400

Browse files
authored
Merge pull request #212 from aviadatsnyk/master
fix: prevent extracting archived files outside of target path. Credit to Snyk Security Research Team for disclosure and fixing the issue.
2 parents e116bc1 + 6f4dfeb commit 62f6400

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

adm-zip.js

+11
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ module.exports = function(/*String*/input) {
354354

355355

356356
var target = pth.resolve(targetPath, maintainEntryPath ? entryName : pth.basename(entryName));
357+
if(!target.startsWith(targetPath)) {
358+
throw Utils.Errors.INVALID_FILENAME + ": " + entryName;
359+
}
357360

358361
if (item.isDirectory) {
359362
target = pth.resolve(target, "..");
@@ -429,6 +432,10 @@ module.exports = function(/*String*/input) {
429432
_zip.entries.forEach(function(entry) {
430433
entryName = entry.entryName.toString();
431434

435+
if(!pth.resolve(targetPath, entryName).startsWith(targetPath)) {
436+
throw Utils.Errors.INVALID_FILENAME + ": " + entryName;
437+
}
438+
432439
if(isWin){
433440
entryName = escapeFileName(entryName)
434441
}
@@ -471,6 +478,10 @@ module.exports = function(/*String*/input) {
471478
entryName = escapeFileName(entryName)
472479
}
473480

481+
if(!pth.resolve(targetPath, entryName).startsWith(targetPath)) {
482+
throw Utils.Errors.INVALID_FILENAME + ": " + entryName;
483+
}
484+
474485
if (entry.isDirectory) {
475486
Utils.makeDir(pth.resolve(targetPath, entryName));
476487
if(--i == 0)

0 commit comments

Comments
 (0)