当前位置:网站首页>Laravel document sorting 3. CSRF protection
Laravel document sorting 3. CSRF protection
2022-06-25 04:18:00 【Angry devil】
Preface :Laravel Document sorting , Only for record , Nothing else .
1、Laravel How to avoid cross site forged requests ?
Generate CSRF token, Verify that the user is the actual sender user .
2、 How to generate CSRF token
<?php echo csrf_field(); ?>
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
It can also be in blade Use in templates :
{ { csrf_field() }}
3、 Usually we don't need to verify this token, that , How did it come true ?
VerifyCsrfToken middleware , The request and session Medium token Is it consistent .
4、 If there are some routes you don't want to be CSRF Protect , How to set ?
stay VerifyCsrfToken Middleware , add to $expect attribute , exclude URI
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
/**
* URIs Should be CSRF Verify execution .
*
* @var array
*/
protected $except = [
'stripe/*',
];
}
5、VerfifyCsrfToken Only check post How to submit parameters ? What else will be checked ?
In the header X-CSRF-TOKEN. Such as the following :
<meta name="csrf-token" content="{ { csrf_token() }}">
This situation , Usually ajax Processing will use :
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
6、Laravel Where else to save CSRF TOKEN?
XSRF-TOKEN cookie in
Ps: You can also use cookie Value to set X-XSRF-TOKEN Request header
7、 Why do we need to forge the request method ?
because html The form does not support put patch or delete The action of , If you have to use these request methods , It must be forged .
8、 An example of request method forgery
<form action="/foo/bar" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{ { csrf_token() }}">
</form>
You can also use auxiliary functions :
<?php echo method_field('PUT'); ?>
stay blade In the template engine :
{ { method_field('PUT') }}
9、 Throw out 404 The wrong way
Method 1 : Auxiliary function abort(404)
Method 2 : Manual throw Symfony\Component\HttpFoundation\Exception\HttpException
Ps: The helper function simply throws a with a specified status code
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
边栏推荐
- Mysql的order by
- 数学分析_笔记_第3章:极限
- 讲座记录《惯性导航的新应用——惯性测量》
- Development of trading system (VI) -- HFT high frequency trading
- Monitoring pancakeswap new token
- Development of trading system (XIII) -- Analysis of quickfix source code
- @RequestBody解决获取参数为null
- PHP代码审计2—这些函数必知必会
- Cesium loading display thermal diagram
- opencv怎么安装?opencv下载安装教程
猜你喜欢

【Proteus仿真】Arduino UNO按键控制数码管闪烁增/减显示

DAP data scheduling function improvement description
![L'épée leetcode fait référence au chemin leetcode de l'offre II 091 pour peindre la maison [planification dynamique] heroding](/img/ad/69fce7cf064479a0ddd477fb935de2.png)
L'épée leetcode fait référence au chemin leetcode de l'offre II 091 pour peindre la maison [planification dynamique] heroding

"Renaissance" in the digital age? The bottom digital collection makes people happy and sad

讲座记录《惯性导航的新应用——惯性测量》

Mathematical analysis_ Notes_ Chapter 3: limits

警惕超范围采集隐私-移动APP违规十宗罪

Hello CTP (III) - CTP quotation API

Development of trading system (II) -- market data

Development of trading system (VIII) -- Construction of low delay network
随机推荐
[harmony OS] [arkui] ETS development graphics and animation drawing
Cesium 加载显示热力图
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
How many images can opencv open?
"Comment positionner l'industrie" dans la planification industrielle locale / parc
Simple integration of client go gin -update
1.初识半音阶口琴
虽然传统意义上的互联网早已不复存在,但这并不代表互联网早已消失不再
openmmlab-环境配置
讲座记录《多种空间大地测量技术的数据处理方法和应用》
SQL, CTE, FLG CASE问题
Qt编译数据库插件通用步骤说明
冷热酸甜、想成就成?冷酸灵母公司登康口腔欲在深交所主板上市
警惕超范围采集隐私-移动APP违规十宗罪
Text keyword extraction: ansj
95% 程序员都在这里摸鱼……
Color NFT series representing diversity launched on the sandbox market platform
Zoran community
Windows 2003 64 bit system PHP running error: 1% is not a valid Win32 Application
佐喃社区