当前位置:网站首页>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
边栏推荐
- Shutter fittedbox component
- Development of trading system (VI) -- HFT high frequency trading
- Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
- Development of trading system (VII) -- Analysis of trading delay
- Mathematical analysis_ Notes_ Chapter 3: limits
- (ultra detailed onenet TCP protocol access) arduino+esp8266-01s accesses the Internet of things platform, uploads real-time collected data /tcp transparent transmission (and how to obtain and write Lu
- 1280_ C language to find the average value of two unsigned integer
- 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)
- 讲座记录《惯性导航的新应用——惯性测量》
- Hello CTP (IV) - CTP transaction API
猜你喜欢

How many images can opencv open?

Intel 13th generation core showed its true colors for the first time: 68mb cache improved significantly
![[team learning] SQL programming language notes - task04](/img/3e/c75f5b4610c6b6700567fe75cd2339.png)
[team learning] SQL programming language notes - task04

Cesium graphic annotation circle, square, polygon, ellipse, etc

client-go gin的简单整合十-Update

How to use crawlers to capture bullet screen and comment data of station B?

Cesium 加载显示热力图

1280_C语言求两个无符号整形的平均值

地方/園區產業規劃之 “ 如何進行產業定比特 ”

numpy np tips:使用opencv对数组插值放缩到固定形状 cv2.resize(res, dsize=(64, 64), interpolation=cv2.INTER_CUBIC)
随机推荐
微信小程序中的列表渲染
2022-06-21-flink-49 (I. SQL manual)
Simple integration of client go gin 11 delete
【LeetCode】22. 括号生成
opencv最大能打开多少图像?
Intel 13代酷睿首次露出真面目:68MB缓存提升明显
【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。
Development of trading system (II) -- market data
Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
Nodejs 通过Heidisql连接mysql出现ER_BAD_DB_ERROR: Unknown database 'my_db_books'
PHP code audit 2 - these functions must be known and understood
PHP code audit 1 - php Ini
Crawler grabs the idea of reading on wechat
[kubernetes series] installation and use of Helm
1. Phase II of the project - user registration and login
讲座记录《惯性导航的新应用——惯性测量》
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
“语法糖”——我的编程新知
Development of trading system (VII) -- Analysis of trading delay
1.初识半音阶口琴