【问题标题】:How to stop redirecting to other domain by configuring IIS or web.config?如何通过配置 IIS 或 web.config 停止重定向到其他域?
【发布时间】:2016-02-21 03:10:27
【问题描述】:

在现代 CMS 中,有许多地方使用 returnUrl 查询字符串重定向用户。例如,成功登录后将用户重定向到内部 URL。

问题是任何人都可以修改 returnUrl,因此很容易受到攻击。处理此问题的一种方法是在向客户端浏览器发送 302 HTTP 代码(重定向)之前验证应用程序脚本/程序的参数。但是,这需要更改应用程序代码。

如何在 IIS 级别处理它?如果用户在不接触应用程序代码的情况下被重定向到其他域,是否可以显示错误页面?

【问题讨论】:

    标签: asp.net redirect iis


    【解决方案1】:

    我想通了。 安装 IIS URL Rewrite Module 然后编辑 web 应用程序的 web.config 并在 system.webServer 节点中添加以下内容:

    <rewrite>
        <outboundRules>
            <rule name="Rewrite Location Header" preCondition="IsRedirection" enabled="true">
                <match serverVariable="RESPONSE_Location" pattern="http[s]{0,1}://localhost/(.*)" negate="true" />
                <conditions>
                </conditions>
                <action type="Rewrite" value="http://{HTTP_HOST}/error.html" replace="true" />
            </rule>
            <preConditions>
                <preCondition name="IsRedirection">
                    <add input="{RESPONSE_STATUS}" pattern="3\d\d" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      相关资源
      最近更新 更多