htaccess的保护,防止委任代表代表、htaccess

2023-09-02 20:32:20 作者:怦然心动

我就是用这个code(净推荐一些论坛),以阻止代理到我的网站文件,使用htaccess文件:

I was using this code (recommended by some forums in the net) to block Proxies to my website files, using htaccess file:

RewriteEngine on    
RewriteCond %{HTTP:XROXY_CONNECTION}    !^$ [OR]    
RewriteCond %{HTTP:X-FORWARDED-FOR}     !^$ [OR]    
RewriteCond %{HTTP:FORWARDED-FOR}       !^$ [OR]    
RewriteCond %{HTTP:X-FORWARDED}         !^$ [OR]    
RewriteCond %{HTTP:VIA}                 !^$ [OR]    
RewriteCond %{HTTP:FORWARDED}           !^$ [OR]    
RewriteCond %{HTTP:USERAGENT_VIA}       !^$ [OR]    
RewriteCond %{HTTP:X_FORWARDED_FOR}     !^$ [OR]    
RewriteCond %{HTTP:PROXY_CONNECTION}    !^$ [OR]    
RewriteCond %{HTTP:XPROXY_CONNECTION}   !^$ [OR]    
RewriteCond %{HTTP:HTTP_PC_REMOTE_ADDR} !^$ [OR]    
RewriteCond %{HTTP:HTTP_CLIENT_IP}      !^$     
RewriteRule ^(.*)$ - [F]

这是工作完美。然而,今年以来,GOOGLE更新了自己的Andr​​oid平台有一个所谓的新功能: 数据通信pression代理(使用内部命名为浏览器的设置选项降低数据使用情况)。根据这个帖子更新了2014年1月,我可以看到它是Android设备的新功能: https://developers.google.com/chrome/mobile/docs /数据-COM pression

It was working perfect. However, since this year, GOOGLE updated his ANDROID platform with a new feature called: "Data Compression Proxy" (using the option inside the settings of the browser named "Reduce Data Usage"). According to this post Updated in January 2014, I can see it is a new feature for Android Devices: https://developers.google.com/chrome/mobile/docs/data-compression

现在htaccess的code仍阻挡代理这正是我需要的,但另外它阻止了使用Chrome移动的Andr​​oid设备的所有请求。即使在Android手机用户连接到通过WIFI或移动4G网络没有任何代理。代理设置是由谷歌内部在自己的服务器设置。

Now the htaccess code is still blocking proxies which is what I needed, but additionally it is blocking all requests coming from Android Devices using Chrome Mobile. Even when the Android Phone User is connected to the internet via WIFI or Mobile 4G without any Proxy. The proxy setting is set by Google internally on their servers.

当然,如果用户禁用该选项(见我设定中的默认在电话),他们可以访问到我的网站。

Of course, if the user disable that option (which I see was set "on" by default in the phones), they can access to my websites.

我需要知道,如果有一种方法可以白名单内同一code谷歌Android代理发愁吗?我的意思是,A code来自Google.com?

I needed to know if there is a WAY to Whitelist GOOGLE android PROXIES inside same code? I mean, A code for referrer coming from Google.com ?

我尝试这样做了,但是没有奏效:

I tried this already but didn't work:

的RewriteCond%{HTTP_REFERER}! google.com。的[OR]

RewriteCond %{HTTP_REFERER} !.google.com. [OR]

我不想改变原来的code到像每个IP的封锁,因为封锁代理罪犯IP将在该文件中创建一个大名单,并且难以控制和管理。

I would not want to change the original code to something like blocking per IP's, since Blocking proxies by offenders IP would create a big list on that file, and harder to control and manage it.

请让我知道。谢谢你。

推荐答案

有一对夫妇的事情可以做,你可以白名单的所有Android的用户代理,或者你可以白名单内经的头时,它的COM pression代理。当白名单,它不能成为一个或的情况下,它必须满足

There's a couple of things you can do, you can whitelist all "Android" user agents, or you can whitelist the "VIA" header when it's the compression proxy. When you whitelist, it can't be an "OR"'s condition, it must be satisfied.

这是Android的Chrome浏览器通过COM pression代理一个典型的请求看起来是这样的:

A typical request from android chrome through the compression proxy looks something like this:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Forwarded: for="xxx"
Scheme: http
Via: 1.1 Chrome Compression Proxy
X-Forwarded-For: xxx
Connection: Keep-alive
User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; Nexus 5 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36

所以,你可以反对这门亲事,用户代理或通过的Chrome浏览器的COM pression代理的Linux的Andr​​oid的一部分:

So you can match against the "Linux; Android" part of the user agent or the "Chrome Compression Proxy" in the via:

RewriteEngine on   
RewriteCond %{HTTP_USER_AGENT} !Linux; Android [234].[0-9]

RewriteCond %{HTTP:XROXY_CONNECTION}    !^$ [OR]    
RewriteCond %{HTTP:X-FORWARDED-FOR}     !^$ [OR]    
RewriteCond %{HTTP:FORWARDED-FOR}       !^$ [OR]    
RewriteCond %{HTTP:X-FORWARDED}         !^$ [OR]    
RewriteCond %{HTTP:VIA}                 !^$ [OR]    
RewriteCond %{HTTP:FORWARDED}           !^$ [OR]    
RewriteCond %{HTTP:USERAGENT_VIA}       !^$ [OR]    
RewriteCond %{HTTP:X_FORWARDED_FOR}     !^$ [OR]    
RewriteCond %{HTTP:PROXY_CONNECTION}    !^$ [OR]    
RewriteCond %{HTTP:XPROXY_CONNECTION}   !^$ [OR]    
RewriteCond %{HTTP:HTTP_PC_REMOTE_ADDR} !^$ [OR]    
RewriteCond %{HTTP:HTTP_CLIENT_IP}      !^$     
RewriteRule ^(.*)$ - [F]

RewriteEngine on   
RewriteCond %{HTTP:VIA} !Chrome Compression Proxy

RewriteCond %{HTTP:XROXY_CONNECTION}    !^$ [OR]    
RewriteCond %{HTTP:X-FORWARDED-FOR}     !^$ [OR]    
RewriteCond %{HTTP:FORWARDED-FOR}       !^$ [OR]    
RewriteCond %{HTTP:X-FORWARDED}         !^$ [OR]    
RewriteCond %{HTTP:VIA}                 !^$ [OR]    
RewriteCond %{HTTP:FORWARDED}           !^$ [OR]    
RewriteCond %{HTTP:USERAGENT_VIA}       !^$ [OR]    
RewriteCond %{HTTP:X_FORWARDED_FOR}     !^$ [OR]    
RewriteCond %{HTTP:PROXY_CONNECTION}    !^$ [OR]    
RewriteCond %{HTTP:XPROXY_CONNECTION}   !^$ [OR]    
RewriteCond %{HTTP:HTTP_PC_REMOTE_ADDR} !^$ [OR]    
RewriteCond %{HTTP:HTTP_CLIENT_IP}      !^$     
RewriteRule ^(.*)$ - [F]