Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF middleware #1

Open
rambocoder opened this issue Apr 15, 2013 · 7 comments
Open

CSRF middleware #1

rambocoder opened this issue Apr 15, 2013 · 7 comments

Comments

@rambocoder
Copy link

Vladimir, do you know if somebody created a CSRF prevention middleware for Cowboy?

@dvv
Copy link
Owner

dvv commented Apr 15, 2013

I don't. But it should be fairly possible to spawn one based on cookie session invented here.
What to read on the theme?

@rambocoder
Copy link
Author

I tired implementing a CSRF middleware using your cowboy_session rambocoder@b26980d however, the catch is that I need to read POST["_csrf"] and I do that using cowboy_req:body_qs/1 in the middleware module, however in the page handler, I tried to read the other body values again and cowboy_req:body_qs/1 becomes useless, since Cowboy only allows you to read body_qs once :(

The fact that body_qs can be read only once, and that there is no way to pass additional data from middleware to handler's in a clean way, it just makes sense to not have CSRF as middleware but to implement it in specific handlers.

@dvv
Copy link
Owner

dvv commented Apr 16, 2013

ninenines/cowboy#502
I believe you should store read body in request meta.
Or, we might want to create a body parser middleware, put it before csrf one and make next layers not operate on body directly.

@rambocoder
Copy link
Author

If we have middleware that will parse the body, how could we passed the body information to the next middleware or to the handler? Using request meta?

@dvv
Copy link
Owner

dvv commented Apr 16, 2013

I base on the point that security is unsured by passing CSRF in secure encrypted cookie so that it can't be snooped. If we change CSRF in session every time, it is not guessable outside and we can pass token via querystring.
Of course, someone more involved in the theme is welcome to judge.

@essen
Copy link

essen commented Apr 20, 2013

@rambocoder Sorry to hijack this, but you sent me an email, I sent you a reply, and your ClamAV seems to reject all my emails to you.

@dvv
Copy link
Owner

dvv commented May 19, 2013

FYI angular.js technique:
http://docs.angularjs.org/api/ng.$http#jsonp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants