当前位置:网站首页>CSRF protection mechanism
CSRF protection mechanism
2022-07-19 14:58:00 【Leisurely summer】
1、 What is? csrf
CSRF(Cross-site request forgery), Chinese name : Cross-site request forgery
You can understand that CSRF attack : The attacker stole your identity , Send malicious requests in your name .CSRF The things that can be done include : Send email in your name , Send a message , Stealing your account , Even buying goods , Virtual currency transfer ...... Problems include : Personal privacy disclosure and property security .
CSRF This kind of attack is 2000 It has been proposed by foreign security personnel in , But at home , until 06 It was only in ,08 year , A number of large-scale communities and interactive websites at home and abroad have emerged respectively CSRF Loophole , Such as :NYTimes.com( The New York times )、Metafilter( A large BLOG Website ),YouTube And baidu HI...... And now , Many sites on the Internet are still defenseless , So the security industry says CSRF by “ sleeping giant ”.
2、CSRF Principle

As can be seen from the above figure , To complete once CSRF attack , The victim must complete three steps in turn :
- Log in to trusted sites A, And build locally Cookie.
- Do not log out A Under the circumstances , Visit the danger website B.
- Trigger website B Some of the elements in
3、CSRF Our defense strategy
Defense in the industry right now CSRF There are three main strategies to attack : verification HTTP Referer Field ; Add... To the request address token And verify ; stay HTTP Custom properties in the header and verify .
3.1、 verification HTTP Referer Field
according to HTTP agreement , stay HTTP There is a field in the header called Referer, It records the time to HTTP The source address of the request . In general , Requests to access a security restricted page come from the same website , Request to verify its... In the background Referer value , If it is a domain name starting with its own security website , Then the request is legal . If Referer If it's another website , It could be hackers CSRF attack , Refuse the request .
3.2、 Add... To the request address token And verify
CSRF The attack was successful , Because hackers can completely fake users' requests , All user authentication information in this request exists in cookie in , So hackers can directly use users' own... Without knowing the authentication information cookie To pass security verification . Resist CSRF, The key is to put information in the request that the hacker can't forge , And the information does not exist in cookie In . Can be in HTTP Was added a request in the form of randomly generated parameter token, And build an interceptor on the server side to verify this token, If not in the request token perhaps token The content is not correct , Think it might be CSRF Attack and reject the request .
3.3、 stay HTTP Custom properties in the header and verify
This method is also used token And verify that , Different from the previous method , It's not about token In the form of parameters HTTP In request , But put it in HTTP In the custom attribute in the header .
4、security Medium csrf Defense mechanisms
org.springframework.security.web.csrf.CsrfFilter
csrf Also known as Cross Site Request Forgery ,SpringSecurity For all post Request validation to include system generated csrf Of token Information , If not , False report . To prevent csrf The effect of the attack .(1. Generate token 2. verification token)
4.1、 Turn on csrf protective
// close csrf protective
// http.csrf().disable();
// Turn on csrf protective , Define which paths do not need protection
http.csrf().ignoringAntMatchers("/user/save");4.2、 The page needs to add token value
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>边栏推荐
- session管理
- Data consistency between redis and MySQL
- 详解C语言动态内存管理
- ORA-00054
- Load Objective-C at runtime
- Comparison of two virtual machines
- [flask introduction series] exception handling
- Top domestic experts gathered in Guangzhou to discuss the safety application of health care data
- Which company is better in data filling and report presentation? Yixin ABI gives you the answer
- Compositionapi component development paradigm
猜你喜欢

Abstract classes and derived classes

kube-proxy & Service & Endpoint

国科大. 深度学习. 期末试题与简要思路分析

Oracle - 锁

Which company is better in data filling and report presentation? Yixin ABI gives you the answer

滑動窗口最大值問題

3438. 数制转换

An unforgettable day in 2022 summer camp

详解C语言动态内存管理

Deep understanding of transaction isolation levels
随机推荐
Abstract classes and derived classes
Read the paper: temporary graph networks for deep learning on dynamic graphs
5-21 interceptor
Read the paper: temporary graph networks for deep learning on dynamic graphs
MySQL index (II)
运行时加载 Objective-C
Unity uses a map to control the transparency of the material's main map
SQL wrong questions set of Niuke brush questions
国科大. 深度学习. 期末试题与简要思路分析
1、DBMS基本概念
Deep understanding of transaction isolation levels
中断的分类
Use of token in ogg
MySQL storage functions and triggers
状态机练习
Practice of tDesign in vitest
MySQL CPU使用率飙升,如何定位是被谁占用了
ICML2022 | 几何多模态对比表示学习
国科大.深度学习.期末复习知识点总结笔记
Alibaba microservice component Nacos registry