openedx / edx-drf-extensions

edX extensions for Django REST Framework
http://edx-drf-extensions.readthedocs.org
Apache License 2.0
17 stars 16 forks source link

JWT cookie sometimes contains a different user than the session #381

Open robrap opened 1 year ago

robrap commented 1 year ago

Using edx-platform Safe Session monitoring, we've seen cases where the user id related to the LMS session does not match the user id in the JWT cookie. Although this issue is ultimately related to the LMS, which creates both the LMS session and the JWT cookie, this issue is being documented in this repo because this is where the JwtAuthentication class lives, which is a good place for adding observability, and potentially for taking corrective action.

Here are some related tickets:

robrap commented 1 year ago

@feanil: Some ideas we had discussed:

Observability for user id mismatches

Error handing for mismatches

For auth failure that would have resulted in jwt_auth_result of 'forgiven-failure', we will instead fail if there is a mismatch and use jwt_auth_result of ‘user-mismatch-failure’ (or something like that).

For all other cases, we discussed not doing anything new or different regarding mismatches, and simply starting with observability.

Todos for @robrap:

robrap commented 1 year ago

[inform] @feanil: I moved the two known issues to github issues and added references to this ticket above. 2U does not plan to prioritize these, but they would be helpful: 1) as part of auth clean-up, and 2) to enable making safe session alerting more sensitive.

robrap commented 1 year ago

@feanil: When you return to this work, I'm wondering if this existing test_set_request_user_with_use_jwt_cookie has a good chunk of what you would need, and could be duplicated/simplified for this work?