当前位置:网站首页>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
边栏推荐
- 【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。
- 2D 照片变身 3D 模型,来看英伟达的 AI 新“魔法”!
- SEO的5大关键指标:排名+流量+会话+停留时长+跳出率
- 如何绘制产业招商地图
- cesium 图形标注圆形、正方形、多边形、椭圆等
- How to quickly deliver high-value software
- Text keyword extraction: ansj
- "How to carry out industrial positioning" in local / Park industrial planning
- client-go gin的简单整合十一-Delete
- 讲座记录《捷联惯导解算的历史及发展》
猜你喜欢

2. play the chromatic harmonica

navicat可不可以直接操作安卓数据库SQLite

Development of trading system (VIII) -- Construction of low delay network

DAP data scheduling function improvement description
![[proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube](/img/28/33f3e9736a68439b5bcdc4e75c939c.png)
[proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube

冷热酸甜、想成就成?冷酸灵母公司登康口腔欲在深交所主板上市

95% 程序员都在这里摸鱼……

文本关键词提取:ansj

BSC parsing input data of transaction

地方/园区产业规划之 “ 如何进行产业定位 ”
随机推荐
Simple integration of client go gin -update
AI quantitative transaction (I) -- Introduction to quantitative transaction
《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台
Siddhartha: the book of life can be regurgitated frequently
[harmony OS] [ark UI] basic ETS context operations
警惕超范围采集隐私-移动APP违规十宗罪
Development of trading system (x) -- fix agreement
代表多样性的彩色 NFT 系列上线 The Sandbox 市场平台
Intel 13th generation core showed its true colors for the first time: 68mb cache improved significantly
Exercise: how difficult is it to simulate the blessing lottery two-color ball - China 500W grand prize? Just run the code.
The 5th series of NFT works of missing parts was launched on the sandbox market platform
Development of trading system (VIII) -- Construction of low delay network
"How to carry out industrial positioning" in local / Park industrial planning
《悉达多》:一生之书,可以时常反刍
LeetCode 劍指Offer II 091 粉刷房子[動態規劃] HERODING的LeetCode之路
Numpy NP tips: use OpenCV to interpolate and zoom the array to a fixed shape cv2 resize(res, dsize=(64, 64), interpolation=cv2. INTER_ CUBIC)
How many images can opencv open?
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
2022-06-21-flink-49 (I. SQL manual)
How to use crawlers to capture bullet screen and comment data of station B?