|  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: -
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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
36 + 49 = ?
Subscribe to this entry?

 [2013-07-25 09:20 UTC] info at directwebsolutions dot nl
From manual page:
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);

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 15:01:32 2024 UTC