Preventing CSRF with the same-site cookie attribute

After Deep review on HttpCookie Source it’s confirm that we cannot do this with the code, as there is no way to add extra attribute on Cookie and class is marked as sealed. But still anyhow I manage solution by modifying web.config as below. <rewrite> <outboundRules> <rule name=”Add SameSite” preCondition=”No SameSite”> <match serverVariable=”RESPONSE_Set_Cookie” pattern=”.*” negate=”false” … Read more

rails – “WARNING: Can’t verify CSRF token authenticity” for json devise requests

EDIT: In Rails 4 I now use what @genkilabs suggests in the comment below: protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == ‘application/json’ } Which, instead of completely turning off the built in security, kills off any session that might exist when something hits the server without the CSRF token. skip_before_filter :verify_authenticity_token, :if => … Read more

Do login forms need tokens against CSRF attacks?

Yes. In general, you need to secure your login forms from CSRF attacks just as any other. Otherwise your site is vulnerable to a sort of “trusted domain phishing” attack. In short, a CSRF-vulnerable login page enables an attacker to share a user account with the victim. The vulnerability plays out like this: The attacker … Read more

Turn off CSRF token in rails 3

In the controller where you want to disable CSRF the check: skip_before_action :verify_authenticity_token Or to disable it for everything except a few methods: skip_before_action :verify_authenticity_token, :except => [:update, :create] Or to disable only specified methods: skip_before_action :verify_authenticity_token, :only => [:custom_auth, :update] More info: RoR Request Forgery Protection

Passing csrftoken with python Requests

If you are going to set the referrer header, then for that specific site you need to set the referrer to the same URL as the login page: import sys import requests URL = ‘https://portal.bitcasa.com/login’ client = requests.session() # Retrieve the CSRF token first client.get(URL) # sets cookie if ‘csrftoken’ in client.cookies: # Django 1.6 … Read more