kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Login returns 500 when usernames differ only in case and none matches exactly

Open amritraj7237 opened this issue 1 month ago • 0 comments

🙂 Looking for an issue? Welcome! This issue is open for contribution. If this is the first time you’re requesting an issue, please:

  • Read Contributing guidelines carefully. Pay extra attention to Using generative AI. Pull requests and comments that don’t follow the guidelines won’t be answered.
  • Confirm that you’ve read the guidelines in your comment.

Observed behavior

If a facility has two users whose usernames only differ in case, like Shared_Username and shared_username, and someone tries to log in as SHARED_USERNAME with the wrong password, the server returns a 500 instead of the usual "incorrect username or password" error.

Errors and logs

AttributeError: 'NoneType' object has no attribute 'password'
  kolibri/core/auth/viewsets/session.py, in _throw_validation_error

Expected behavior

A 401 invalid credentials error for a wrong password, or a 400 missing password error if no password is sent.

User-facing consequences

The learner gets a generic server error and doesn't know what went wrong.

Steps to reproduce

  1. Create Shared_Username and shared_username in the same facility
  2. Try to sign in as SHARED_USERNAME with any wrong password
  3. The POST to /api/auth/session/ returns 500

Context

Found this on develop. When the case-insensitive lookup returns more than one user, the code falls back to an exact-case match (added in #11082). If nothing matches exactly, that returns None, and the next line reads .password on it.

I've opened #15540 with a fix and regression tests.

amritraj7237 avatar Oct 07 '26 21:10 amritraj7237