基于复杂方案OWSAP CsrfGuard的CSRF安全解决方案(适配nginx + DWR)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1、什么是CSRF?
已经有很多博文讲解其过程和攻击手段,在此就不重复了。 O(∩_∩)O 不清楚的同学,请自行搜索或按链接去了解: http://blog.csdn.net/Flaght/article/details/3873590

2、CSRFGuard_Project
开源项目 CSRFGuard,介绍了如何使用在 HTTP 请求中加入 token 并验证的方法来抵御 CSRF。 https://www.owasp.org/index.php/Category:OWASP_CSRFGuard_Project

3、检测CSRF方法?
OWASP上面有一个叫做CSRFTester的工具,可以构建进行测试。
下载链接:https://www.owasp.org/index.php/CSRFTester
教程指引:http://www.zyiqibook.com/article216.html

4、如何防御CSRF?
我们采用CSRFGuard_Project方案 JAVA DOM方式。
配置如下:

1)引入csrfguard-3.1.0.jar到你的工程: 2)配置web.xml:


    
       JavaScriptServlet
       org.owasp.csrfguard.servlet.JavaScriptServlet
    
    
       JavaScriptServlet
       /JavaScriptServlet
    
    
      Owasp.CsrfGuard.Config
      WEB-INF/csrfguard.properties
    
    
       Owasp.CsrfGuard.Config.Print
       true
    
    
    
        org.owasp.csrfguard.CsrfGuardHttpSessionListener
    
    
        org.owasp.csrfguard.CsrfGuardServletContextListener
    
    
        CSRFGuard
        org.owasp.csrfguard.CsrfGuardFilter
    
    
        CSRFGuard
        /*
    

3)引入配置文件csrfguard.js csrfguard.properties(jar包META-INF里面有) csrfguard.properties配置文件中有几点需要注意:

可以指定加载的js,为方便管理,我放在WEB-INF目录下:

org.owasp.csrfguard.JavascriptServlet.sourceFile = WEB-INF/csrfguard.js

org.owasp.csrfguard.TokenName 对于nginx分发多servers的情况,nginx默认过滤带下划线的header,要么改掉nginx的配置,要么改这个参数的值。 参考:http://www.ttlsa.com/nginx/nginx-proxy_set_header

#>>>>>>>>>>>>>--author by caizhengluan  e-mail: [email protected]
#Nginx ignores the underlined header variables by default.
# Please do not set "TokenName" has any underlines if you can't unkonwn how to change nginx's configuration.
org.owasp.csrfguard.TokenName=PAYCSRFTOKEN
#<<<<<<<<<<<<<--author by caizhengluan  e-mail: [email protected]

org.owasp.csrfguard.JavascriptServlet.refererMatchDomain 对于nginx分发多servers的情况,需要设置为false

#>>>>>>>>>>>>>--author by caizhengluan  e-mail: [email protected]
# If you have cluster and nginx, please set this value to false.Otherwise, you will can't visit into the servers when you access nginx address.
org.owasp.csrfguard.JavascriptServlet.refererMatchDomain = false
#<<<<<<<<<<<<<--author by caizhengluan  e-mail: [email protected]

4、如何具体防御DWR和我们的页面? 在你的页面最后加上这么一句:



输入图片说明

转载自:https://my.oschina.net/langxSpirit/blog/678901

转载于:https://my.oschina.net/sniperLi/blog/778266

你可能感兴趣的:(基于复杂方案OWSAP CsrfGuard的CSRF安全解决方案(适配nginx + DWR))