Questions tagged [csrf-protection]

Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF (sometimes pronounced sea-surf) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts. Unlike cross-site scripting (XSS), which exploits the trust a user has for a particular site, CSRF exploits the trust that a site has in a user's browser.

Cross-site request forgery, also known as a one-click attack or session riding and abbreviated as CSRF (sometimes pronounced sea-surf) or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts. Unlike cross-site scripting (XSS), which exploits the trust a user has for a particular site, CSRF exploits the trust that a site has in a user's browser.

Web sites have various CSRF countermeasures available:

  • Requiring a secret, user-specific token in all form submissions and side-effect URLs prevents CSRF; the attacker's site cannot put the right token in its submissions. This technique is commonly referred to as the Synchronizer Token Pattern.
  • Requiring the client to provide authentication data in the same HTTP Request used to perform any operation with security implications (money transfer, etc.)
  • Limiting the lifetime of session cookies
  • Ensuring that there is no clientaccesspolicy.xml file granting unintended access to Silverlight controls
  • Ensuring that there is no crossdomain.xml file granting unintended access to Flash movies
  • Verifying that the request's header contains a X-Requested-With (used by Ruby on Rails before v2.0 and Django before v1.2.5), or checking the HTTP Referer header and/or HTTP Origin header. These protections have been proven insecure under a combination of browser plugins and redirects which can allow an attacker to provide custom HTTP headers on a request to any website, hence allowing a forged request.

Links:

712 questions
9
votes
1 answer

Does django csrf token must be unique on every request?

I have a question about Django CsrfViewMiddleware mechanism. I know, that Django: Set new csrftoken cookie on every request. Check, than X-CSRFToken header value (or hidden input "csrfmiddlewaretoken") must be equals to csrftoken cookie. But…
akozin
  • 529
  • 1
  • 7
  • 18
9
votes
2 answers

CSRF (Cross-site request forgery) protection in spring MVC

I'm little confuse in this CSRF (Cross-site request forgery) protection in spring. No I have my jsp and my controller and a web service. What I want to do is validate the token at the web service level and if token is a match, run the web service…
Ravindu
  • 2,408
  • 8
  • 30
  • 46
9
votes
4 answers

File upload in Struts2 along with the Spring CSRF token

I use, Spring Framework 4.0.0 RELEASE (GA) Spring Security 3.2.0 RELEASE (GA) Struts 2.3.16 In which, I use an in-built security token to guard against CSRF attacks.
Tiny
  • 27,221
  • 105
  • 339
  • 599
9
votes
5 answers

Spring CSRF token does not work, when the request to be sent is a multipart request

I use, Spring Framework 4.0.0 RELEASE (GA) Spring Security 3.2.0 RELEASE (GA) Struts 2.3.16 In which, I use an in-built security token to guard against CSRF attacks. The Struts form looks like the following.
Tiny
  • 27,221
  • 105
  • 339
  • 599
9
votes
2 answers

Preventing CSRF for websockets

I'm currently considering CSRF vulnerabilities in websockets. I've already blocked all cross-domain websocket requests, however there exist scripts (such as this python bad boy) to get around such security measures. Is it worth including a token in…
user1161657
  • 971
  • 2
  • 10
  • 24
8
votes
2 answers

CSRF token problem with CodeIgniter

I am having a very weird CSRF protection problem in CodeIgniter. I have made sure that I use form_open to start my form, csrf_protection is set to true in the config file, and I have also made sure that the hidden csrf name and value fields match…
Koes Bong
  • 1,113
  • 3
  • 15
  • 28
8
votes
3 answers

Rails CSRF protection with Single Page Application (react, angular, ember)

Ok. I officially lost my mind with this problem. Let's take a default Rails application (5, but I tried also with a 4 default app). I'm trying to use a simple javascript code to send an ajax POST request to one controller action. In my…
user4412054
8
votes
1 answer

Django 1.2.4 CSRF verification failed

Django 1.2 is consistently giving me this CSRF verification error when I perform a POST form. I "think" I've done all the things asked in the Django 1.2 docs, namely, Ensure MIDDLEWARE_CLASSES is included with…
Bryan
  • 3,220
  • 3
  • 26
  • 31
8
votes
0 answers

CSRF - Referer when performing ajax request from chrome extension with Django Backend

I am using the latest versions of Django and Django Rest Framework. My web application provide an API that is used currently by the front end only. I am on the process to create a chrome extension using the same API routes. When I use the local…
8
votes
1 answer

Symfony2: Invalid CSRF token while remember me authentication

I have application written in Symfony 2.8.11 and FosUserBundle 2.0.0-beta1. User can connect to the site via VPN or basic auth. Mostly they use Internet Explorer 11 on Windows 7. Some of them are experiencing a Invalid CSRF token issue in random…
dees91
  • 1,211
  • 13
  • 21
8
votes
3 answers

ForbiddenError: invalid csrf token, express js

I've tried to get csurf to work but seem to have stumbled upon something. The code so far looks like this: index.ejs
. …
Drwk
  • 107
  • 1
  • 1
  • 9
8
votes
1 answer

How to use Express JS 4.0's csurf?

I have been checking csurf's wiki, but it is empty. This module adds a csrfToken() function to user requests, but then, how should I use it? Can someone give a code example with explanations? What should I do on user side? What should I do on…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
8
votes
1 answer

Struts2 token interceptor: CSRF protection

I am trying to protect my web application from CSRF attacks by using struts token interceptor. The problem I am facing right now is our JSP pages makes more than one call to server (While JSP is converted to JS a struts token is added to JS.But in…
Mok
  • 277
  • 1
  • 6
  • 16
7
votes
2 answers

CSRF protection with a React Form, a Flask server, and Flask-WTF

TL;DR I need to protect my form from CSRF attacks and I want to use ReactJS for the frontend and Flask/Flask-WTF for the backend. I’m refactoring a website built with Python, Flask, and Flask-WTF for forms and I want to use React for the frontend…
Hum4n01d
  • 1,312
  • 3
  • 15
  • 30
7
votes
1 answer

Correct use of protect_from_forgery in Rails app serving Web and API

I am developing a Rails 4 app that serves a mobile app through an API, and has a web UI for admins to manage the application. There's also a couple of web pages that users will see (successful e-mail confirmation and reset password). I created two…
Roma149
  • 1,401
  • 1
  • 12
  • 11