概念
概念
恶意(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'支持)