Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

RewriteRule brings Apache to its knees

Last post 02-27-2010, 1:45 PM by Peadarin. 1 replies.
Sort Posts: Previous Next
  •  01-06-2010, 11:59 AM 58249

    RewriteRule brings Apache to its knees

    hi there

    The following quickly nobbles apache on a powerful box. I presume there is a lot of recursion in the regex.

    RewriteRule ^(([^/\.\?]+/?)*)$ index.php?c=$1 [L,QSA]

    Any gurus shed any light please?

    Cheers

    Dude

  •  02-27-2010, 1:45 PM 60183 in reply to 58249

    Re: RewriteRule brings Apache to its knees

    This rule looks to match relative directory names on linux/unix systems, where directory names cannot have a . (dot) or file names must have a suffix with a . (dot), and directory names must have at least 1 byte and cannot contain dot or question marks, I think that was the intent of this rule

     in fact, it matches absolutely everything : matching any non / followed by an optional / .....  and excluding  . (dot) and ? (question mark)  on the way.

    Are you sure you want to filter something with this expression before running index.php ? Do you really need a filter which excludes only . and ? ? Please provide what type of string you want to match with your redirection rule (as per the site guidelines)

     

    I think you might hit a simple backtracking problem

    the general form ([^x]+x?)*   makes sone NFA engines (based on Thompson ideas from the 70's) going nuts.

    Assuming you want to process directory names like the following ones  (without . not ? in the directory names)

    abc   abcd/fgh    abcd/

    The following rule might help with less severe backtracking

         - / is not optional between directory elements,

         - use non-grouping syntax when you do not need the corresponding backreferences.

    ((?:[^/.?]+/)*[^/.?]*)

    Backtracking is then restricted to the last directory elements, and is not exponentially complex. This now depends on your regular expression engine.

    You might wish to update it with a more secure range of bytes, like excluding null bytes, control bytes, spaces, take care about newlines and the interaction with $ and ^ by disabling multiline, and so on. This depends on your application in index.php

     

     

    An other thing : inside a character class, . is a ".", ? is "?" , there is no need to escape them.

     

View as RSS news feed in XML