-
Notifications
You must be signed in to change notification settings - Fork 126
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
Signing Cookies #11
Comments
Not sure about this one. If the attacker is a MITM, there are attack vectors that are much more dangerous (and more straightforward to execute at the same time). Simply stealing the session cookie seems much more viable for the attacker than tampering with a CSRF cookie, tricking the user into visiting the hostile website, etc. |
Just to add to it: other CSRF implementations (like Django or Flask-SeaSurf) do not seem to use any kind of signatures on the CSRF cookies. |
Django's cookies are signed by default. Rails is the same, since 3.0 if I The primary benefit is that you can detect any attempt to tamper: because This also benefits HTTPS connections, which are still at risk from the On Monday, July 28, 2014, Justinas Stankevičius [email protected]
|
I should also mention that because the cookies are not HttpOnly by default, any XSS vulnerability (which does not require a MITM!) can write to the cookies directly and avoid the same-origin policy that would normally restrict that. I assume that we don't enforce HttpOnly for convenience—so that AJAX requests can get the CSRF token—but this opens up another avenue for attack. We can comfortably (under any reasonable circumstance) assume that no-one is going to brute-force our HMAC-SHA256 signed values, so any attempts to modify the cookie via XSS (which is going to be the most common), MITM on our users' site or even a MITM on any external scripts we use—can at least be detected and the request rejected. |
I don't think Django signs cookies by default. As I see it, there are both set_cookie() and set_signed_cookie() functions. Your point about the XSS vulnerabilities is a valid and convincing one, though. I will think about how to integrate the signing some more, mostly whether to break API and make it default (forced?). |
Ah, good catch. Django’s default cookie store is signed (https://docs.djangoproject.com/en/dev/topics/http/sessions/#using-cookie-based-sessions) but I didn’t realise this doesn’t include their CSRF implementation. Odd! On 29 Jul 2014, at 4:58 AM, Justinas Stankevičius [email protected] wrote:
|
This only applies to the session cookie. All other cookies are up to user to sign. |
Well this has been sitting open for a while. Seeing how there are now alternatives like goji-csrf which do use cookie signing and the fact that it would change the API, I think this should be considered out of scope for now. |
nosurf does not currently sign cookies as the standard http.Cookie implementation only defines the "basic" attributes of a cookie.
CSRF cookies should be signed (so we can identify attempts to tamper) with HMAC-SHA256, and then authenticated before checking the cookie against the submitted request. An example of a solid authentication implementation can be found here.
func (h *CSRFHandler) SetAuthKeys(key []byte, keys ...[]byte)
andfunc (h *CSRFHandler) SetEncryptionKeys(key []byte, keys ...[]byte)
, with the variadic param allowing a package user to pass in multiple key pairs (which facilitates cycling keys). This would be similar to how gorilla/securecookie handles key rotation, but you could probably get away with just accepting a single key.nosurf.New
accept an options struct that then calls securecookie API before then returning a configured*CSRFHandler
.The text was updated successfully, but these errors were encountered: