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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 15:01:30 2024 UTC