0

我使用的网络服务器是 Apache 2.2。我正在尝试验证外部方发送的查询字符串中的域。

有效请求的示例: https ://something.example.com/aaa/bbb/ccc?returnurl=https://test.example.com/home

无效请求示例:

  1. scheme://something.example.com/aaa/bbb/ccc?returnurl=https://something.evil.com/home
  2. scheme://something.example.com/aaa/bbb/ccc?returnurl=http://www.google.com
  3. scheme://something.example.com/aaa/bbb/ccct?returnurl=https://something.evil.com/blah?url=https://test.example.com/home

到目前为止,在我的 httpd.conf 文件中,我有:

    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^/aaa/bbb/ccc$
    RewriteCond %{QUERY_STRING} !(\.|https://|http://)example\.com(\.|/)|(\.|https://|http://)exampledev\.com(\.|/) [NC]
    RewriteRule ^(.*) / [R=403,L]

上面的代码基本上是查看查询字符串,如果 example.com 和 exampledev.com 不在 query_string 中,则将用户重定向到禁止页面。

此代码仅完成部分工作,因为无效请求编号 3 将被视为包含 example.com,这可能被视为网络钓鱼攻击

不知何故,我需要验证在 query_string returnurl 中返回的域。

http:// 或 httpd:// .com 或 .net 或 .org 或任何其他顶级域之间的字符串。

有人可以帮助或建议我如何验证作为 returnurl 查询字符串返回的域吗?

4

1 回答 1

0

使用以下内容:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/aaa/bbb/ccc$
RewriteCond %{QUERY_STRING} !(returnurl|[&]returnurl)=(http|https)://([a-zA-Z0-9]+[.]example[.]com|[a-zA-Z0-9]+[.]exampledev[.]com|example[.]com|exampledev[.]com)[&]{0,1}
RewriteRule ^(.*) / [R=403,L]
于 2012-06-26T15:49:08.823 回答