当前位置:网站首页>security CSRF Vulnerability Protection
security CSRF Vulnerability Protection
2022-08-02 00:07:00 【Three or two lines of program】
I. Overview of CSRF
xss exploits user trust in websites
csrf exploits the website's trust in the user's browser
Example

Second, CSRF defense
1. Defense strategy
Through the token synchronization mode, in addition to the default cookie parameter in each http request, the server generates a random string called csrf token. After opening, the httpsession saves a copy, and the front-end request arrivesWhen comparing the requested csrf token information with the server, if they are not equal, the http request will be rejected
Considering that the website may place external links, it is required to be idempotent when requesting, so there is no need to use CSRF tokens for methods such as HEAD OPTIONS TRACE. Forcible use may lead to token leakage
2. Traditional web development configuration
@Configurationpublic class SecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().formLogin().and()//Open csrf.csrf();}}
3. Front-end and back-end separation configuration
The default is that csrf is stored in the server httpsession. In front-end and back-end separation, it is necessary to put the generated csrf into the cookie and obtain the token in the cookie for submission when requesting.
Modify csrf into cookie
@Configurationpublic class SecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().anyRequest().authenticated().and().formLogin().and()//Open csrf.csrf()//Save the token to the cookie and allow the cookie front end to get it.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());}}Visit the login interface to view cookies

Send request with token
The first type: request other interfaces and carry it in the request header
X-XSRF-TOKEN:value in cookie
The second type: carry in the request parameters
_csrf:value in cookie
边栏推荐
- 【Leetcode】479. Largest Palindrome Product
- Spark Sql之union
- [LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph
- Win11内存管理错误怎么办?
- 【Leetcode】478. Generate Random Point in a Circle(配数学证明)
- Win10安装DBeaver连接MySQL8、导入和导出数据库详细教程
- 洞见云原生微服务及微服务架构浅析
- Enterprise firewall management, what firewall management tools are there?
- 递归:方法调用自身
- oozie startup error on cdh's hue, Cannot allocate containers as requested resource is greater than maximum allowed
猜你喜欢

数据机构---第五章树与二叉树---二叉树的概念---应用题

2022 6th Strong Net Cup Part WP

企业防护墙管理,有什么防火墙管理工具?

技术分享 | 接口测试中如何使用Json 来进行数据交互 ?

CDH6 Hue to open a "ASCII" codec can 't encode characters

在CDH的hue上的oozie出现,提交 Coordinator My Schedule 时出错

Architecture basic concept and nature of architecture

Win11内存管理错误怎么办?

yay 报错 response decoding failed: invalid character ‘<‘ looking for beginning of value;

使用Jenkins做持续集成,这个知识点必须要掌握
随机推荐
[LeetCode304 Weekly Competition] Two questions about the base ring tree 6134. Find the closest node to the given two nodes, 6135. The longest cycle in the graph
Flink学习第四天——完成第一个Flink 流批一体案例
伸展树的特性及实现
Quartus uses tcl files to quickly configure pins
Spark Sql之join on and和where
UI自动化测试框架搭建-标记性能较差用例
easy-excel 解决百万数据导入导出,性能很强
cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
QML包管理
学习英语的网站与资料
Docker实践经验:Docker 上部署 mysql8 主从复制
经典文献阅读之--DLO
GIF制作-灰常简单的一键动图工具
根本上解决mysql启动失败问题Job for mysqld.service failed because the control process exited with error code
LeetCode_279_完全平方数
Various Joins of Sql
一款简洁的文件传输工具
多御安全浏览器android版更新至1.7,改进加密协议
【Leetcode】473. Matchsticks to Square
Flink学习第三天——一文带你了解什么是Flink流?