monterail / guidelines

[DEPRECATED] We are Ruby on Rails experts from Poland. Think hussars. Solid & winged. These are our guidelines.
71 stars 17 forks source link

Setup XSRF-TOKEN cookie in Rails for angular CSRF protection #177

Closed chytreg closed 11 years ago

chytreg commented 11 years ago

Imho cleaner and more solid solution than set X-CSRF-Token on Angular site (source).

Had some problems with token setting when I run test on poltergeist or capybara-webkit. If you want to use client side more solid solution is to use:

# Inject CSRF Token
angular.element(document).ready () =>
  @app.config ["$httpProvider", (provider) ->
    provider.defaults.headers.common['X-CSRF-Token'] = angular.element('meta[name="csrf-token"]').attr('content')
  ]

or the cookie solution which I prefer.

jandudulski commented 11 years ago

Billion :+1:

chytreg commented 11 years ago

Any objections?

sheerun commented 11 years ago

Yes, security. Storing CSRF token in cookies is vulnerable to session fixation. Fetching it from meta is ok.

chytreg commented 11 years ago

Example or source pls.

Best regards Dariusz Gertych

2013/8/21 Adam Stankiewicz notifications@github.com

Yes, security. Storing CSRF token in cookies is vulnerable to session fixation. Fetching it from meta is ok.

— Reply to this email directly or view it on GitHubhttps://github.com/monterail/guidelines/pull/177#issuecomment-23018386 .

chytreg commented 11 years ago

@sheerun http://stackoverflow.com/questions/4463422/csrf-can-i-use-a-cookie

Best regards Dariusz Gertych

2013/8/21 Dariusz Gertych dariusz.gertych@monterail.com

Example or source pls.

Best regards Dariusz Gertych

2013/8/21 Adam Stankiewicz notifications@github.com

Yes, security. Storing CSRF token in cookies is vulnerable to session fixation. Fetching it from meta is ok.

— Reply to this email directly or view it on GitHubhttps://github.com/monterail/guidelines/pull/177#issuecomment-23018386 .

chytreg commented 11 years ago

Think I found: http://homakov.blogspot.com.es/2013/06/cookie-forcing-protection-made-easy.html :( @teamon @jandudulski

sheerun commented 11 years ago

Yup, exactly.

chytreg commented 11 years ago

Insecure!!!

jandudulski commented 11 years ago

Homakov :heart:

sheerun commented 11 years ago

For the record, nie wiedziałem o tym poście :D