Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Prevent Zip Traversal Attacks (#156)
Browse files Browse the repository at this point in the history
Checks for special characters within filenames within a ZIP file using strpos comparison
  • Loading branch information
snoopysecurity authored Feb 25, 2020
1 parent aa42817 commit d15207e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Chumper/Zipper/Zipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ private function extractFilesInternal($path, callable $matchingMethod)
private function extractOneFileInternal($fileName, $path)
{
$tmpPath = str_replace($this->getInternalPath(), '', $fileName);

//Prevent Zip traversal attacks
if (strpos($fileName, '../') !== false || strpos($fileName, '..\\') !== false) {
throw new \RuntimeException('Special characters found within filenames');
}

// We need to create the directory first in case it doesn't exist
$dir = pathinfo($path.DIRECTORY_SEPARATOR.$tmpPath, PATHINFO_DIRNAME);
Expand Down

0 comments on commit d15207e

Please sign in to comment.