kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Fix 500s on network location PATCH without base_url and on malformed basic-auth facility ids

Open rtibbles opened this issue 2 weeks ago โ€ข 5 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.

Overview

Two auth and discovery paths return a 500 for malformed input: a network location PATCH without base_url, and basic authentication against the public facility user endpoint with a malformed facility id. The first should succeed and the second should fail authentication.

Complexity: Low Target branch: develop

Context

On develop at fe298f5449:

  • PATCH /api/discovery/staticnetworklocation/<id>/ with {"nickname": "x"} raises KeyError: 'base_url' in the serializer's validate (network_location.py#L71). (device permission or facility admin)
  • GET /api/public/facilityuser/ with basic auth username=learner&facility=bad:password raises ValueError in backends.py#L117, which catches only DoesNotExist. (anonymous)

The Change

  • The network location serializer should validate base_url only when the request includes it.
  • The basic-auth backend should treat a malformed facility id as a failed authentication.

Acceptance Criteria

  • [ ] The PATCH under Context returns 200 and changes only nickname.
  • [ ] The basic-auth request under Context returns 401.
  • [ ] Tests cover both requests.

AI usage

I had Claude Code sweep Kolibri's API code for unvalidated request input and reproduce each 500 with a test. I chose the fix and the split into sub-issues. Claude Code drafted the issue to the pattern of #15838.

rtibbles avatar Nov 15 '26 20:11 rtibbles

Hi! ๐Ÿ‘‹

This issue is available for contribution and supports self-assignment. Here's how to get started:

  • Comment /assign to assign yourself to this issue
  • You can have up to 2 issues assigned at a time across all community repos
  • Dropping an issue has a 7-day cooldown before the slot opens up
  • Link your pull request to this issue when you submit it

๐Ÿ“– Read the Contributing guidelines before starting.

Are you preparing for Google Summer of Code? See our GSoC guidelines.

learning-equality-bot avatar Nov 15 '26 21:11 learning-equality-bot

Hi! ๐Ÿ‘‹

This issue is available for contribution and supports self-assignment. Here's how to get started:

  • Comment /assign to assign yourself to this issue
  • You can have up to 2 issues assigned at a time across all community repos
  • Dropping an issue has a 7-day cooldown before the slot opens up
  • Link your pull request to this issue when you submit it

๐Ÿ“– Read the Contributing guidelines before starting.

Are you preparing for Google Summer of Code? See our GSoC guidelines.

learning-equality-bot avatar Nov 15 '26 21:11 learning-equality-bot

/assign

rishiraj38 avatar Nov 16 '26 07:11 rishiraj38

Hi! ๐Ÿ‘‹

You've been assigned to this issue. Here's what to do next:

  • Read the issue description carefully and make sure you understand the requirements
  • Link your pull request to this issue when you submit it
  • If you can no longer work on this, unassign yourself so others can pick it up

Good luck! ๐Ÿ˜Š

Are you preparing for Google Summer of Code? See our GSoC guidelines.

learning-equality-bot avatar Nov 16 '26 07:11 learning-equality-bot

I've read the contributing guidelines, including the section on generative AI.

The network location serializer runs address discovery on every validate, so a PATCH without base_url hits a KeyError; it now skips discovery when the request has no base_url. The basic-auth facility lookup only catches DoesNotExist, so a malformed id raises the ValueError from the UUID field; it now catches that too and fails authentication with a 401, the same way csv_utils.infer_facility handles it. Each path gets one API test that fails on develop.

rishiraj38 avatar Nov 16 '26 10:11 rishiraj38