|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29145 unlink() won't delete symlink pointing outside open_basedir
Submitted: 2004-07-14 15:12 UTC Modified: 2005-01-31 23:32 UTC
Avg. Score:4.7 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:6 (100.0%)
From: francois at bonzon dot com Assigned:
Status: Wont fix Package: Safe Mode/open_basedir
PHP Version: 4.3.7 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:
13 + 7 = ?
Subscribe to this entry?

 [2004-07-14 15:12 UTC] francois at bonzon dot com
First, remember that when you delete a symlink (symbolic link) with the unlink() function, the link file itself is deleted, not the target file it references.

When you try to delete a symbolic link and an open_basedir restriction is in effect, with the link file itself inside the allowed path(s), but the target file outside the allowed path(s), then PHP incorrectly refuses to do it.

Reproduce code:
# the file 'test' is a symlink to '/home'
unlink($_SERVER['DOCUMENT_ROOT'] . '/debug/test');

Expected result:
PHP shouldn't resolve the symbolic link when determining whether or not it is within the allowed path(s), and allow the deletion. It should't care what the link references, but only whether the link file itself is in the allowed path(s).

Actual result:
PHP throws this error message:

Warning: unlink(): open_basedir restriction in effect. File(/home/sites/site23/web/debug/test) is not within the allowed path(s): (/home/sites/site23:/tmp) in /home/sites/site23/web/debug/unlink.php on line 6

You can see the contradiction in this message: /home/sites/site23/web/debug/test is indeed in the /home/sites/site23 directory-tree.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-15 00:36 UTC]
The nature of open_basedir handling prevents this behavior. 
This is almost impossible to change without a lot of 
special exceptions for unlink() operations on symlinks. 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 02:05:54 2022 UTC