liqd / adhocracy3

Adhocracy 3 with customizations for various projects
https://adhocracy3.readthedocs.io
Other
50 stars 11 forks source link

Switch auth from header/local storage to cookie #2318

Open slomo opened 8 years ago

slomo commented 8 years ago

Due to security concerns (#2299) we should consider switching our authentication scheme to cookies.

Requirements:

  1. User needs to know when and as whom it is logged in
  2. User needs to be able to login
  3. User needs to be able to logout
  4. User want only to login once on site with multiple embeds
  5. Developer want the setup to work on local machines (ideally w/o nginx)
  6. Administrators want a migration path for existing installations
  7. Attackers should not be able to get a valid session through XSS-Attacks
  8. Attackers should not be able to do CSRF (via XSS or forms)
  9. Attackers should not be able to do requests with users session from other origins
  10. User wants t o reloggin when the session expires or is invalid (due to new authentication scheme) (currently we have a quite technical error message)

Steps:

slomo commented 8 years ago

@liqd/write-access-adhocracy-3 Please leave comments and so we can extend the sections as needed.

joka commented 8 years ago

I don't feel well without CSRF protection. There are plenty of different possiblities for this attack and I don't know if we really consider everything.

slomo commented 8 years ago

Okay than but how does CSRF protection works on a RestAPI?

joka commented 8 years ago

I only did a short research but the more secure solutions i found have "double" authentication. Normal cooky auth and a csrf token send with HTTP-header (stored in local storage or cooky)

joka commented 8 years ago

Examples: http://de.slideshare.net/robertjd/jwt-authentication-with-angularjs https://docs.djangoproject.com/en/dev/ref/csrf/#ajax

MagdaN commented 8 years ago

I worked with the csrf-token solution in django (rest framework) and angular in the frontedn and it worked fine

joka commented 8 years ago

cool

slomo commented 8 years ago

Okay thanks for the feedback, I added CSRF to the ticket.

joka commented 8 years ago

added "handle session timout in the frontend (R10)"

joka commented 8 years ago

You suggest use one endpoint for token and cooky based authentication. To simplify documentation/implementation if would prefere one dedicated endpoint for each authentication method.

Also the difference between email and login name login does not make much sense from the client point of view. The backend could support both without much effort.

joka commented 8 years ago

Befor we refactor authentication we should think about using "standard" architectures like Oauth2 (revoke + access token), we need to deal with this anyway. Here is an example with Oauth2, JWT, cookies http://de.slideshare.net/robertjd/jwt-authentication-with-angularjs . Benefits for the SinglePageApplication use case: