当前位置:网站首页>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
边栏推荐
- Flink Yarn Per Job - CliFrontend
- 【Leetcode】475. Heaters
- OpenCV DNN blogFromImage()详解
- color transparency parameter
- 仿牛客网项目第三章:开发社区核心功能(详细步骤和思路)
- Flink Yarn Per Job - 提交流程一
- 20220725资料更新
- 工作5年,测试用例都设计不好?来看看大厂的用例设计总结
- oozie startup error on cdh's hue, Cannot allocate containers as requested resource is greater than maximum allowed
- CDH6 Hue to open a "ASCII" codec can 't encode characters
猜你喜欢

ICLR 2022最佳论文:基于对比消歧的偏标签学习

Classical Literature Reading--DLO

Making a Simple 3D Renderer

GetHashCode与Equals

20220725 Information update

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

Thymeleaf简介

security CSRF漏洞保护

EasyExcel的简单读取操作

Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
随机推荐
Win11如何获得最佳电源效率?
如何用Redis实现分布式锁?
Classical Literature Reading--DLO
【MySQL系列】MySQL索引事务
Flink学习第三天——一文带你了解什么是Flink流?
OpenCV DNN blogFromImage()详解
Flink Yarn Per Job - CliFrontend
获取小猪民宿(短租)数据
DVWA靶场环境搭建
ICLR 2022 Best Paper: Partial Label Learning Based on Contrastive Disambiguation
ansible模块--copy模块
深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
DOM 基础操作
【Leetcode】475. Heaters
Win11内存管理错误怎么办?
[Camp Experience Post] 2022 Cybersecurity Summer Camp
recursion: method calls itself
Win10安装DBeaver连接MySQL8、导入和导出数据库详细教程
多御安全浏览器android版更新至1.7,改进加密协议
yay 报错 response decoding failed: invalid character ‘<‘ looking for beginning of value;