Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to allow encoded slashes on Apache

I'm currently trying to place a URL within a URL. For example:

http://example.com/url/http%3A%2F%2Fwww.url2.com 

I'm aware that I have to encode the URL, which I have done, but now I am getting a 404 error back from the server rather than my app. I think my problem lies with apache and can be fixed with the AllowEncodedSlashes On directive.

I've tried putting the directive at the bottom of the httpd.conf to no effect, and am unsure what to do next. Am I putting it in the right place? If so, does anyone have any other solutions?

like image 638
tommizzle Avatar asked Dec 08 '10 17:12

tommizzle


People also ask

What is AllowOverride all in Apache?

Apache has an option called “AllowOverride” which allows you to override some Apache settings via a . htaccess file you can place in a directory. In it, you can override PHP settings, create URL rewrites, … Pretty much the basics for every website.

What is ServerAdmin in Apache?

The ServerAdmin and ServerTokens directives control what information about the server will be presented in server-generated documents such as error messages. The ServerTokens directive sets the value of the Server HTTP response header field.

What is IfModule in Apache?

<IfModule> is simply a directive that tests the condition "is the named module loaded by apache httpd" (in your example mod_expires). It allows people to produce conditional based configuration for different installations where certain modules may be present or not.

What is MultiViews Apache?

A MultiViews search is where the server does an implicit filename pattern match, and choose from amongst the results. For example, if you have a file called configuration.


2 Answers

I kept coming across this post for another issue. Let me just explain real quick.

I had the same style URL and was also trying to proxy it.

Example: Proxy requests from /example/ to another server.

/example/http:%2F%2Fwww.someurl.com/ 

Issue 1: Apache believes that's an invalid url

Solution: AllowEncodedSlashes On in httpd.conf

Issue 2: Apache decodes the encoded slashes

Solution: AllowEncodedSlashes NoDecode in httpd.conf (Requires Apache 2.3.12+)

Issue 3: mod_proxy attempts to re-encode (double encode) the URL changing %2F to %252F (eg. /example/http:%252F%252Fwww.someurl.com/)

Solution: In httpd.conf use the ProxyPass keyword nocanon to pass the raw URL thru the proxy.

ProxyPass http://anotherserver:8080/example/ nocanon 

httpd.conf file:

AllowEncodedSlashes NoDecode  <Location /example/>   ProxyPass http://anotherserver:8080/example/ nocanon </Location> 

Reference:

  • http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
  • http://www.silverdisc.co.uk/blog/2009/02/28/url-canonicalisation-and-normalisation
  • Cannot match %2F in mod_rewrite
like image 155
technocrat Avatar answered Sep 18 '22 13:09

technocrat


This issue is not related to Apache Bug 35256. Rather, it is related to Bug 46830. The AllowEncodedSlashes setting is not inherited by virtual hosts, and virtual hosts are used in many default Apache configurations, such as the one in Ubuntu. The workaround is to add the AllowEncodedSlashes setting inside a <VirtualHost> container (/etc/apache2/sites-available/default in Ubuntu).

Bug 35256: %2F will be decoded in PATH_INFO (Documentation to AllowEncodedSlashes says no decoding will be done)

Bug 46830: If AllowEncodedSlashes On is set in the global context, it is not inherited by virtual hosts. You must explicitly set AllowEncodedSlashes On in every <VirtalHost> container.

The documentation for how the different configuration sections are merged says:

Sections inside <VirtualHost> sections are applied after the corresponding sections outside the virtual host definition. This allows virtual hosts to override the main server configuration.

like image 23
Roger Dahl Avatar answered Sep 20 '22 13:09

Roger Dahl