csrf

What is the right way to resolve token mismatch error in laravel?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 16:00:24
since I've updated laravel to 5.4 I constantly get: TokenMismatchException in VerifyCsrfToken.php line 68 exception thrown. After some digging and reading through a whole lot of posts and github issues I've figured that my tokens aren't matching :). The point is that my laravel app sets the encrypted version of the token "XSRF-TOKEN" instead of its plain (X-CSRF-TOKEN) counterpart and the helper csrf_token() spits out the plain token hence mismatching tokens. Confusing though why documentation mentions X-XSRF-TOKEN when I get XSRF-TOKEN (missing X-) instead? So the questions are: Has the

yii2 csrf验证以及token管理

≡放荡痞女 提交于 2019-12-04 15:07:38
开启/关闭csrf 默认情况下yii2是开启了csrf验证功能的,如果需要关闭它的话,只要在控制器中设置一个属性就可以: public $enableCsrfValidation = false; 一般情况下不建议关闭,但api场景可能需要关闭。 TOKEN生成管理 token生成有三种方式 meta标签 在模板中使用 <?=yii\helpers\Html::csrfMetaTags();?> 即可生成meta标签,如下 <meta name="csrf-param" content="_csrf"> <meta name="csrf-token" content="NnNIMTVXUFJuN3tJDDAPAFk4OWBFOAgiBEIiX1kUPTdlJytXQAh9YQ=="> meta标签主要是给ajax用的,ajax提交的时候可以直接从meta中获取csrf-token然后一并提交给后端,csrf-param就是参数名称,也可以直接通过header头提交,以jquery为例: $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); 表单隐藏域 使用 <?=yii\helpers\Html::beginForm();?> 替代手动输入 <form>

How to detect CSRF vulnerabilities [closed]

◇◆丶佛笑我妖孽 提交于 2019-12-04 15:01:11
Closed . This question needs to be more focused . It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post . Closed 5 years ago . given a website, how to detect potential CSRF vulnerabilities? thanks in advance SilverlightFox This is a CSRF attack:- A page on www.evil.com that the victim is enticed to browse contains the following code:- <form method="post" action="https://www.example.com/executeAction"> <input type="hidden" name="action" value="deleteAllUsers"> </form> <script>document.forms[0].submit()<

Using AngularJS with SpringSecurity3.2 for CSRF

天涯浪子 提交于 2019-12-04 14:26:07
问题 AngularJS index.html <head> <meta name="_csrf" content="${_csrf.token}"/> <!-- default header name is X-CSRF-TOKEN --> <meta name="_csrf_header" content="${_csrf.headerName}"/> </head> SpringSecurity 3.2 Spring uses HttpSessionCsrfTokenRepository which by default gives header name for CSRF as X-CSRF-TOKEN , however Anuglar convention is X-XSRF-TOKEN I wanted to extend HttpSessionCsrfTokenRepository and override the header name, but since it is marked final I ended up implementing a custom

Angular2 and Django: CSRF Token Headache

扶醉桌前 提交于 2019-12-04 14:18:46
The Issue I'm Having I'm making an Ajax POST request from my Angular2 client to my Django (v1.9) backend (both on localhost, different ports). I'm not yet using the Django REST framework, I'm just dumping the JSON in Django without any add-ons. I have been issued a csrf token by the server, and I'm manually sending it back in the HTTP headers (I can see it there when I make the call). However, I still get the error from django: Forbidden (CSRF cookie not set.) I've read a number of other threads, and tried a few things, but still can't get Django to accept the CSRF token. Client side code:

Gets error “Cannot get CSRF” when trying to install jenkins-plugin using ANSIBLE

一个人想着一个人 提交于 2019-12-04 13:47:16
I am using ANSIBLE to install jenkins on CENTOS. The installation works fine but when it comes to the task of installing plugin, i get the following error. fatal: [jenkins]: FAILED! => {"changed": false, "details": "Request failed: <urlopen error [Errno 111] Connection refused>", "failed": true, "msg": "Cannot get CSRF"} The code is as follows. - name: Install jenkins rpm_key: state: present key: https://pkg.jenkins.io/redhat-stable/jenkins.io.key - name: Add Repository for jenkins yum_repository: name: jenkins description: Repo needed for automatic installation of Jenkins baseurl: http://pkg

Protecting prototype.js based XHR requests against CSRF

痞子三分冷 提交于 2019-12-04 12:19:59
Django has been updated to 1.3, and in fact ever since 1.2.5, it has extended the scheme to pass a Cross Site Request Forgery protection token to XMLHttpRequests. The Django folks helpfully provide an example for jQuery to apply a specific header to every XHR. Prototype (and thus Scriptaculous) have to comply to this scheme, yet I can't find a way to tell prototype to add the X-CSRFToken header. The best would be to do it once in a way that applies it across the app (like for jQuery). Is there a way to do that? This is a wild guess but you could try extending the base AJAX class... Ajax.Base

Correctly set headers for Laravel 5 CSRF Token

浪子不回头ぞ 提交于 2019-12-04 11:48:27
Alright, been searching this one for hours and just can't find the start of a solution. I am using an angularJS frontend with a laravel backend. Restangular is my communcation service. My POST are fine, because I can include the _token in the data and it will work. But for Restangular to call a destroy function it looks like... Restangular.all('auth/logout').remove(); //maps to AuthController@Destroy All fine, but then you will get a TOKENMISMATCH Exception, which is a good security messure Since I can't find a way to include the _token into the remove, since it's body-less essentially, I

Is it a good practice to store the csrf token in meta tag?

旧街凉风 提交于 2019-12-04 11:39:19
问题 If I make a POST request without using form and want to prevent CSRF attack, what I can do is to set the csrf-token in meta tag and put it back to the header when the request is triggered. Is it a good practice? <meta name="csrf-token" content="xxx"> Put the token back via the header, using JQuery for example: $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); 回答1: Yes this is good practice. If you are using ajax I think this is the cleanest solution.

How to prevent Cross-site request forgery (CSRF) effectively in PHP

半世苍凉 提交于 2019-12-04 11:26:56
问题 I am trying to prevent CSRF in php in the following way: A $_SESSION['token'] is generated at the start of each page. I already know that using $_COOKIES is completely wrong since they are send automatically for each request. In each <form> , the following input: <input type="hidden" name="t" value="<?php echo '$_SESSION['token']; ?>"> is appended. The $_SESSION['token']; is validated with the $_POST['t'] Now I have several small questions: Is this a good way to prevent CSRF? If not please