何时使用隐藏字段,何时使用标题以及为什么?X-XSRF_TOKEN 什么时候使用?X-CSRF TOKEN我们什么时候使用?
When use hidden field and when use header and why ?
X-XSRF_TOKEN when we use?
X-CSRF TOKEN when we use?
所有这些都是为了跨站点请求伪造保护,并且您只需要使用其中一个即可向后端发送请求.不同的名称来自不同的框架.
All of them are for cross site request forgery protection and you need to use just one of them when sending a request to backend. Different names come from different frameworks.
这一切都是关于向后端发送一个 csrf 值.然后后端会将其与该特定用户的数据库中存储的 csrf 值进行比较,如果匹配,则允许处理请求.
It's all about sending a csrf value to backend. Then backend will compare it with the csrf value stored in database for that specific user and if it matches, it will allow processing the request.
csrf :
x-csrf-token:
csrf 值 放在一个元标记中,然后在前端我们可以从该元标记中获取值并将其发送到后端.莉>csrf value in a meta tag while rendering the html, then in front end we can get the value from that meta tag and send it to backend.Laravel 特定:
Laravel specific:
laravel 作为后端时.Laravel 会自动检查此标头并将其与数据库中的有效 csrf 值 进行比较.(laravel 有一个中间件)laravel as backend. Laravel checks this header automatically and compares it to the valid csrf value in database.(laravel has a middleware for this)x-xsrf-token:
axios 等流行库,会自动从 xsrf-token cookie 中获取此标头的值并将其放入每个请求标头中.xsrf-token 的 cookie,然后我们使用 angular 或 axios 的前端框架会自动使用它.axios, automatically get value of this header from xsrf-token cookie and put it in every request header.xsrf-token in backend, then our front end framework that uses angular or axios will use it automatically.Laravel 特定:
Laravel specific:
axios 或 angular 和 laravel 时,你不需要做任何事情.只需登录用户,'auth' 中间件就可以完成这项工作.x-csrf-token 相比,它是一个更大的字符串,因为 cookie 在 laravel 中是加密的.axios or angular with laravel, you don't need to do anything. just log user in and 'auth' middleware will do the job.x-csrf-token because cookies are encrypted in laravel.这篇关于X-XSRF-TOKEN 和 X-CSRF-TOKEN 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Laravel Eloquent Union 查询Laravel Eloquent Union query(Laravel Eloquent Union 查询)
覆盖 Laravel 5 辅助函数Overwrite laravel 5 helper function(覆盖 Laravel 5 辅助函数)
laravel querybuilder 如何在 where 函数中使用 likelaravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函数中使用 like)
响应内容必须是实现 __toString()、“boolean"和“The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(响应内容必须是实现 __toS
Laravel 5 的角色,如何只允许管理员访问某些根Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允许管理员访问某些根)
Laravel Auth - 使用 md5 而不是集成的 Hash::make()Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())