Skip to content

Commit

Permalink
Fixes #33 - ensure we catch additional malicious/crafted filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
mrook committed Nov 19, 2020
1 parent bbb4f10 commit 0670a05
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Archive/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ public function _readHeader($v_binary_data, &$v_header)

// ----- Extract the properties
$v_header['filename'] = rtrim($v_data['filename'], "\0");
if ($this->_maliciousFilename($v_header['filename'])) {
if ($this->_isMaliciousFilename($v_header['filename'])) {
$this->_error(
'Malicious .tar detected, file "' . $v_header['filename'] .
'" will not install in desired directory tree'
Expand Down Expand Up @@ -1800,9 +1800,9 @@ private function _tarRecToSize($tar_size)
*
* @return bool
*/
private function _maliciousFilename($file)
private function _isMaliciousFilename($file)
{
if (strpos($file, 'phar://') === 0) {
if (strpos($file, '://') !== false) {
return true;
}
if (strpos($file, '../') !== false || strpos($file, '..\\') !== false) {
Expand Down Expand Up @@ -1838,7 +1838,7 @@ public function _readLongHeader(&$v_header)

$v_filename = rtrim(substr($v_filename, 0, $v_filesize), "\0");
$v_header['filename'] = $v_filename;
if ($this->_maliciousFilename($v_filename)) {
if ($this->_isMaliciousFilename($v_filename)) {
$this->_error(
'Malicious .tar detected, file "' . $v_filename .
'" will not install in desired directory tree'
Expand Down

0 comments on commit 0670a05

Please sign in to comment.