当前位置:网站首页>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
边栏推荐
- Where is the red area of OpenCV?
- 升级cmake
- Vigilance against over range collection of privacy - ten mobile app violations
- La gamme NFT Color, qui représente la diversité, est en ligne sur la plate - forme du marché Sandbox
- @Requestbody solution get parameter is null
- Development of trading system (x) -- fix agreement
- DAP数据调度功能完善说明
- openmmlab-环境配置
- 《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台
- 小心被偷脸!天天用的人脸识别风险原来这么多?
猜你喜欢

1. Phase II of the project - user registration and login

【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。

numpy np tips:使用opencv对数组插值放缩到固定形状 cv2.resize(res, dsize=(64, 64), interpolation=cv2.INTER_CUBIC)

数学分析_笔记_第3章:极限

文本关键词提取:ansj

NFT Insider #63:The Sandbox与时代杂志达成合作,YGG成立西班牙subDAO

Crawler crawls Sina Weibo data

论文阅读《LSD-SLAM: Large-Scale Direct Monocular SLAM》

"Grammar sugar" -- my new programming knowledge

Summary of various problems encountered by cocos2d-x
随机推荐
《悉达多》:一生之书,可以时常反刍
【LeetCode】148. 排序链表
The art of writing simple code
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
Although the Internet in the traditional sense has long ceased to exist, this does not mean that the Internet has long disappeared
DAP数据调度功能完善说明
General steps for QT compiling database plug-ins
PHP代码审计1—PHP.ini的那些事
How to use ide to automatically sign and debug Hongmeng application
Text keyword extraction: ansj
【LeetCode】143. Rearrange linked list
《Missing Parts》NFT 作品集第 5 系列上线 The Sandbox 市场平台
Coinlist queuing tutorial to improve the winning rate
IntStream API介绍
AI quantitative transaction (II) -- tushare financial data framework
[proteus simulation] Arduino uno key controls the flashing increase / decrease display of nixie tube
mysql的tinyint字段类型判断的疑惑
Uniapp makes mobile app programs, using uni Choosevideo record video, video playback is fuzzy, and the resolution is low
地方/園區產業規劃之 “ 如何進行產業定比特 ”
Development of trading system (VIII) -- Construction of low delay network