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

Secure csrf #78

Open
mrazvan21 opened this issue Mar 25, 2016 · 6 comments
Open

Secure csrf #78

mrazvan21 opened this issue Mar 25, 2016 · 6 comments

Comments

@mrazvan21
Copy link

how can I set secure csrf?

@shaunwarman
Copy link
Member

You can drop a hidden element on the page with your created csrf similar to this kraken example

Be sure that you have a session to hold onto the secret for validation purposes.

Flow:

  • Incoming non-safe http verb with csrf header
  • parse request
  • lusca middleware finds _csrf and uses secret from session to validate _csrf

@mrazvan21
Copy link
Author

@shaunwarman I use csrf in cookie :) not in html :)
with param angular true in lusca settings

@shaunwarman
Copy link
Member

Ah, ok perfect! What are you trying to change?

@mrazvan21
Copy link
Author

I use node.js in apache (proxy).
I want to set XSRF-TOKEN with flag security true (obvious use https :D)
Session is set with security true but csrf can't set directly from lusca only If I overwrite res.cookie because from lusca when set xsrf, cookie is not set with options.secure = true;

You can see here https://github.com/krakenjs/lusca/blob/master/lib/csrf.js at line 49 (res.cookie(cookie, token);)

I'm forwarding ssl details from apache at node, node knows that site is on https (ssl is set from apache conf)). I set in express-session at cookie section secure= true;

I managed to set csrf with security=true only if I overwritten res.cookie (when options.secure true is not set I set automatically to true if https is active) but I don't like this...

I don't understand what I omitted..

@stgogm
Copy link
Contributor

stgogm commented Jun 2, 2017

I'm facing the same issue and as I see, there's no way to set the cookie as secure or HTTP only but to overwrite it.

This is because the CSRF configuration doesn't accept options for the cookie.

https://expressjs.com/en/api.html#res.cookie

@stgogm
Copy link
Contributor

stgogm commented Jun 2, 2017

Opened a pull request with a possible solution: #104

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