Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Followup on #54: Make XSRF optional #92

Merged
merged 11 commits into from May 1, 2018
Merged

Followup on #54: Make XSRF optional #92

merged 11 commits into from May 1, 2018

Conversation

ghost
Copy link

@ghost ghost commented Apr 15, 2018

This changeset resolves @jkarni's request for @3noch to fix the tests in #54 which resulted in that PR being reverted just after it was merged.

It also resolves the 4th todo-item from #64, Add option without cookies.

However, this changeset undoes part of #54, namely its name, Add check-origin method for CSRF. The addition of the versatile hook for rejecting requests seemed like a bigger fish than making XSRF optional, and so #53 remains unfixed.

   data CookieSettings = CookieSettings {
   ...
-  -- | An arbitrary check for the request. Use this to implement validating
-  --   the Origin/Referer headers. Default @const True@.
-  , cookieCheckRequest      :: !(Request -> Bool)
-  } deriving (Generic)

3noch and others added 5 commits April 15, 2018 15:00
- move XsrfCookieSettings fields single subfield of example CookieSettings
- add a (non total) function to extract fields from the XsrfCookieSettings sub value
- extract the fields with the new function
@alpmestan alpmestan requested a review from jkarni April 16, 2018 08:09
@3noch
Copy link
Contributor

3noch commented Apr 16, 2018

@plredmond Dang that's very kind of you! I unfortunately finished the app using my fork and moved on without any chance to go back and clean it up. Your help is much appreciated, even though it does lack a key feature. But at least it's getting closer.

@ghost
Copy link
Author

ghost commented Apr 16, 2018

@3noch No problem! I needed this functionality for something I'm working on. Sorry for cutting out the cookieCheckRequest & associated calls.

@domenkozar
Copy link
Collaborator

@plredmond thanks for doing this, I'm going down the same path today wishing for CSRF to be optional.

I have one nitpicky comment - given that this library started with CSRF as a name and that https://en.wikipedia.org/wiki/Cross-site_request_forgery claims XSRF is equivalent to CSRF I see very little benefit changing the naming, confusing existing servant-auth user base.

I'll test these changes today and report back.

@3noch
Copy link
Contributor

3noch commented Apr 17, 2018

@domenkozar

I have one nitpicky comment - given that this library started with CSRF as a name and that https://en.wikipedia.org/wiki/Cross-site_request_forgery claims XSRF is equivalent to CSRF I see very little benefit changing the naming, confusing existing servant-auth user base.

This was my change originally. The library used both CSRF and XSRF in random places so I picked what seemed to be the dominant one and normalized. I think using both is the most confusing of the options.

@domenkozar
Copy link
Collaborator

$ git grep -i xsrf | wc -l
45
$ git grep -i csrf | wc -l
27

I didn't see that in the diff - I do agree consistency is important so nevermind my comment.

@domenkozar
Copy link
Collaborator

I've tested with defaultCookieSettings { cookieXsrfSetting = Nothing } and can confirm POST requests now have no XSRF checking and NO-XSRF-TOKEN cookie exists.

@domenkozar
Copy link
Collaborator

@plredmond could you rebase please?

@ghost
Copy link
Author

ghost commented Apr 19, 2018 via email

@domenkozar
Copy link
Collaborator

@plredmond could you also add a test case for clearSession?

@ghost
Copy link
Author

ghost commented Apr 21, 2018 via email

@domenkozar
Copy link
Collaborator

@plredmond thanks - I think once it's proven that logic in clearSession works, we can merge this :)

PLR added 2 commits April 24, 2018 20:31
@ghost
Copy link
Author

ghost commented Apr 25, 2018

@domenkozar clearSession was working because it cleared the session cookie which prevents further authentication.

However, clearSession logic was unconditionally adding a cookie named NO-XSRF-COOKIE. That has been fixed and tested in 05dd6f5. The new tests have extra calls to GET / to demonstrate the state of the authentication, but I could remove those if you think it's not necessary.

Additionally 5f78fc4 changes all server-spec tests not to rely on the default name for the session cookie. Let me know if you want this reverted.

@ghost
Copy link
Author

ghost commented Apr 25, 2018

Ok.. it looks like I can't use a few pieces of wreq or http-client because they aren't a part of the GHC-7.10.3 environment. I've got that environment building locally now and will see if I can get this working.

@ghost
Copy link
Author

ghost commented May 1, 2018 via email

@domenkozar domenkozar merged commit bcbfbd8 into haskell-servant:master May 1, 2018
@domenkozar
Copy link
Collaborator

@plredmond do you think it would be better to delete the cookie instead of setting value to "value"? For example one might check for existence of the cookie if someone is signed in (not in a secure way).

@ghost
Copy link
Author

ghost commented Jun 5, 2018 via email

@3noch
Copy link
Contributor

3noch commented Jun 5, 2018

The Default instance for SetCookie sets the value to "value" IIRC. The other complication is that the Servant types actually specify exactly 2 cookies, so you'd have to make the types more complex.

@ghost ghost mentioned this pull request Jul 9, 2018
@ghost ghost deleted the csrf-check-origin-rebase branch July 9, 2018 03:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants