Skip to content

Commit 4eb1c25

Browse files
nielsdosjorgsowa
authored andcommitted
Apache only generates REDIRECT_STATUS, so explicitly check for that if the server name is Apache, don't allow other variable names. Furthermore, redirect.so and Netscape no longer exist, so remove those entries as we can't check their server name anymore. We now also check for the configuration override *first* such that it always take precedence. This would allow for a mitigation path if something like this happens in the future.
1 parent d1d167f commit 4eb1c25

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

sapi/cgi/cgi_main.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,18 +1888,17 @@ int main(int argc, char *argv[])
18881888

18891889
/* check force_cgi after startup, so we have proper output */
18901890
if (cgi && CGIG(force_redirect)) {
1891-
/* Apache will generate REDIRECT_STATUS,
1892-
* Netscape and redirect.so will generate HTTP_REDIRECT_STATUS.
1893-
* redirect.so and installation instructions available from
1894-
* http://www.koehntopp.de/php.
1895-
1896-
*/
1897-
if (!getenv("REDIRECT_STATUS") &&
1898-
!getenv ("HTTP_REDIRECT_STATUS") &&
1899-
/* this is to allow a different env var to be configured
1900-
* in case some server does something different than above */
1901-
(!CGIG(redirect_status_env) || !getenv(CGIG(redirect_status_env)))
1902-
) {
1891+
/* This is to allow a different environment variable to be configured
1892+
* in case the we cannot auto-detect which environment variable to use.
1893+
* Checking this first to allow user overrides in case the environment
1894+
* variable can be set by an untrusted party. */
1895+
const char *redirect_status_env = CGIG(redirect_status_env);
1896+
if (!redirect_status_env) {
1897+
/* Apache will generate REDIRECT_STATUS. */
1898+
redirect_status_env = "REDIRECT_STATUS";
1899+
}
1900+
1901+
if (!getenv(redirect_status_env)) {
19031902
zend_try {
19041903
SG(sapi_headers).http_response_code = 400;
19051904
PUTS("<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\

0 commit comments

Comments
 (0)