|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: francois at bonzon dot com
New email:
PHP Version: OS:


 [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: Tue Nov 29 08:05:54 2022 UTC