ATS中开启Refer防盗链功能

来源:互联网 发布:网络女歌手名字 编辑:程序博客网 时间:2024/06/06 05:36

ATS默认提供了对Referer头的http request的防盗链功能,主要应用于图片,对视频等会使用级别更高的防盗链功能,比如事先约定好key,采用md5或HMAC-Sha1算法加密等。

在remap.config中按如下格式设置:

map_with_referer client-URL origin-server-URL redirect-URL regex1 [regex2 ...]

配置
同时需要在records.config中做如下相应配置:
启用deep linking protection
CONFIG proxy.config.http.referer_filter INT 1
启用redirect-URL的运行时格式化(测试时没有作用)
CONFIG proxy.config.http.referer_format_redirect INT 1

正则表达式说明
正则表达式只针对有Referer头的请求进行合法性校验,当然没有Referer头的请求也是允许的
在正则表达式中,*表示通配,~表示取反,*和~的不同组合能生成不同的filtering rules,比如:
~*表示Referer头可选,*~表示带有Referer头的请求将要求验证合法性

举例
map_with_referer http://y.foo.bar.com/x/yy/  http://foo.bar.com/x/yy/ http://games.bar.com/new_games .*\.bar\.com www.bar-friends.com
解释:
Referer头必须在request中,只有 ”.*.bar.com” and “www.bar-friends.com”被允许

map_with_referer http://y.foo.bar.com/x/yy/  http://foo.bar.com/x/yy/ http://games.bar.com/new_games * ~.*\.evil\.com
解释:
Referer头必须在request中,除了”.*.evil.com”以外,所有的referer都允许

map_with_referer http://y.foo.bar.com/x/yy/  http://foo.bar.com/x/yy/ http://games.bar.com/error ~* * ~.*\.evil\.com
解释:
Referer头可选,但是当Referer头存在时,只有来自”.*.evil.com”的请求被重定向到redirect-URL

map_with_referer http://y.foo.bar.com/x/yy/  http://foo.bar.com/x/yy/ http://pics.taobaocdn.com/bao/album/wp/pic_fobbiden.png ~* ^http://[^/]+.(baidu|taobao|alibaba|alipay|google|search.msn).com(.cn|)/
解释:
Referer头可选,但是当Referer头存在时,如来源请求不是从后面这些网站来的,则给它返回一个禁止使用的图片。

测试实践
在命令行使用curl来测试,修改Referer头比较方便
测试的结果是,正则表达式是这样的
map_with_refer http://www.baidu.com/ http://10.10.110.142/ http://10.10.110.142/505.html  ~* .*\.baidu\.com
0 0
原创粉丝点击