验证query_string中的域是否为rewritecond

时间:2012-06-26 06:40:38

标签: apache mod-rewrite url-rewriting query-string

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

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

无效请求的示例:

  1. 方案://something.example.com/aaa/bbb/ccc RETURNURL = HTTPS:?//something.evil.com/home
  2. 方案://something.example.com/aaa/bbb/ccc RETURNURL = HTTP://www.google.com
  3. 方案://something.example.com/aaa/bbb/ccct RETURNURL = HTTPS:?//something.evil.com/blah URL = HTTPS://test.example.com/home
  4. 到目前为止,在我的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]
    

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

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

    我需要验证query_string returnurl中返回的域。

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

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

1 个答案:

答案 0 :(得分: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]
相关问题