diff options
author | Stefan Fritsch <sf@apache.org> | 2010-12-28 15:20:52 +0100 |
---|---|---|
committer | Stefan Fritsch <sf@apache.org> | 2010-12-28 15:20:52 +0100 |
commit | afea2a1dc450cbd336df2a8494e87d57a2dc2b22 (patch) | |
tree | fa583ffbd6c9754e46830d800caa34d3a93637ae | |
parent | readability improvements: (diff) | |
download | apache2-afea2a1dc450cbd336df2a8494e87d57a2dc2b22.tar.xz apache2-afea2a1dc450cbd336df2a8494e87d57a2dc2b22.zip |
When exporting request headers to HTTP_* environment variables, drop variables
whose names contain invalid characters. Describe in the docs how to restore the
old behaviour.
Submitted by: Malte S. Stretz <mss apache org>
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1053353 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | docs/manual/env.xml | 34 | ||||
-rw-r--r-- | docs/manual/howto/cgi.xml | 20 | ||||
-rw-r--r-- | docs/manual/new_features_2_4.xml | 11 | ||||
-rw-r--r-- | server/util_script.c | 11 |
5 files changed, 70 insertions, 10 deletions
@@ -2,6 +2,10 @@ Changes with Apache 2.3.11 + *) core: When exporting request headers to HTTP_* environment variables, + drop variables whose names contain invalid characters. Describe in the + docs how to restore the old behaviour. [Malte S. Stretz <mss apache org>] + *) core: When selecting an IP-based virtual host, favor an exact match for the port over a wildcard (or omitted) port instead of favoring the one that came first in the configuration file. [Eric Covener] diff --git a/docs/manual/env.xml b/docs/manual/env.xml index 055f69e7d9..1cfcb7ff44 100644 --- a/docs/manual/env.xml +++ b/docs/manual/env.xml @@ -140,6 +140,13 @@ not be a number. Characters which do not match this restriction will be replaced by an underscore when passed to CGI scripts and SSI pages.</li> + + <li>A special case are HTTP headers which are passed to CGI + scripts and the like via environment variables (see below). + They are converted to uppercase and only dashes are replaced with + underscores; if the header contains any other (invalid) character, + the whole header is silently dropped. See <a href="#fixheader"> + below</a> for a workaround.</li> <li>The <directive module="mod_env">SetEnv</directive> directive runs late during request processing meaning that directives such as @@ -423,6 +430,33 @@ <section id="examples"> <title>Examples</title> + <section id="fixheader"> + <title>Passing broken headers to CGI scripts</title> + + <p>Starting with version 2.4, Apache is more strict about how HTTP + headers are converted to environment variables in <module>mod_cgi + </module> and other modules: Previously any invalid characters + in header names were simply translated to underscores. This allowed + for some potential cross-site-scripting attacks via header injection + (see <a href="http://events.ccc.de/congress/2007/Fahrplan/events/2212.en.html"> + Unusual Web Bugs</a>, slide 19/20).</p> + + <p>If you have to support a client which sends broken headers and + which can't be fixed, a simple workaround involving <module>mod_setenvif + </module> and <module>mod_header</module> allows you to still accept + these headers:</p> + +<example><pre> +# +# The following works around a client sending a broken Accept_Encoding +# header. +# +SetEnvIfNoCase ^Accept.Encoding$ ^(.*)$ fix_accept_encoding=$1 +RequestHeader set Accept-Encoding %{fix_accept_encoding}e env=fix_accept_encoding +</pre></example> + + </section> + <section id="misbehaving"> <title>Changing protocol behavior with misbehaving clients</title> diff --git a/docs/manual/howto/cgi.xml b/docs/manual/howto/cgi.xml index ca239138a4..890c6087b1 100644 --- a/docs/manual/howto/cgi.xml +++ b/docs/manual/howto/cgi.xml @@ -352,11 +352,6 @@ <p>Make sure that this is in fact the path to the interpreter.</p> - - <p>In addition, if your CGI program depends on other <a - href="#env">environment variables</a>, you will need to - assure that those variables are passed by Apache.</p> - <note type="warning"> When editing CGI scripts on Windows, end-of-line characters may be appended to the interpreter path. Ensure that files are then @@ -365,6 +360,21 @@ unrecognized end-of-line character being interpreted as a part of the interpreter filename. </note> + </section> + + <section id="missingenv"> + <title>Missing environment variables</title> + + <p>If your CGI program depends on non-standard <a + href="#env">environment variables</a>, you will need to + assure that those variables are passed by Apache.</p> + + <p>When you miss HTTP headers from the environment, make + sure they are formatted according to + <a href="http://tools.ietf.org/html/rfc2616">RFC 2616</a>, + section 4.2: Header names must start with a letter, + followed only by letters, numbers or hyphen. Any header + violating this rule will be dropped silently.</p> </section> diff --git a/docs/manual/new_features_2_4.xml b/docs/manual/new_features_2_4.xml index 94539bd5d9..70f7a8d7e4 100644 --- a/docs/manual/new_features_2_4.xml +++ b/docs/manual/new_features_2_4.xml @@ -109,11 +109,20 @@ authentication or authorization.</dd> <dt><module>mod_include</module></dt> - <dd>Support for the 'onerror' attribute within an 'include' element, allowing an error document to be served on error instead of the default error string.</dd> + <dt><module>mod_cgi</module>, <module>mod_include</module>, + <module>mod_isapi</module>, ...</dt> + <dd>Translation of headers to environment variables is more strict than + before to mitigate some possible cross-site-scripting attacks via header + injection. Headers containing invalid characters (including underscores) + are now silently dropped. <a href="env.html">Environment Variables + in Apache</a> has some pointers on how to work around broken legacy + clients which require such headers. (This affects all modules which + use these environment variables.)</dd> + </dl> </section> diff --git a/server/util_script.c b/server/util_script.c index f5e4ef1210..2a987b1fba 100644 --- a/server/util_script.c +++ b/server/util_script.c @@ -67,11 +67,14 @@ static char *http2env(apr_pool_t *a, const char *w) *cp++ = '_'; while ((c = *w++) != 0) { - if (!apr_isalnum(c)) { + if (apr_isalnum(c)) { + *cp++ = apr_toupper(c); + } + else if (c == '-') { *cp++ = '_'; } else { - *cp++ = apr_toupper(c); + return NULL; } } *cp = 0; @@ -175,8 +178,8 @@ AP_DECLARE(void) ap_add_common_vars(request_rec *r) continue; } #endif - else { - apr_table_addn(e, http2env(r->pool, hdrs[i].key), hdrs[i].val); + else if ((env_temp = http2env(r->pool, hdrs[i].key)) != NULL) { + apr_table_addn(e, env_temp, hdrs[i].val); } } |