php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65332 Phar follows symlinks instead of adding them which causes problems
Submitted: 2013-07-25 09:20 UTC Modified: -
Votes:7
Avg. Score:4.4 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:4 (66.7%)
From: info at directwebsolutions dot nl Assigned:
Status: Open Package: PHAR related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: info at directwebsolutions dot nl
New email:
PHP Version: OS:

 

 [2013-07-25 09:20 UTC] info at directwebsolutions dot nl
Description:
------------
---
From manual page: http://www.php.net/phar.buildfromdirectory#refsect1-phar.buildfromdirectory-description
---
Phar follows symlinks. Normally a backup of files would make a copy of the symlink file (which is normally 0 bytes) and add it to the tar. That is how the tar binary works. Phar follows the symlink and continues adding files outside the set 'buildFromDirectory'.

Example: i execute $phar->buildFromDirectory('/home/user/public_html'); and there is a symlink named 'stats' which resolves to '/etc/stats/'. Phar then goes to /etc/stats and starts adding files to the tar package. In my opinion Phar should check if the complete filepath starts with the 'buildFromDirectory' first parameter and exclude files is not.

This is especially on shared hosting platforms which open_basedir restriction a problem, but i would recommend to also fix this for all server configurations.

It is also weird that if you look at the 'Actual Result' that for a humans eye the path IS WITHIN the allowed open_basedir directory, but actually it is OUTSIDE the open_basedir (/usr/...). Probably due to the symlink.

Maybe a new parameter could be a solution:
$phar->buildFromDirectory(..., [$follow_symlinks = true]);

Test script:
---------------
<?
  $phar = new PharData($localfilepath);
  $phar->compress(Phar::GZ);
  $phar->buildFromDirectory($localbackupdir);
?>

Expected result:
----------------
SUCCESS - tar(gz) file created

Actual result:
--------------
Warning: RecursiveDirectoryIterator::hasChildren() [recursivedirectoryiterator.haschildren]: open_basedir restriction in effect. File(/home/user/awstats/icon) is not within the allowed path(s): (/home/user/:/tmp:/var/tmp:/usr/local/lib/php/) in file ... line ..

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Iterator RecursiveIteratorIterator returned a path "/usr/local/awstats/icon" that is not in the base directory "/home/user"' in /home/user/tarscript.php:40 Stack trace: #0 /home/user/tarscript.php(40): PharData->buildFromDirectory('/home/user...') #1 {main} thrown in /home/user/tarscript.php on line 40

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Jan 21 18:01:22 2020 UTC