Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2395

rewrite() handler can't be used with any URL containing encoded characters

XMLWordPrintable

      There is a bit of a catch-22 that makes it basically impossible to use the rewrite() handler with any URL containing encoded characters, such as a space.  

      Take for example, the following URL:

      localhost/foo%20bar
      

      and the following simple rewrite:

      rewrite( '/index.cfm%{REQUEST_URL}' ) 

      The final URL will incorrectly be this:

      localhost/index.cfm/foo%2520bar
      

      which double encodes the space.

      The issue is two fold:

      • The rewrite() handler uses the RelativePathAttribute which specifically requires a decoded path as it will encode any % chars it contains 
      • The only exchange attributes for getting the request URL ( %{REQUEST_PATH}, and  
        %{RELATIVE_PATH} ) both represent the encoded form of the URI.  The exchange has the decoded version of the URI as exchange.getRequestPath() but there is no exchange attribute in the predicate language to access it!

      I'll also point out it's quite confusing that the predicate attribute actually called REQUEST_PATH doesn't actually return the exchanges request path, but instead the relative path!  

      So basically, how do you do a rewrite of the path and not get double-encoded characters?  I'll also point out, this ticket of mine from 2 years ago would have offered a workaround had it been completed :/  

      https://issues.redhat.com/browse/UNDERTOW-2120

      I recommend adding a new exchange attribute to the predicate language called %{DECODED_REQUEST_PATH} which returns the actual exchange.getRequestPath() as I have done in my app here:

      https://github.com/Ortus-Solutions/runwar/commit/5c05cddf9fca7296707c473ea834c834d760067e#diff-82022da60e22864a43ce51a715347bdd160acc972d78939c408f038a742d044c

      I also recommend improving the docs for the rewrite handler to make it more clear it requires a decoded path. 

      https://undertow.io/undertow-docs/undertow-docs-2.0.0/#rewrite-handler 

       

              Unassigned Unassigned
              bdw429s Brad Wood
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: