Today, If I authenticate on DjangoLDP instance A in client A, I get two auth means : a cookie sessionid and a JWT bearer token stored in browser localStorage. If I then authenticate to another DjangoLDP instance B in client B and that instance B is federated with instance A, I start to be in trouble : client B sends bearer token B and cookie A to server A, and server A authenticates me as user A instead of user B.
I think that the session cookie should only be used to first generate the access token, but not in subsequent requests.
Designs
Child items
...
Show closed items
Linked items
0
Link issues together to show that they're related.
Learn more.
I have identified a place where the user is set in auth/middleware.py:
# If the user is already authenticated and that user is the user we are# getting passed in the headers, then the correct user is already# persisted in the session and we don't need to continue.ifrequest.user.is_authenticated:return
Is that correct ?
Then, I think the following code use the bearer token to authenticate the user, is that right ?
# We are seeing this user for the first time in this session, attempt# to authenticate the user.user=auth.authenticate(request)ifuser:# User is valid. Set request.user and persist user in the session# by logging the user in.request.user=userauth.login(request,user)
I believe that "persisted in the session" means that the user was authenticated by an earlier call to authenticate, not that the user is included in the cookie. Is the cookie being used in authentication is someway I don't know about? @jbpasquier
The subsequent call to auth.authenticate will hit the ExternalUserBackend which will use the Authorization token to authenticate
@calummackervoy if there is a session, there must be a session cookie. The user is not "included in the cookie", but the session ID is. My understanding is that we should never use the session information to authenticate the user. We should only use Authorization token, even for calls that are not meant for authentication (i.e. GET any resource for example).
So all the places where user.is_authenticated is used in django code should be replaced with a Authorization token check mecanism.
@fabien4vo I meant that I don't think the session ID is used in authentication - I think JB Lemée's comment in your code sample just means "if request.user.is_authenticated is set" - meaning that some backend already authenticated it before the middleware
If that's correct, we have two different strategies :
We never trust the session cookie and reauthenticate the user for each request. Could this impact performances ? The drawback is also that any admin session using another user cookie will be terminated.
We do not use session mechanism to check user permissions. It means that any call to user.is_authenticated in any packages should be replaced by a system that get user from the token instead of the session