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

Can Google Re-Captcha 2 prevent CSRF attacks?

A Cross-Site Request Forgery attack rides on the victim's session to submit malicious requests to a trusted site. The Cheat Sheet here describes CAPTCHA as a good way to prevent CSRF attacks. As we know, Google Re-Captcha is effective in preventing…
Chong Lip Phang
  • 8,755
  • 5
  • 65
  • 100
7
votes
1 answer

How can I use ring anti-forgery / CSRF token with latest version ring/compojure?

I copied some old code that was working in compojure 1.1.18 and other old libs, but using the latest versions I can't get it to work. Here's my minimal example code copied from the minimal example here to demonstrate that with latest ring and…
sventechie
  • 1,859
  • 1
  • 22
  • 51
7
votes
2 answers

Yii2 How to properly create checkbox column in gridview for bulk actions?

I need to create "bulk actions" similar to wordpress posts management, so you can for example delete multiple records at a time. This is my approach, and works fine, but I'm sure it is not the best approach, since this method is vulnerable to CSRF…
lalo
  • 901
  • 2
  • 10
  • 15
6
votes
1 answer

Node js csrf token protection not working

I have the following in my app.js file server side after bodyParser let dotEnv = require("dotenv"); dotEnv.load(); let express = require("express"); let app = express(); if (process.env.NODE_ENV === 'production') { app =…
jones
  • 1,423
  • 3
  • 35
  • 76
6
votes
7 answers

Laravel 419 Error - VerifyCsrfToken issue

I have multiple Laravel sites hosted on the same server. With the latest site I've created, the contact form refuses to submit without throwing a 419 error. I have set up the routing in my web.php file just like the other websites, which have live,…
Chad
  • 1,531
  • 3
  • 20
  • 46
6
votes
1 answer

(window as any).global = window;

I am new in typescript, and I have used on global var in polyfill.js (window as any).global = window; So with security or XSS purpose is it vulnerable to use. Or should I remove to find another route? Thanks, techies.
Anupam Maurya
  • 1,927
  • 22
  • 26
6
votes
1 answer

Laravel 5.4: Exclude a route with parameters from CSRF verification

As per Laravel 5.4 Docs, you can exclude a route from CSRF verification by adding the route to $except property at VerifyCsrfToken middleware. But for some reason, a route with parameters couldn't be excluded with exact route name unless excluded…
blazR
  • 95
  • 2
  • 7
6
votes
1 answer

SpringBoot - Angular 5 - CSRF

Iam lost now and need some help. I have a SpringBoot Server with SpringSecurtiy 4.3. Angular 5 App And want to enable CSRF protection since it should be enabled on both by default (says the docs) :Its NOT! On SpringBoot I need to add these…
Gregor Sklorz
  • 1,645
  • 2
  • 19
  • 27
6
votes
3 answers

Add security headers to help protection from injection attacks in c# asp.net

I have a C# asp.net application.It was sent to security assessment and below were the risks. -Missing "Content-Security-Policy" header -Missing "X-Content-Type-Options" header -Missing "X-XSS-Protection" header -It was observed that server…
user3660473
  • 131
  • 2
  • 3
  • 15
6
votes
2 answers

Bearer tokens and CSRF

We are building 3 different applications MVC application, API, SPA (not Angular) with ASP.NET Core. All the actions in this application are only for authorized users. That's why we protect them with IdentityServer. We use a cookie to store the…
user1336
  • 6,435
  • 2
  • 27
  • 34
6
votes
1 answer

Rails 5 devise_token_auth Can't verify CSRF token authenticity

I am working on a Rails 5 api project which is used by mobile client with gem devise_token_auth for authorization. I am clear about what the warning means. 1st Question: CSRF protect should be turned OFF for api(JSON/XML)respond, correct? I…
William Hu
  • 15,423
  • 11
  • 100
  • 121
6
votes
2 answers

Django CSRF protection forces to set "Vary: Cookie" header that leads to inefficient cache

Django's CsrfViewMiddleware sets "Vary: Cookie" header, that means that cache system will take into account not only page URL but also user's Cookies that are unique for each user. So pages don't cache once for all users, but for each user. And in…
6
votes
2 answers

Flask : CSRF verification failed

I am sending a POST request from an iOS client -(void)loadFavorite:(NSArray*)favorites{ //data and url preparation NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url …
Boris-V
  • 437
  • 1
  • 4
  • 15
6
votes
1 answer

Selective usage of Spring Security's CSRF filter

Disclaimer: My question is somewhat similar to this question and this question, but I have tried all the answers suggested in those threads and already spent few days struggling with the problem. I am introducing Spring Security 3.2.6 in my existing…
Amit
  • 13,134
  • 17
  • 77
  • 148
6
votes
3 answers

Secure CSRF protection without sessions or database?

i'm trying to implement secure CSRF protection to HTML login form, i know the best way to implement CSRF protection is storing random csrf_key in a session, but i want to add CSRF to my login & register forms... and i do not want to store many…
itai
  • 302
  • 5
  • 15