阻止打开 URL 从 gorilla/mux 重定向

Prevent Open URL Redirect from gorilla/mux

我正在使用 Go + gorilla/mux v1.4 框架开发 RESTful 网络应用程序。发布后的一些基本安全测试揭示了应用程序中的 Open URL Redirection 漏洞,允许用户提交带有外部 URL 的特制请求,导致服务器以 301 重定向响应。

我使用 Burp Suite and found that any request that redirects to an external URL in the app seems to be responding with a 301 Moved Permanently. I've been looking at all possible ways to intercept these requests before the 301 is sent but this behavior seems to be baked into the net/http server implementation.

测试了这个

这是发送到服务器的原始请求 (myapp.mycompany.com:8000):

GET http://evilwebsite.com HTTP/1.1
Accept: */*
Cache-Control: no-cache
Host: myapp.mycompany.com:8000
Content-Length: 0

任何时候的响应都是:

HTTP/1.1 301 Moved Permanently
Location: http://evilwebsite.com/
Date: Fri, 13 Mar 2020 08:55:24 GMT
Content-Length: 0

尽管检查 request.URL 以防止 http.handler 中的此类重定向,但我没有任何运气让请求到达处理程序。似乎基础 http 网络服务器正在执行重定向,但不允许它到达我在 PathPrefix("/").Handler 代码中定义的自定义处理程序代码。

我的目标是确保应用程序 returns 对此类请求发出 404-Not Found 或 400-Bad Request。有没有其他人用 gorilla/mux 遇到过这种情况。我对 Jetty 网络应用程序进行了同样的尝试,发现它返回了一个完全有效的 404。我已经用了几天了,真的可以使用一些想法。

这不是声称的 Open URL 重定向安全问题。此请求无效,因为路径包含绝对 URL,其域与 Host header 不同。没有理智的客户端(即浏览器)可以首先被引诱发出这样的无效请求,因此没有实际的攻击向量。

当然,可以创建自定义客户端来提交此类请求。但是也可以使自定义客户端以 non-standard 方式解释服务器响应或直接访问恶意 URL 而无需联系您的服务器。这意味着在这种情况下客户端本身将是问题而不是服务器响应。