php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #26066 REMOTE_USER not defined when using Basic Auth
Submitted: 2003-10-31 23:12 UTC Modified: 2003-11-03 19:10 UTC
From: gavin at vess dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.4RC3 OS: Linux 2.4.18-27.7.x
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gavin at vess dot com
New email:
PHP Version: OS:

 

 [2003-10-31 23:12 UTC] gavin at vess dot com
Description:
------------
The appended output of "grep's" through PHP and Apache 2 source code clearly show "unconnected" code relating to the username supplied by a user when using basic authentication with HTTP.  PHP source code uses the environment variable HTTP_AUTHORIZATION, yet no code sets this variable within either Apache 2.0.48 or PHP 4.3.4RC3.  This prevents PHP_AUTH* from being set (the code to set these still exists in PHP).  Perhaps this PHP code was written for other web servers that do supply HTTP_AUTHORIZATION environment variable.

This wouldn't cause me any concern, except that REMOTE_USER is also unavailable when using the Apache 2/FastCGI configuration, since Apache 2 sees the script protected by an .htaccess, but not the FastCGI PHP binary.  apache2.0.48/server/util_script.c: ap_add_common_vars() sets up the various environment variables to pass to the FastCGI, but REMOTE_USER is excluded since no authentication was required to access the PHP binary (only the script, but that was an earlier phase in processing the request).  Sigh .. perhaps I will patch Apache to help maintain a consistent environment for my customers .. easier than trying to explain all this to them.

In any case, the documentation at http://us3.php.net/features.http-auth is out-of-sync with Apache 2 / PHP 4.3.4RC3.  Perhaps the information previously accessible via $_SERVER['REMOTE_USER'] and $_SERVER['PHP_AUTH_USER'] will eventually become available through another mechanism (maybe in PHP5)?

I haven't had time to follow the design discussions in php-dev, so I haven't provided a patch to address the dangling code or inconsistencies with the docs, but merely documented (below) evidence of the inconsistencies (perhaps just the result of work-in-progress?).

Cheers,
Gavin

Reproduce code:
---------------
httpd-2.0.48$ grep -r HTTP_AUTHORIZATION .
returns nothing

php-4.3.4RC3$ grep -r HTTP_AUTHORIZATION .
./sapi/caudium/caudium.c:  php_handle_auth_data(lookup_string_header("HTTP_AUTHORIZATION", NULL), TSRMLS_C);
./sapi/cgi/cgi_main.c:          auth = sapi_cgibin_getenv("HTTP_AUTHORIZATION",0 TSRMLS_CC);

php-4.3.4RC3$ grep -r php_handle_auth_data .
./main/main.c:/* {{{ php_handle_auth_data
./main/main.c:PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC)
./main/php_main.h:PHPAPI int php_handle_auth_data(const char *auth TSRMLS_DC);
./netware/phplib.imp:php_handle_auth_data,
./sapi/apache2filter/sapi_apache2.c:            php_handle_auth_data(auth TSRMLS_CC);
./sapi/apache2handler/sapi_apache2.c:           php_handle_auth_data(auth TSRMLS_CC);
./sapi/caudium/caudium.c:  php_handle_auth_data(lookup_string_header("HTTP_AUTHORIZATION", NULL), TSRMLS_C);
./sapi/cgi/cgi_main.c:          php_handle_auth_data(auth TSRMLS_CC);
./sapi/thttpd/thttpd.c: php_handle_auth_data(TG(hc)->authorization TSRMLS_CC);
./sapi/tux/php_tux.c:   php_handle_auth_data(TG(hc)->authorization TSRMLS_CC);



Expected result:
----------------
This PHP code below is never executed, since SG(request_info).auth_user has no value, because it is set from the HTTP_AUTHORIZATION environment variable, which is never set by either PHP or Apache code.  This prevents PHP_AUTH_USER from having a value.

php_register_variable("PHP_AUTH_USER", SG(request_info).auth_user, array_ptr TSRMLS_CC);

"grep -r PHP_AUTH_USER" the source tree will quickly turn up the relevant code.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-01 05:36 UTC] sniper@php.net
This only works fine with PHP being as DSO.
If the Apache2 doesn't provide that env var, it's propably
a) bug in apache or b) configuration issue

 [2003-11-03 19:10 UTC] gavin at vess dot com
Ok .. found it, and patched ap_add_common_vars() in Apache2 to provide an HTTP_AUTHORIZATION header to FastCGI scripts (minus the base64 encoded password for security reasons).

Apache source code refers to the authorization header using case-insenstive comparison with 'Authorization', and the 'HTTP_' prefix is prepended in http2env().

Further, this environment variable is, by default, deleted from the Apache's "environment" in ap_add_common_vars() for CGI's (including FastCGI).

Reference: http://www.faqs.org/rfcs/rfc2617.html
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jun 20 11:01:31 2025 UTC