]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
When exporting request headers to HTTP_* environment variables, drop variables
authorStefan Fritsch <sf@apache.org>
Tue, 28 Dec 2010 14:20:52 +0000 (14:20 +0000)
committerStefan Fritsch <sf@apache.org>
Tue, 28 Dec 2010 14:20:52 +0000 (14:20 +0000)
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

CHANGES
docs/manual/env.xml
docs/manual/howto/cgi.xml
docs/manual/new_features_2_4.xml
server/util_script.c

diff --git a/CHANGES b/CHANGES
index b6a5f34e1d6ff5486aebc114fcf89fb18c479c42..a11a200271c5c51af00139e15e01e23110e187f5 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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]
index 055f69e7d90be0d3dd8ab51076573349e1d3636e..1cfcb7ff448667b79650c3dd82bf5866029df65e 100644 (file)
           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
   <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>
 
index ca239138a415fda5f2f5e0bdb7ed9ca447ad4df2..890c6087b1f831cd9f26ce8c371c3581a5640493 100644 (file)
 
       <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
       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>
 
index 94539bd5d9ef6d1b76ef00261ed093115cd608dd..70f7a8d7e4da9a64a0bd26366d05e41913b4dbda 100644 (file)
       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>
 
index f5e4ef1210f495a2d3f36bb8d7ec29c5d44c6fbb..2a987b1fba24c537b00afab0a07033255b125de6 100644 (file)
@@ -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);
         }
     }