csrf

What are some viable techniques for combining CSRF protection with RESTful APIs?

不想你离开。 提交于 2019-11-30 05:50:47
I'm interested in hearing what approaches people have taken when building a RESTful (or quasi-RESTful) API for their web applications. A practical example: Say you have a traditional browser-based web application which uses CSRF protection on all forms. A hidden input with a CSRF protection token is included in each form presented in the browser. Upon submission of the form, if this input does not match the server-side version of token, the form is considered invalid. Now say you want to expose the web application as an API (perhaps using JSON instead of HTML). Traditionally when publishing an

How to enable Spring Security POST redirect after log in with CSRF?

跟風遠走 提交于 2019-11-30 05:43:45
问题 I'm using Spring Security 3.2 with CSRF. My configuration includes this: <csrf /> <form-login default-target-url="/defaultPage"/> When the user does a POST form submit (with a CSRF token) that requires authentication, he is redirected to the log in page. Afterwards, instead of submitting the request, the user is redirected to the defaultPage by Spring Security. I suspect the issue is that the CSRF token gets reset during log in. How can I get such a POST redirect after log in working? Update

Can't create CSRF token with Spring Security

笑着哭i 提交于 2019-11-30 05:19:29
I am using Spring Security 3.2.3 in my Spring MVC application and getting some unexpected behavior. According to the documentation here , it should be possible to use ${_csrf.token} in the meta tags of my html: <meta name="_csrf" content="${_csrf.token}" /> <!-- default header name is X-CSRF-TOKEN --> <meta name="_csrf_header" content="${_csrf.headerName}" /> From where I extract the value of "content" using JQuery and place it into the Request Header using AJAX. For some reason though, Spring Security doesn't "convert" this into an actual token, it just gets sent into the header as a literal

Rails - Losing session with Integration Tests and Capybara - CSRF related?

寵の児 提交于 2019-11-30 04:58:21
I'm using Rails 3.1.0.rc4 and I'm working on doing integration tests with capybara's new Steak-like DSL and Rspec (using Devise authentication) The issue I'm having is that when I run an integration test, the rack-test driver from capybara seems to just completely lose the user's logged in session, in fact, the session seems to just clear out altogether. After days of debugging, I'm at a complete loss as to why. Going line by line through the middleware stack, I believe I've ruled the problem down to something going on in the ActiveRecord::SessionStore that is causing this. I've read here that

Laravel 5 and Internet Explorer : Token Mismatch

心不动则不痛 提交于 2019-11-30 04:37:35
问题 My Laravel5 website uses csrf tokens to prevent CSRF attacks. On Chrome and Firefox, eveything works fine. I submitted the site for my client to test and, when he uses Internet Explorer (9/10), he has "Token mismatch" errors on evey page using the token. I assume it is a cookie/session issue. After some research, I tried removing the slash in the cookie name ("laravel_session"), and changing the session driver ("file" by default). It didn't help. I know my client could change its "trust

Django Ajax CSRF 认证

安稳与你 提交于 2019-11-30 02:37:21
CSRF(Cross-site request forgery跨站请求伪造,也被称为“one click attack”或者session riding,通常缩写为CSRF或者XSRF。是一种对网站的恶意利用。 Django 中自带了 防止CSRF攻击的功能,但是一些新手不知道如何使用,给自己编程带来了麻烦。常常会出现下面django csrf token missing or incorrect的错误。 GET 请求不需要 CSRF 认证,POST 请求需要正确认证才能得到正确的返回结果。一般在POST表单中加入 {% csrf_token %} <form method="POST" action="/post-url/"> {% csrf_token %} <input name='zxdc' value="myvalue"> </form> 如果使用Ajax调用的时候 $.post('/diy/req_user_vehcile/', { csrfmiddlewaretoken: '{{ csrf_token }}', // 增加一个参数csrfmiddlewaretoken plateno: value, }, function (result) { } 注意: django1.8及之前版本 视图为 def myview(request): context_map = {

How to use Zend Framework Form Hash (token) with AJAX

我的未来我决定 提交于 2019-11-30 01:54:57
I have included Zend_Form_Element_Hash into a form multiplecheckbox form. I have jQuery set to fire off an AJAX request when a checkbox is clicked, I pass the token with this AJAX request. The first AJAX request works great, but the subsequent ones fail. I suspect it may be once the token has been validated it is then removed from the session (hop = 1). What would be your plan of attack for securing a form with Zend Framework Hash yet using AJAX to complete some of these requests? I finally abandoned using Zend_Form_Element_Hash and just created a token manually, registered it with Zend

Does AntiForgeryToken in ASP.NET MVC prevent against all CSRF attacks?

假如想象 提交于 2019-11-30 01:52:48
Using AntiForgeryToken requires each request to pass a valid token, so malicious web pages with simple script posting data to my web application won't succeed. But what if a malicious script will first make some simple GET request (by Ajax ) in order to download the page containing the antiforgery token in a hidden input field, extracts it, and use it to make a valid POST ? Is it possible, or am I missing something? Cheekysoft Yes, this is all you need to do. As long as you generate a new token on each protected page, with <%= Html.AntiForgeryToken() %> and always ensure it is checked in any

Rails 5 API protect_from_forgery

喜你入骨 提交于 2019-11-30 01:51:59
I have a Rails 5 API app ( ApplicationController < ActionController::API ). The need came up to add a simple GUI form for one endpoint of this API. Initially I was getting ActionView::Template::Error undefined method protect_against_forgery? when I tried to render the form. I added include ActionController::RequestForgeryProtection and protect_from_forgery with:exception to that endpoint. Which solved that issue as expected. However, when I try to submit this form I get: 422 Unprocessable Entity ActionController::InvalidAuthenticityToken . I've added <%= csrf_meta_tags %> and verified that

How to make sure Rails API is secured from CSRF?

依然范特西╮ 提交于 2019-11-30 01:45:35
问题 I've been developing Rails app with REST API for access from mobile application. It works quite well. When user logs in from mobile application, he gets auth_token that he uses in his future requests to API. The issue is that API is also accessible from web by going to path /api/v1/... and because of this, it has to be protected from CSRF. I have BaseApiController class which inherits from ApplicationController that has protect_from_forgery "enabled". Here's example: class Api::V1: