Skip to content

Commit

Permalink
fix: prevent extracting archived files outside of target path
Browse files Browse the repository at this point in the history
  • Loading branch information
aviadatsnyk committed Apr 22, 2018
1 parent e116bc1 commit 6f4dfeb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions adm-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ module.exports = function(/*String*/input) {


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

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

if(!pth.resolve(targetPath, entryName).startsWith(targetPath)) {
throw Utils.Errors.INVALID_FILENAME + ": " + entryName;
}

if(isWin){
entryName = escapeFileName(entryName)
}
Expand Down Expand Up @@ -471,6 +478,10 @@ module.exports = function(/*String*/input) {
entryName = escapeFileName(entryName)
}

if(!pth.resolve(targetPath, entryName).startsWith(targetPath)) {
throw Utils.Errors.INVALID_FILENAME + ": " + entryName;
}

if (entry.isDirectory) {
Utils.makeDir(pth.resolve(targetPath, entryName));
if(--i == 0)
Expand Down

0 comments on commit 6f4dfeb

Please sign in to comment.