Following the thread
http://mail-archives.apache.org/mod_mbox/httpd-dev/201112.mbox/%3CCAKUrXK4uwT%3DP1KtEziNqFdxXs%2BtyWvggzpL8x2u-Bbq8tZ-Zsw%40mail.gmail.com%3E
and the related discussion in 2.2.x/STATUS, attached is a patch for
trunk that implements the checking according to the following
criteria:

* modules can handle whatever valid URIs they want in the translate_name phase
* our modules (rewrite, proxy, alias, whatever) decline URIs they can't handle
* core's translate_name enforces HTTP constraints on the URI,
returning 400 otherwise

(This patch is based on a 2.2.x patch from jorton with a tweak
suggested by wrowe, with the necessary reverts to fit it on trunk.)

The obvious alternative is to reverse the long-standing design and

* remove the check in core's translate name that currently returns
400, and implement it before calling translate name
* remove the check in alias, rewrite, proxy, whatever that currently declines

(That long-standing design was missing checks in rewrite and proxy,
and changing the design would resolve the same issue in third-party
modules while yanking the right of some module to implement other URI
forms.)
Index: server/protocol.c
===================================================================
--- server/protocol.c   (revision 1232925)
+++ server/protocol.c   (working copy)
@@ -652,26 +652,6 @@
 
     ap_parse_uri(r, uri);
 
-    /* RFC 2616:
-     *   Request-URI    = "*" | absoluteURI | abs_path | authority
-     *
-     * authority is a special case for CONNECT.  If the request is not
-     * using CONNECT, and the parsed URI does not have scheme, and
-     * it does not begin with '/', and it is not '*', then, fail
-     * and give a 400 response. */
-    if (r->method_number != M_CONNECT 
-        && !r->parsed_uri.scheme 
-        && uri[0] != '/'
-        && !(uri[0] == '*' && uri[1] == '\0')) {
-        ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00559)
-                      "invalid request-URI %s", uri);
-        r->args = NULL;
-        r->hostname = NULL;
-        r->status = HTTP_BAD_REQUEST;
-        r->uri = apr_pstrdup(r->pool, uri);
-        return 0;
-    }
-
     if (ll[0]) {
         r->assbackwards = 0;
         pro = ll;
Index: modules/proxy/mod_proxy.c
===================================================================
--- modules/proxy/mod_proxy.c   (revision 1232925)
+++ modules/proxy/mod_proxy.c   (working copy)
@@ -656,18 +656,11 @@
         return OK;
     }
 
-    if (strcmp(r->unparsed_uri, "*") == 0) {
-        /* "*" cannot be proxied. */
+    if ((r->unparsed_uri[0] == '*' && r->unparsed_uri[1] == '\0')
+        || !r->uri || r->uri[0] != '/') {
         return DECLINED;
     }
 
-    /* Check that the URI is valid. */
-    if (!r->uri || r->uri[0] != '/') {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01137)
-                     "Invalid URI in request %s", r->the_request);
-        return HTTP_BAD_REQUEST;
-    }
-
     /* XXX: since r->uri has been manipulated already we're not really
      * compliant with RFC1945 at this point.  But this probably isn't
      * an issue because this is a hybrid proxy/origin server.
Index: modules/mappers/mod_rewrite.c
===================================================================
--- modules/mappers/mod_rewrite.c       (revision 1232925)
+++ modules/mappers/mod_rewrite.c       (working copy)
@@ -4419,18 +4419,11 @@
         return DECLINED;
     }
 
-    if (strcmp(r->unparsed_uri, "*") == 0) {
-        /* Don't apply rewrite rules to "*". */
+    if ((r->unparsed_uri[0] == '*' && r->unparsed_uri[1] == '\0')
+        || !r->uri || r->uri[0] != '/') {
         return DECLINED;
     }
 
-    /* Check that the URI is valid. */
-    if (!r->uri || r->uri[0] != '/') {
-        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00668)
-                     "Invalid URI in request %s", r->the_request);
-        return HTTP_BAD_REQUEST;
-    }
-    
     /*
      *  add the SCRIPT_URL variable to the env. this is a bit complicated
      *  due to the fact that apache uses subrequests and internal redirects

Reply via email to