简体   繁体   English

需要在Apache上允许编码斜杠

[英]Need to allow encoded slashes on Apache

I'm currently trying to place a URL within a URL. 我目前正在尝试在URL中放置一个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. 我知道我必须完成对URL的编码,但是现在我从服务器而不是我的应用程序收到了404错误。 I think my problem lies with apache and can be fixed with the AllowEncodedSlashes On directive. 我认为我的问题出在Apache上,可以通过AllowEncodedSlashes On指令解决。

I've tried putting the directive at the bottom of the httpd.conf to no effect, and am unsure what to do next. 我尝试将指令放在httpd.conf的底部无效,并且不确定下一步该怎么做。 Am I putting it in the right place? 我把它放在正确的位置了吗? If so, does anyone have any other solutions? 如果是这样,还有人有其他解决方案吗?

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. 我有相同的样式URL,并且也在尝试代理它。

Example: Proxy requests from /example/ to another server. 示例:从/example/到另一台服务器的代理请求。

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

Issue 1: Apache believes that's an invalid url 问题1: Apache认为这是无效的URL

Solution: AllowEncodedSlashes On in httpd.conf 解决方案:httpd.conf中的AllowEncodedSlashes On

Issue 2: Apache decodes the encoded slashes 问题2: Apache解码编码的斜杠

Solution: AllowEncodedSlashes NoDecode in httpd.conf (Requires Apache 2.3.12+) 解决方案:httpd.conf中的AllowEncodedSlashes NoDecode (需要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/ ) 问题3: mod_proxy尝试将%2F更改为%252F的URL重新编码(双重编码)(例如/example/http:%252F%252Fwww.someurl.com/

Solution: In httpd.conf use the ProxyPass keyword nocanon to pass the raw URL thru the proxy. 解决方案:在httpd.conf使用ProxyPass关键字nocanon来通过代理传递原始URL。

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

httpd.conf file: httpd.conf文件:

AllowEncodedSlashes NoDecode

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

Reference: 参考:

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. 此问题与Apache Bug 35256不相关。相反,它与Bug 46830有关。虚拟主机不继承AllowEncodedSlashes设置,并且虚拟主机用于许多默认的Apache配置中,例如Ubuntu中的配置。 The workaround is to add the AllowEncodedSlashes setting inside a <VirtualHost> container ( /etc/apache2/sites-available/default in Ubuntu). 解决方法是在<VirtualHost>容器(Ubuntu中为/etc/apache2/sites-available/default )内添加AllowEncodedSlashes设置。

Bug 35256 : %2F will be decoded in PATH_INFO (Documentation to AllowEncodedSlashes says no decoding will be done) 错误35256%2F将在PATH_INFO中解码( AllowEncodedSlashes文档说不会解码)

Bug 46830 : If AllowEncodedSlashes On is set in the global context, it is not inherited by virtual hosts. 错误46830 :如果在全局上下文中设置AllowEncodedSlashes On ,则虚拟主机不会继承它。 You must explicitly set AllowEncodedSlashes On in every <VirtalHost> container. 您必须在每个<VirtalHost>容器中显式设置AllowEncodedSlashes On

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. <VirtualHost>部分中的部分在虚拟主机定义之外的相应部分之后应用。 This allows virtual hosts to override the main server configuration. 这允许虚拟主机覆盖主服务器配置。

I wasted a great many hours on this problem too. 我在这个问题上也浪费了很多时间。 I'm a bit late to the party, but it seems there's a solution now. 我参加聚会有点晚了,但是现在看来有解决方案了。

As per this thread , there is (was) a bug in Apache such that if you have AllowEncodedSlashes On , it prevents the 404, but it mistakenly decodes the slashes, which is incorrect according to the RFC. 按照此线程 ,Apache中有一个(是)错误,如果您具有AllowEncodedSlashes On ,它将阻止404,但会错误地解码斜杠,根据RFC,这是不正确的。

This comment offers a solution, namely to use: 此注释提供了一种解决方案,即使用:

AllowEncodedSlashes NoDecode

in light of all the hassles, i opted for base64_encoding followed by urlencoding. 考虑到所有麻烦,我选择了base64_encoding,然后选择urlencoding。 It works without having to fool around with apache server settings or looking at bug reports. 它的工作无需笨拙的apache服务器设置或查看错误报告。 It also works without having to put the url in the query section. 它也可以工作而不必将URL放在查询部分中。

$enc_url = urlencode(base64_encode($uri_string));

and to get it back 并取回

$url = base64_decode(urldecode($enc_url));

http://example.com/admin/supplier_show/8/YWRtaW4vc3VwcGxpZXJz

http://example.com/admin/supplier_show/93/YWRtaW4vc3VwcGxpZXJzLzEwMA%3D%3D

After a fair bit of testing, and looking at the bug in Apache, I've concluded that despite offered solutions in different forums, this is an unresolved issue in Apache. 经过相当多的测试,并查看了Apache中的错误,我得出的结论是,尽管在不同的论坛中提供了解决方案,但这在Apache中还是一个未解决的问题。 See the bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=35256 查看错误: https//issues.apache.org/bugzilla/show_bug.cgi?id = 35256

The workaround that works for me is to refactor the URI so that the item that can contain the escaped slashes is in the query section of the URI, instead of the path. 对我有用的解决方法是重构URI,以便可以包含转义斜杠的项目位于URI的查询部分中,而不是路径中。 My tests show that when they are there, they don't get filtered out by Apache, no matter the AllowEncodedSlashes and AcceptPathInfo settings. 我的测试表明,当它们在那里时,无论AllowEncodedSlashes和AcceptPathInfo设置如何,它们都不会被Apache过滤掉。

So: http://test.com/url?http%3A%2F%2Fwww.url2.com 因此: http://test.com/url?http%3A%2F%2Fwww.url2.comhttp://test.com/url?http%3A%2F%2Fwww.url2.com

or: http://test.com/url?theURL=http%3A%2F%2Fwww.url2.com 或: http://test.com/url?theURL=http%3A%2F%2Fwww.url2.com : http://test.com/url?theURL=http%3A%2F%2Fwww.url2.com

instead of: http://test.com/url/http%3A%2F%2Fwww.url2.com 而不是: http://test.com/url/http%3A%2F%2Fwww.url2.com : http://test.com/url/http%3A%2F%2Fwww.url2.com

This means an architecture change for our project, but it seems unavoidable. 这意味着我们项目的体系结构更改,但这似乎是不可避免的。 Hope you found a solution. 希望您找到了解决方案。

Replace %2F with %252F at the client side. 在客户端将%2F替换为%252F

This is the double-encoded form of the forward slash. 这是正斜杠的双重编码形式。

So when it reaches the server and gets prematurely decoded it will decode it to %2F which is exactly what you want. 因此,当它到达服务器并过早解码时,它将解码为%2F,这正是您想要的。

I'm getting the same problem with "AllowEncodedSlashes On", and have tried placing the directive in a couple different places: apache2.conf, httpd.conf, and inside a section, as per an example at http://www.jampmark.com/web-scripting/5-solutions-to-url-encoded-slashes-problem-in-apache.html . 我在“ AllowEncodedSlashes On”上遇到了同样的问题,并尝试将指令放置在几个不同的位置:apache2.conf,httpd.conf和节内,如http://www.jampmark上的示例.com / web-scripting / 5-solutions-to-url-encoded-slashes-problem-in-apache.html

If you haven't already, you might want to set your logging level to debug (another directive) and see if you get the error: 如果尚未安装,则可能需要将日志记录级别设置为调试(另一个指令),然后查看是否收到错误:

found %2f (encoded '/') in URI (decoded='/url/http://www.url2.com'), returning 404 在URI(已解码='/ url / http://www.url2.com')中找到%2f(编码为'/'),返回404

other not found errors don't provide this info in the logs. 其他未找到的错误不在日志中提供此信息。 Just another diagnostic... 只是另一个诊断...

Good luck (to both of us)! 祝你好运(我们俩)!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM