#42198 [Fbk]: SCRIPT_NAME and PHP_SELF truncated when inside a userdir and using PATH_INFO
| From: | jani@php.net | Date: | Tue, 07 Aug 2007 13:10:10 +0000 |
| Subject: | #42198 [Fbk]: SCRIPT_NAME and PHP_SELF truncated when inside a userdir and using PATH_INFO | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115841@lists.php.net to get a copy of this message | ||
ID: 42198
Updated by: jani@php.net
Reported By: hans at parse dot nl
Status: Feedback
Bug Type: CGI related
Operating System: Linux
PHP Version: 5.2.4RC1
New Comment:
And FYI, about PHP_SELF:
http://www.php.net/reserved.variables
(yes, it's supposed to contain PATH_INFO..)
Previous Comments:
------------------------------------------------------------------------
[2007-08-07 13:08:05] jani@php.net
See bug #31892 (It's about Apache)
I fixed the issues there with this patch (against latest CVS checkout
of PHP_5_2):
http://pecl.php.net/~jani/patches/bug_31892.patch
I then tried the same on lighttpd but no luck: Lighttpd sets
PATH_TRANSLATED incorrectly, debugged it and saw it was set to this:
PATH_TRANSLATED: /opt/www//foo/bar/
PATH_INFO: /foo/bar/
SCRIPT_FILENAME: /home/jani/t.php
SCRIPT_NAME: /r/t.php
PHP_SELF: /r/t.php
REQUEST_URI: /r/t.php/foo/bar/?bar=foo
Obviously when there's this alias/userdir lighttpd still uses document
root to set the PATH_TRANSLATED with (I checked the actual value
lighttpd sets it to, it's not the one PHP modifies..).
Lighttpd seems to ignore the script name totally too. Under apache it
now works (when my patch is applied) as expected:
PATH_TRANSLATED: /home/jani/t.php/foo/bar/
PATH_INFO: /foo/bar/
SCRIPT_FILENAME: /home/jani/t.php
SCRIPT_NAME: /r/t.php/foo/bar/
PHP_SELF: /r/t.php/foo/bar/
REQUEST_URI: /r/t.php/foo/bar/?bar=foo
------------------------------------------------------------------------
[2007-08-07 12:35:44] hans at parse dot nl
Heh i was pondering and typing a apache2handler example and then i saw
your Apache comment. Here it is anyway:
--
Yes i agree, my patch is kinda hacky but solved my personal userdir
problem ;) The alias problem was someone else's which i overlooked.
Your alias example suffers from the same problem as userdirs, being
that the DOCUMENT_ROOT always points to the docroot of the host, but as
i already pointed out, this is also the case in apache/mod_php5 or
apache2handler, not just cgi-fcgi.
apache2handler actually is an even bigger mess :) for example:
request: http://www.site.com/~hans/info.php/foo/bar
result:
_SERVER["DOCUMENT_ROOT"] /var/www/site.com/www/htdocs
_SERVER["REQUEST_URI"] /~hans/info.php/foo/bar
_SERVER["SCRIPT_NAME"] /~hans/info.php
_SERVER["PATH_INFO"] /foo/bar
_SERVER["PATH_TRANSLATED"] /var/www/site.com/www/htdocs/foo/bar
_SERVER["PHP_SELF"] /~hans/info.php/foo/bar
Not really consistent, and also an invalid PATH_TRANSLATED, and
PATH_INFO added to PHP_SELF ?!
Anyway, back to Lighttpd. I'll try to whip up a less hacky fix that
also handles the aliases.
------------------------------------------------------------------------
[2007-08-07 11:51:55] jani@php.net
Then again same happens with Apache too..
------------------------------------------------------------------------
[2007-08-07 11:41:19] jani@php.net
You patch does not fix the issue for anything but the userdir module
and in a very hackish way. For the aliasing part of your (saw your
example on the lighttpd bug report) it does not fix it at all.
When I debugged this I noticed this:
["PATH_TRANSLATED"]=>
string(17) "/opt/www/foo/bar/"
["SCRIPT_FILENAME"]=>
string(16) "/home/jani/t.php"
["DOCUMENT_ROOT"]=>
string(9) "/opt/www/"
["REQUEST_URI"]=>
string(17) "/r/t.php/foo/bar/"
Shouldn't DOCUMENT_ROOT be /home/jani/ in this case when it's the
alias? And PATH_TRANSLATED is also wrong..
------------------------------------------------------------------------
[2007-08-07 09:23:00] hans at parse dot nl
A little more explanation fyi: The problem is that DOCUMENT_ROOT is
always set to the configured document root of the default host or the
vhost, even when calling scripts from a userdir. This is not just in
Lighttpd/FastCGI, also f.e. in Apache setups. In my testcase
DOCUMENT_ROOT is '/var/www/htdocs'.
So if i call http://servername/~hans/info.php/foo/bar , We
enter this
bit of code in init_request_info() in sapi/cgi/cgi_main.c:
---
/* figure out docroot
SCRIPT_FILENAME minus SCRIPT_NAME
*/
if (env_document_root)
{
int l = strlen(env_document_root);
int path_translated_len = 0;
char *path_translated = NULL;
if (l && env_document_root[l - 1] == '/') {
--l;
}
/* we have docroot, so we should have:
* DOCUMENT_ROOT=/docroot
* SCRIPT_FILENAME=/docroot/info.php
*
* SCRIPT_NAME is the portion of the path beyond docroot
*/
env_script_name = pt + l;
---
Since env_document_root is pretty much always set, we enter the if. pt
is '/home/hans/public_html/info.php' at this point (which is correct). l
becomes 15, the strlen of our DOCUMENT_ROOT '/var/www/htdocs'. The
"trailing slash check if loop" is skipped since our docroot doesn't have
a trailing slash. After this, SCRIPT_NAME is set to pt + l. pt being
'/home/hans/public_html/info.php' and l being 15, this results in a
invalid SCRIPT_NAME (and thus a PHP_SELF) of 'ic_html/info.php'.
My patch adds a userdir check to the 'if (env_document_root)', to
prevent from entering this if() with a DOCUMENT_ROOT that doesn't match
the actual docroot of the userdir. The code that follows after this if()
handles the userdir requests perfectly and results in correct
SCRIPT_NAME and PHP_SELF vars.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/42198
--
Edit this bug report at http://bugs.php.net/?id=42198&edit=1