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
141
votes
2 answers

CSRF Token necessary when using Stateless(= Sessionless) Authentication?

Is it necessary to use CSRF Protection when the application relies on stateless authentication (using something like HMAC)? Example: We've got a single page app (otherwise we have to append the token on each link:
97
votes
11 answers

Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'

After configuring Spring Security 3.2, _csrf.token is not bound to a request or a session object. This is the spring security config:
Hugo Robayo
  • 1,110
  • 1
  • 7
  • 7
69
votes
4 answers

Laravel 5.6 - Passport JWT httponly cookie SPA authentication for self consuming API?

NOTE: I had 4 bounties on this question, but non of the upvoted answers below are the answer needed for this question. Everything needed is in Update 3 below, just looking for Laravel code to implement. UPDATE 3: This flow chart is exactly the flow…
Wonka
  • 8,244
  • 21
  • 73
  • 121
42
votes
4 answers

How can I disable Django's csrf protection only in certain cases?

I'm trying to write a site in Django where the API URLs are the same as user-facing URLs. But I'm having trouble with pages which use POST requests and CSRF protection. For example, if I have a page /foo/add I want to be able to send POST requests…
lucas
  • 1,910
  • 2
  • 21
  • 25
34
votes
2 answers

How to does the token prevent csrf attack?

I have read about CSRF and how the Unpredictable Synchronizer Token Pattern is used to prevent it. I didn't quite understand how it works. Let's take this scenario : A user is logged into a site with this form:
david
  • 3,310
  • 7
  • 36
  • 59
27
votes
3 answers

angular4 httpclient csrf does not send x-xsrf-token

In angular documentation, it is mentioned that the angular httpclient will automatically send the value of cookie XSRF-TOKEN in the header X-XSRF-TOKEN of post request. Documentation link But it does not send the header for me. Here is my…
netuser
  • 553
  • 1
  • 6
  • 11
27
votes
2 answers

Why can't a malicious site obtain a CSRF token via GET before attacking?

If I understand correctly, in a CSRF attack a malicious website A tells my browser to send a request to site B. My browser will automatically include my B cookies in that request. Although A cannot see those cookies, if I'm already authenticated in…
thelastone
  • 475
  • 4
  • 11
24
votes
1 answer

How to selectively disable CSRF check in Phoenix framework

I'm trying to create a Facebook Page Tab which points to my website. Facebook sends a HTTP POST request to the url of my website. The problem here is that the server has a built-in CSRF check, and it returns the following…
N. Sola
  • 340
  • 4
  • 11
24
votes
5 answers

How to send csrf_token() inside AngularJS form using Laravel API?

I am trying to build an angular + laravel rest application. I can get the views of my database. When I try to add new items. I get 500 error telling me mismatch csrf token. My form layout is : …
ytsejam
  • 3,291
  • 7
  • 39
  • 69
21
votes
1 answer

Why does the CSRF token in Rails not prevent multiple tabs from working properly?

After reading about how the CSRF protection works in Rails, I tried to trigger CSRF protection by doing this: Note: We are using cookie based sessions. Visit login page. Check CSRF token in meta => abc123 Open a 2nd browser tab, and visit the same…
you786
  • 3,659
  • 5
  • 48
  • 74
21
votes
3 answers

how to implement csrf protection for cross domain requests

I have two web apps, one for the Web UI in AngularJS and one for the REST webservices in Java. Both are deployed on separate domains. The applications uses cookie for authentication. Whenever user enters a valid username and password, server returns…
user3565529
  • 1,317
  • 2
  • 14
  • 24
21
votes
3 answers

CSRF token collisions with multiple tabs

I built CSRF protection in my application, by simply generating a random token on every page load, putting it into session, and then binding the token to the tag attribute like: Then on…
Justin
  • 42,716
  • 77
  • 201
  • 296
18
votes
4 answers

Get the CSRF token in test

I'm writing functional test and i need to make ajax post request. "The CSRF token is invalid. Please try to resubmit the form". How can i get the token in my functional test ? $crawler = $this->client->request( 'POST', $url, array( …
bux
  • 7,087
  • 11
  • 45
  • 86
18
votes
2 answers

Reasons for spontaneously authenticity token rejection on production site

My Rails application throws an ActionController::InvalidAuthenticityToken from time to time. It occurs spontaneously once a month or so. As I don't think that there is some other site trying a CSRF attack, I started to make my thoughts about this…
Markus Graf
  • 533
  • 3
  • 16
18
votes
2 answers

How to use Flask-WTForms CSRF protection with AJAX?

Flask-WTForms provides CSRF protection. It works great when using normal HTML forms, but the process is less clear when using AJAX. I have a file upload in my form, and I split the process in two with AJAX: the file goes to the upload endpoint…
rublex
  • 1,893
  • 5
  • 27
  • 45
1
2 3
47 48