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:8
Avg. Score:4.4 ± 0.7
Reproduced:7 of 7 (100.0%)
Same Version:3 (42.9%)
Same OS:5 (71.4%)
From: info at directwebsolutions dot nl Assigned:
Status: Open Package: PHAR related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 18:01:28 2024 UTC