csrf(cross site request forgery)攻击笔记

概念

概念

        恶意(evil)网站携带正规网站凭据信息,向正规网站发送恶意请求;(由于携带的凭据cookie为正规网站签发的凭据,正规网站未识别出为恶意请求,执行结果造成损失)

保护措施

        1、使用csrf token(工作原理:打开受保护资源的时候携带随机csrf token,在之后

              提交请求时,将csrf token一并提交给后台,用于csrf校验)

                1.1、csrf token 应该不会被浏览器自动放置到http请求中,所以应该在header

                        或parameter中携带要求的token信息进行校验

                1.2、csrf token 应该使用post等安全的请求方式获取,如果使用get请求方式可能会导

                        致泄露

        2、使用samesite attribute(参见:https://docs.spring.io/spring-security/site/docs/current/reference/html5/#csrf-explained

Set-Cookie: JSESSIONID=randomid; Domain=bank.example.com; Secure; HttpOnly; SameSite=Lax

                2.1、SameSite的合理值为:

                        Strict - when specified any request coming from the same-site will include the                         cookie. Otherwise, the cookie will not be included in the HTTP request.

                        Lax - when specified cookies will be sent when coming from the same-site or                         when the request comes from top-level navigations and the method is idempotent.                         Otherwise, the cookie will not be included in the HTTP request.

                2.2、SameSite属性依赖于浏览器是否支持此属性(大部分现代浏览器都支持此属性

                        ,部分旧浏览器可能bu'支持)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值