当前位置:网站首页>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
边栏推荐
- Axure教程-新手入门基础(小白强烈推荐!!!)
- 使用Ganache、web3.js和remix在私有链上部署并调用合约
- 辛普森悖论
- LeetCode_279_完全平方数
- Quartus uses tcl files to quickly configure pins
- WEB安全基础 - - - XRAY使用
- background-image使用
- 在MySQL中使用MD5加密【入门体验】
- 学习英语的网站与资料
- A brief analysis of mobile APP security testing in software testing, shared by a third-party software testing agency in Beijing
猜你喜欢

A brief analysis of mobile APP security testing in software testing, shared by a third-party software testing agency in Beijing

TCP 可靠吗?为什么?

Thinkphp 5.0.24变量覆盖漏洞导致RCE分析

Making a Simple 3D Renderer

Thymeleaf简介

DOM 基础操作

字节跳动面试官:请你实现一个大文件上传和断点续传

Excel导入和导出

使用Ganache、web3.js和remix在私有链上部署并调用合约

ICLR 2022最佳论文:基于对比消歧的偏标签学习
随机推荐
在linux下MySQL的常用操作命令
Bean的生命周期
【Leetcode】475. Heaters
Flink Yarn Per Job - Yarn应用
thinkphp漏洞总结
Chrome书签插件,让你实现高效整理
【Leetcode】473. Matchsticks to Square
在CentOS下安装MySQL
Docker实践经验:Docker 上部署 mysql8 主从复制
程序员还差对象?new一个就行了
YOLO等目标检测模型的非极大值抑制NMS和评价指标(Acc, Precision, Recall, AP, mAP, RoI)、YOLOv5中[email protected]与
The Spark of Sql join on the and and where
在MySQL中使用MD5加密【入门体验】
ansible模块--copy模块
background-image使用
LeetCode_322_零钱兑换
WEB安全基础 - - - XRAY使用
@Transactional注解在类上还是接口上使用,哪种方式更好?
The third chapter of the imitation cattle network project: develop the core functions of the community (detailed steps and ideas)
@Scheduled注解详解