Apache 为rewritecond验证查询字符串中的域

Apache 为rewritecond验证查询字符串中的域,apache,mod-rewrite,url-rewriting,query-string,Apache,Mod Rewrite,Url Rewriting,Query String,我使用的Web服务器是Apache2.2。我正在尝试验证外部方发送的查询字符串中的域 有效请求的一个示例: 无效请求的示例: scheme://something.example.com/aaa/bbb/ccc?returnurl=https://something.evil.com/home scheme://something.example.com/aaa/bbb/ccc?returnurl=http://www.google.com scheme://something.example

我使用的Web服务器是Apache2.2。我正在尝试验证外部方发送的查询字符串中的域

有效请求的一个示例:

无效请求的示例:

  • scheme://something.example.com/aaa/bbb/ccc?returnurl=https://something.evil.com/home
  • scheme://something.example.com/aaa/bbb/ccc?returnurl=http://www.google.com
  • 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不在查询字符串中,则将用户重定向到禁止页面

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

    不知何故,我需要验证查询字符串returnurl中返回的域

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

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

    使用以下命令:

    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]
    

    谢谢你在这方面的帮助,例如:returnurl=google.comsometingbad.com到目前为止,我已将此代码重写为cond%{QUERY_STRING}!(returnurl)[&]returnurl)=(http | https)://(示例1(\.com\.com\.au)[/])示例2(‌​\.com\.com\.au)[/]\[a-zA-Z0-9]+[.]example1(\.com\.com\.au)[/]\[a-zA-Z0-9]+[.]ex‌​ample2(\.com\.com\.au)[/]\[a-zA-Z0-9]+[.][a-zA-Z0-9]+[.]exmaple2(\.com\.com\.au‌​)[/])[&]{0,1}这将停止“.com.au”和“.com”后面的任何字符串,但必须有[/]。我不知道如何说[/\]。非常感谢您的帮助。这可能会完成任务。(\.com$\.com\.au$\.com/\.com\.au/)