You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jeff Trawick <tr...@gmail.com> on 2012/06/07 03:08:02 UTC

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

On Sat, May 26, 2012 at 9:19 AM, Rainer Jung <ra...@kippdata.de> wrote:
> On 24.05.2012 17:12, Eric Covener wrote:
>>
>> There are a couple of PR's going around about people who were using
>> rewrite to operate on URL's now kicked out of mod_rewrite by default
>> (IIRC at least proxy:blah and CONNECT arg)
>>
>> Should we just add a mod_rewrite directive or RewriteOption that opts
>> in to handling any URL and document the cautions in the directive?  I
>> don't mind doing that code and doc work to skip the new check to
>> unblock people before 2.2.23.  Please comment!
>
>
> I thought the original problem with mod_rewrite existed only for rules with
> the proxy flag. So rules without the proxy floag should be always OK. Right?
> All bugzilla issues I am aware of only use such OK rules. If we would allow
> them, we would fix the problem for most users.

AFAIK the original problem was just for [P].  I don't know if it is
reasonable to let everything else through, on the theory that there's
no telling what can happen with mod_rewrite :)  (But thus far there
has been no telling what existing behavior became broken by NOT
letting everything else through.)

Elsewhere was reported another legacy configuration with [P] which
does not work with the checks added with 4317.  So just limiting the
new check to cases with [P] isn't sufficient.

>
> For rules with the proxy flag I don't know what the "right" soluation would
> be. I think the original CVE issue was triggered by interpreting some URL
> prefix as a userinfo (the "@" separated part).
>
> Jeff at some point was also looking at it, the patch attached to PR 52774
> and my suggestion of only restricting rewrite rules with proxy flag set. But
> it seems he also didn't come to a result.

What happened was that I signed up for a handful of courses on Udacity
and Coursera and am just now catching my breath this week :)

Here are some valid requests which fail the 4317 checks:

CONNECT foo.example.com[:port]
GET http://foo.example.com
GET proxy:http://foo.example.com/    (rewriting something which was
already proxied internally)

I am leaning towards the likely minority view that it is problematic
to not know what the valid inputs to a ~15 year old module really are,
and we should whitelist a few more patterns such as those above and
see how far it gets us.  Unfortunately this breaks a few users but
they are holding the testcases.

-- 
Born in Roswell... married an alien...
http://emptyhammock.com/

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Rainer Jung <ra...@kippdata.de>.
On 08.06.2012 10:58, Plüm, Rüdiger, Vodafone Group wrote:
>
>
>> -----Original Message-----
>> From: Joe Orton
>> Sent: Freitag, 8. Juni 2012 10:38
>> To: dev@httpd.apache.org
>> Subject: Re: post-CVE-2011-4317 (rewrite proxy unintended
>> interpolation) rewrite PR's
>>
>> On Thu, Jun 07, 2012 at 01:23:29PM -0400, Eric Covener wrote:
>>> e.g. RewriteOptions +"I know I'm running this regex against something
>>> that's not guaranteed to look like a URL-path, and I'll write a regex
>>> that carefully matches/captures the input"
>>
>> How about this?  I'm not sure how to put the right level of fear into
>> the name.  AllowUnsafeURI?  AllowInsecureURIMatch?
>
> +1 for the patch as such. Option name discussion may take some time :-)

+1 as well.

Rainer


RE: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Plüm, Rüdiger, Vodafone Group <ru...@vodafone.com>.

> -----Original Message-----
> From: Joe Orton 
> Sent: Freitag, 8. Juni 2012 10:38
> To: dev@httpd.apache.org
> Subject: Re: post-CVE-2011-4317 (rewrite proxy unintended
> interpolation) rewrite PR's
> 
> On Thu, Jun 07, 2012 at 01:23:29PM -0400, Eric Covener wrote:
> > e.g. RewriteOptions +"I know I'm running this regex against something
> > that's not guaranteed to look like a URL-path, and I'll write a regex
> > that carefully matches/captures the input"
> 
> How about this?  I'm not sure how to put the right level of fear into
> the name.  AllowUnsafeURI?  AllowInsecureURIMatch?

+1 for the patch as such. Option name discussion may take some time :-)

Regards

Rüdiger


Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Joe Orton <jo...@redhat.com>.
On Thu, Jun 07, 2012 at 01:23:29PM -0400, Eric Covener wrote:
> e.g. RewriteOptions +"I know I'm running this regex against something
> that's not guaranteed to look like a URL-path, and I'll write a regex
> that carefully matches/captures the input"

How about this?  I'm not sure how to put the right level of fear into 
the name.  AllowUnsafeURI?  AllowInsecureURIMatch?

(This patch works for the CONNECT rewriting case, I haven't tested the 
other problematic cases.)

Index: modules/mappers/mod_rewrite.c
===================================================================
--- modules/mappers/mod_rewrite.c	(revision 1347667)
+++ modules/mappers/mod_rewrite.c	(working copy)
@@ -190,6 +190,7 @@
 #define OPTION_INHERIT              1<<1
 #define OPTION_INHERIT_BEFORE       1<<2
 #define OPTION_NOSLASH              1<<3
+#define OPTION_ANYURI               1<<4
 
 #ifndef RAND_MAX
 #define RAND_MAX 32767
@@ -2895,6 +2896,9 @@
                          "LimitInternalRecursion directive and will be "
                          "ignored.");
         }
+        else if (!strcasecmp(w, "allowanyuri")) {
+            options |= OPTION_ANYURI;
+        }
         else {
             return apr_pstrcat(cmd->pool, "RewriteOptions: unknown option '",
                                w, "'", NULL);
@@ -4443,8 +4447,14 @@
         return DECLINED;
     }
 
-    if ((r->unparsed_uri[0] == '*' && r->unparsed_uri[1] == '\0')
-        || !r->uri || r->uri[0] != '/') {
+    /* Unless the anyuri option is set, ensure that the input to the
+     * first rule really is a URL-path, avoiding security issues with
+     * poorly configured rules.  See CVE-2011-3368, CVE-2011-4317. */
+    if ((dconf->options & OPTION_ANYURI) == 0
+        && ((r->unparsed_uri[0] == '*' && r->unparsed_uri[1] == '\0')
+            || !r->uri || r->uri[0] != '/')) {
+        rewritelog((r, 8, NULL, "Declining, request-URI '%s' is not a URL-path",
+                    r->uri));
         return DECLINED;
     }
 
Index: docs/manual/mod/mod_rewrite.xml
===================================================================
--- docs/manual/mod/mod_rewrite.xml	(revision 1347667)
+++ docs/manual/mod/mod_rewrite.xml	(working copy)
@@ -188,6 +188,37 @@
       later.</p>
       </dd>
 
+      <dt><code>AllowAnyURI</code></dt>
+      <dd>
+
+      <p>When <directive module="mod_rewrite">RewriteRule</directive>
+      is used in <code>VirtualHost</code> or server context with
+      version 2.2.22 or later of httpd, <module>mod_rewrite</module>
+      will only process the rewrite rules if the request URI is a <a
+      href="./directive-dict.html#Syntax">URL-path</a>.  This avoids
+      some security issues where particular rules could allow
+      "surprising" pattern expansions (see <a
+      href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-3368">CVE-2011-3368</a>
+      and <a
+      href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4317">CVE-2011-4317</a>).
+      To lift the restriction on matching a URL-path, the
+      <code>AllowAnyURI</code> option can be enabled, and
+      <module>mod_rewrite</module> will apply the rule set to any
+      request URI string, regardless of whether that string matches
+      the URL-path grammar required by the HTTP specification.</p>
+
+      <note type="warning">
+      <title>Security Warning</title> 
+
+      <p>Enabling this option will make the server vulnerable to
+      security issues if used with rewrite rules which are not
+      carefully authored.  It is <strong>strongly recommended</strong>
+      that this option is not used.  In particularly, beware of input
+      strings containing the '<code>@</code>' character which could
+      change the interpretation of the transformed URI.</p>
+      </note>
+      </dd>
+
       </dl>
 
 </usage>

RE: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Plüm, Rüdiger, Vodafone Group <ru...@vodafone.com>.

> -----Original Message-----
> From: Eric Covener []
> Sent: Donnerstag, 7. Juni 2012 19:23
> To: dev@httpd.apache.org
> Subject: Re: post-CVE-2011-4317 (rewrite proxy unintended
> interpolation) rewrite PR's
> 
> On Thu, Jun 7, 2012 at 1:14 PM, Jeff Trawick <tr...@gmail.com> wrote:
> > Eric, what was the opt-in exactly?  In what scope would you need to
> > enable it in order to process a CONNECT request?
> 
> e.g. RewriteOptions +"I know I'm running this regex against something
> that's not guaranteed to look like a URL-path, and I'll write a regex
> that carefully matches/captures the input"

Makes sense. +1.

Regards

Rüdiger

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Eric Covener <co...@gmail.com>.
On Thu, Jun 7, 2012 at 1:14 PM, Jeff Trawick <tr...@gmail.com> wrote:
> On Thu, Jun 7, 2012 at 11:55 AM, Joe Orton <jo...@redhat.com> wrote:
>> On Wed, Jun 06, 2012 at 09:08:02PM -0400, Jeff Trawick wrote:
>>> Here are some valid requests which fail the 4317 checks:
>>>
>>> CONNECT foo.example.com[:port]
>>> GET http://foo.example.com
>>> GET proxy:http://foo.example.com/    (rewriting something which was
>>> already proxied internally)
>>>
>>> I am leaning towards the likely minority view that it is problematic
>>> to not know what the valid inputs to a ~15 year old module really are,
>>> and we should whitelist a few more patterns such as those above and
>>> see how far it gets us.  Unfortunately this breaks a few users but
>>> they are holding the testcases.
>>
>> Some thoughts:
>>
>> 1) FUD: if we start relaxing those checks again something else is going
>> to break in an unexpected way.
>
> Certainly a valid fear :)
>
>> 2) mod_rewrite's behaviour should match mod_rewrite's documentation.  If
>> mod_rewrite guarantees that the input to the first rule set (in vhost
>> contex) is a URL-path, it shouldn't arbitrarily ignore that guarantee
>> for "special" URIs.
>>
>> I like Eric's suggestion of an opt-in RewriteOption.  This will avoid
>> having to iterate yet again if the whitelist is either too broad or too
>> narrow, and can make the security implications (such as they are)
>> explicit.
>
> Doesn't that just mean that the security implications are unknown when
> you want mod_rewrite to process a proxied http request or a CONNECT?
> I.e., you have to turn off the sanity checks in order to use certain
> infrequently used features.
>
> Eric, what was the opt-in exactly?  In what scope would you need to
> enable it in order to process a CONNECT request?

e.g. RewriteOptions +"I know I'm running this regex against something
that's not guaranteed to look like a URL-path, and I'll write a regex
that carefully matches/captures the input"

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Joe Orton <jo...@redhat.com>.
On Fri, Jun 08, 2012 at 08:19:22AM -0400, Jeff Trawick wrote:
> On Fri, Jun 8, 2012 at 4:58 AM, Joe Orton <jo...@redhat.com> wrote:
> > Yes, but that was exactly the previous state: the security implication
> > of doing crazy stuff with rewrite rules really is totally unknown.  I
> > wouldn't say "infrequently used features", I'd say "undocumented
> > behaviour which happened to work previously".
> 
> "crazy stuff"/"happened to work" seems a bit convenient for referring
> to some useful functionality which was regressed :(  But as far as we
> know Right Now it is practical for a user to ensure that all their
> rewrite rules are well formed and turn on this option without fear.
> Right?

Right, so long as the rule set is safe for all possible input strings, 
and users realise mod_rewrite does not constrain that set of strings.

Yeah, this is perhaps a "convenient" position to take.  We'd be open to 
the same accusation had we decided that 3368/4317 were config issues not 
security issues, just with a different set of disgruntled users.  I'd 
still go this route, I think; default to safe + config option for 
"unsafe" mode.

> I guess there is no desire among the group to take any of the reported
> regressions and deem the "feature" supported in the normal manner.

Without a config option?  I've no objection but neither any desire to 
climb that mountain myself.  The problem I see is that we'd need a 
better specification for the "rule set input string" to replace 
"URL-path"; I've no handle on how complex that would be.

Regards, Joe

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Jeff Trawick <tr...@gmail.com>.
On Fri, Jun 8, 2012 at 4:58 AM, Joe Orton <jo...@redhat.com> wrote:
> On Thu, Jun 07, 2012 at 01:14:37PM -0400, Jeff Trawick wrote:
>> On Thu, Jun 7, 2012 at 11:55 AM, Joe Orton <jo...@redhat.com> wrote:
>> > I like Eric's suggestion of an opt-in RewriteOption.  This will avoid
>> > having to iterate yet again if the whitelist is either too broad or too
>> > narrow, and can make the security implications (such as they are)
>> > explicit.
>>
>> Doesn't that just mean that the security implications are unknown when
>> you want mod_rewrite to process a proxied http request or a CONNECT?
>> I.e., you have to turn off the sanity checks in order to use certain
>> infrequently used features.
>
> Yes, but that was exactly the previous state: the security implication
> of doing crazy stuff with rewrite rules really is totally unknown.  I
> wouldn't say "infrequently used features", I'd say "undocumented
> behaviour which happened to work previously".

"crazy stuff"/"happened to work" seems a bit convenient for referring
to some useful functionality which was regressed :(  But as far as we
know Right Now it is practical for a user to ensure that all their
rewrite rules are well formed and turn on this option without fear.
Right?

I guess there is no desire among the group to take any of the reported
regressions and deem the "feature" supported in the normal manner.

-- 
Born in Roswell... married an alien...
http://emptyhammock.com/

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Joe Orton <jo...@redhat.com>.
On Thu, Jun 07, 2012 at 01:14:37PM -0400, Jeff Trawick wrote:
> On Thu, Jun 7, 2012 at 11:55 AM, Joe Orton <jo...@redhat.com> wrote:
> > I like Eric's suggestion of an opt-in RewriteOption.  This will avoid
> > having to iterate yet again if the whitelist is either too broad or too
> > narrow, and can make the security implications (such as they are)
> > explicit.
> 
> Doesn't that just mean that the security implications are unknown when
> you want mod_rewrite to process a proxied http request or a CONNECT?
> I.e., you have to turn off the sanity checks in order to use certain
> infrequently used features.

Yes, but that was exactly the previous state: the security implication 
of doing crazy stuff with rewrite rules really is totally unknown.  I 
wouldn't say "infrequently used features", I'd say "undocumented 
behaviour which happened to work previously".

Regards, Joe

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Jeff Trawick <tr...@gmail.com>.
On Thu, Jun 7, 2012 at 11:55 AM, Joe Orton <jo...@redhat.com> wrote:
> On Wed, Jun 06, 2012 at 09:08:02PM -0400, Jeff Trawick wrote:
>> Here are some valid requests which fail the 4317 checks:
>>
>> CONNECT foo.example.com[:port]
>> GET http://foo.example.com
>> GET proxy:http://foo.example.com/    (rewriting something which was
>> already proxied internally)
>>
>> I am leaning towards the likely minority view that it is problematic
>> to not know what the valid inputs to a ~15 year old module really are,
>> and we should whitelist a few more patterns such as those above and
>> see how far it gets us.  Unfortunately this breaks a few users but
>> they are holding the testcases.
>
> Some thoughts:
>
> 1) FUD: if we start relaxing those checks again something else is going
> to break in an unexpected way.

Certainly a valid fear :)

> 2) mod_rewrite's behaviour should match mod_rewrite's documentation.  If
> mod_rewrite guarantees that the input to the first rule set (in vhost
> contex) is a URL-path, it shouldn't arbitrarily ignore that guarantee
> for "special" URIs.
>
> I like Eric's suggestion of an opt-in RewriteOption.  This will avoid
> having to iterate yet again if the whitelist is either too broad or too
> narrow, and can make the security implications (such as they are)
> explicit.

Doesn't that just mean that the security implications are unknown when
you want mod_rewrite to process a proxied http request or a CONNECT?
I.e., you have to turn off the sanity checks in order to use certain
infrequently used features.

Eric, what was the opt-in exactly?  In what scope would you need to
enable it in order to process a CONNECT request?

>
> Regards, Joe

-- 
Born in Roswell... married an alien...
http://emptyhammock.com/

Re: post-CVE-2011-4317 (rewrite proxy unintended interpolation) rewrite PR's

Posted by Joe Orton <jo...@redhat.com>.
On Wed, Jun 06, 2012 at 09:08:02PM -0400, Jeff Trawick wrote:
> Here are some valid requests which fail the 4317 checks:
> 
> CONNECT foo.example.com[:port]
> GET http://foo.example.com
> GET proxy:http://foo.example.com/    (rewriting something which was
> already proxied internally)
> 
> I am leaning towards the likely minority view that it is problematic
> to not know what the valid inputs to a ~15 year old module really are,
> and we should whitelist a few more patterns such as those above and
> see how far it gets us.  Unfortunately this breaks a few users but
> they are holding the testcases.

Some thoughts:

1) FUD: if we start relaxing those checks again something else is going 
to break in an unexpected way.

2) mod_rewrite's behaviour should match mod_rewrite's documentation.  If 
mod_rewrite guarantees that the input to the first rule set (in vhost 
contex) is a URL-path, it shouldn't arbitrarily ignore that guarantee 
for "special" URIs.

I like Eric's suggestion of an opt-in RewriteOption.  This will avoid 
having to iterate yet again if the whitelist is either too broad or too 
narrow, and can make the security implications (such as they are) 
explicit.

Regards, Joe