Skip to content

Commit

Permalink
Disallow symlinks to out-of-path filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
mrook committed Dec 14, 2020
1 parent be2da51 commit cde4605
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Archive/Tar.php
Expand Up @@ -2124,6 +2124,14 @@ public function _extractList(
}
}
} elseif ($v_header['typeflag'] == "2") {
if (strpos(realpath(dirname($v_header['link'])), realpath($p_path)) !== 0) {
$this->_error(
'Out-of-path file extraction {'
. $v_header['filename'] . ' --> ' .
$v_header['link'] . '}'
);
return false;
}
if (!$p_symlinks) {
$this->_warning('Symbolic links are not allowed. '
. 'Unable to extract {'
Expand Down
18 changes: 18 additions & 0 deletions tests/out_of_path_fnames.phpt
@@ -0,0 +1,18 @@
--TEST--
tests writes to out-of-path filenames
--SKIPIF--
--FILE--
<?php
require_once dirname(__FILE__) . '/setup.php.inc';
$tar = new Archive_Tar(dirname(__FILE__) . '/out_of_path_symlink.tar');
$tar->extract();
$phpunit->assertErrors(array(array('package' => 'PEAR_Error', 'message' => "Out-of-path file extraction {symlink --> /tmp/}")), 'after 1');
$phpunit->assertFileNotExists('symlink/whatever-filename', 'Out-of-path filename should not have succeeded');
echo 'tests done';
?>
--CLEAN--
<?php
@unlink("symlink");
?>
--EXPECT--
tests done
Binary file added tests/out_of_path_symlink.tar
Binary file not shown.

1 comment on commit cde4605

@carnil
Copy link

@carnil carnil commented on cde4605 Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue fixed by this commit was addressed CVE-2020-36193 according to FriendsOfPHP/security-advisories#525

Please sign in to comment.