kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Escape the channel token in content server lookup URLs

Open rtibbles opened this issue 2 weeks ago • 3 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

get_channel_lookup_url puts the channel token from the request into the content server URL path without escaping it. A token containing /, .., ? or # changes which path and query Kolibri requests from Studio or a peer. It needs content management permission, and the host can't change, but the token should be escaped.

Complexity: Low Target branch: develop

Context

  • content/utils/paths.py#L232-L235 builds /lookup/{identifier}. The token query parameter of /api/content/remotechannel/ reaches it.
  • On develop at fe298f5449:
    • get_channel_lookup_url(identifier="../x") returns /api/public/v1/channels/lookup/../x?channel_versions=true
    • get_channel_lookup_url(identifier="abc?keyword=y#") returns /api/public/v1/channels/lookup/abc?keyword=y#?channel_versions=true

Acceptance Criteria

  • [ ] Both calls under Context return a URL where the whole identifier is one escaped path segment under /lookup/.
  • [ ] Importing a channel by token from Device > Channels works as before.
  • [ ] A test covers an identifier with /, ? and #.

AI usage

I had Claude Code sweep Kolibri's API code for unvalidated input and permission gaps, and confirm each one. I decided this one is a public hardening issue. Claude Code drafted the issue.

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

I'd like to take this issue.

I have read the Contributing guidelines, including the section on Using generative AI.

I reproduced the unescaped lookup path on current develop (fe298f5449). Both cases in the issue match the current get_channel_lookup_url behavior in kolibri/core/content/utils/paths.py:

  • identifier="../x" → /api/public/v1/channels/lookup/../x?channel_versions=true
  • identifier="abc?keyword=y#" → /api/public/v1/channels/lookup/abc?keyword=y#?channel_versions=true

The identifier is interpolated into /lookup/{identifier} with no escaping. I'll quote it as a single path segment so /, ?, and # stay inside that segment, add a test for those characters, and keep a normal token unchanged so Device > Channels import-by-token still works.

/assign

Disclosure: I used an AI assistant to help with the investigation and to draft this comment; I reviewed the develop source and ran the reproduction myself.

JackLee992 avatar Nov 16 '26 00:11 JackLee992

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 00:11 learning-equality-bot