gpt4 book ai didi

IIS10 URL Rewrite 2.1 双编码问题

转载 作者:行者123 更新时间:2023-12-04 06:51:46 25 4
gpt4 key购买 nike

我有一个带有 的 IIS10 服务器ARR 3.0 和 URL 重写模块 2.1 它充当其他几个 Web 服务器的反向代理。其他服务器在不同的端口上运行,因此 IIS10 服务器在端口 80 上提供“友好 URL”。URL 重写用于将请求传递给后端服务器。

一个这样的服务器是 Jenkins .

Jenkins 有一条警告消息告诉您反向代理是否配置正确(more details here),这条警告消息帮助我找到了反向代理中的问题。

问题是 URL 重写正在以某种方式对我的 URL 进行解码和编码,当它们到达 Jenkins 时,它们与浏览器请求的不同。

示例:

URL 重写规则:

<rule name="Jenkins Rewrite" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*jenkins.mydomain.*" />
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Rewrite" url="http://localhost:8080/{R:1}" appendQueryString="true" />
<serverVariables>
<set name="HTTP_X_FORWARDED_HOST" value="{HTTP_HOST}" />
<set name="HTTP_X_FORWARDED_SCHEMA" value="https" />
<set name="HTTP_X_FORWARDED_PROTO" value="https" />
</serverVariables>
</rule>

发送以下 URL 时:

https://jenkins.mydomain/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%3A%2F%2Fjenkins.mydomain%2Fmanage%3F

我注意到在触发规则之前编码的字符被解码,使得 {R:1} 看起来像这样:
/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https:/jenkins.mydomain/manage/
经过一番研究,我发现我可以使用 {UNENCODED_URL} 而不是 {R:1} 在解码之前获取请求字符串,所以我调整了我的规则操作:
<action type="Rewrite" url="http://localhost:8080{UNENCODED_URL}" appendQueryString="false" />
不幸的是,URL Rewrite 在我的 Rewrite 之后再次对 URL 进行编码,从而使 Jenkins 接收到的 URL 被双重编码:
/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%253A%252F%252Fjenkins.mydomain%252Fmanage%253F
简短摘要:

当您查看此 URL 时:
/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%3A%2F%2Fjenkins.mydomain%2Fmanage%3F
我们拥有的是: /administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/<parameter1>
在哪里 <parameter1> = https%3A%2F%2Fjenkins.mydomain%2Fmanage%3F <parameter1> 中的斜线字符被编码以便 Jenkins 可以知道 path 的一部分是什么什么是 <parameter1> .

这意味着,当 URL 重写解码 URL 时, <parameter1>path 的其余部分混在一起.

期望的结果是获得与浏览器发送的 URL 完全相同但指向 localhost 的 URL:
http://localhost:8080/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/testForReverseProxySetup/https%3A%2F%2Fjenkins.mydomain%2Fmanage%3F
无论如何要禁用 URL 重写模块正在执行的解码/编码操作?

PS:我找到了 blog post关于 URL Rewrite v2.1 功能,它说有一个新标志可用于禁用此行为,但我不知道如何或在何处设置它。

In URL Rewrite versions prior to v7.1.1980, when one tries to use UNENCODED_URL, URL Rewrite will encode it which may lead to double encoding if the original URL was already encoded This is in violation of section 2.4 of RFC3986, which says "Implementations must not percent-encode or decode the same string more than once, as decoding an already decoded string might lead to misinterpreting a percent data octet as the beginning of a percent-encoding, or vice versa in the case of percent-encoding an already percent-encoded string." It also made the use of UNENCODED_URL impractical, especially in reverse forwarder scenarios with ARR where the backend servers expect the URL to be passed unmodified.

In v7.1.1980, we are adding a feature flag, useOriginalURLEncoding that allows you to turn off this non-compliant URL Encoding when set to true. The default behavior will remain unchanged (useOriginalURLEncoding is true by default).



这里有人知道怎么做吗?

最佳答案

我设法解决了这个问题,通过设置 useOriginalURLEncoding = false在我在问题中引用的帖子中进行了描述。

设置标志去IIS Manager然后选择Configuration Editor并转到 system.webServer/rewrite/rules 部分,您将在其中找到 useOriginalURLEncoding旗帜。

将该标志设置为 false,当使用 {UNENCODED_URL} 时,URL 重写将不再对 URL 进行编码。规则中的变量。

关于IIS10 URL Rewrite 2.1 双编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47146029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com