Cursor pagination doesn't validate the cursor position or page size

Đang mở
#6,393 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
django, python
Lĩnh vực
api, backend, security, testing

Hướng nghiên cứu

Start with ValuesViewsetCursorPagination in contentcuration/contentcuration/utils/pagination.py, ContentNodePagination in contentcuration/contentcuration/viewsets/contentnode.py, and OptionalContentNodePagination in contentcuration/kolibri_public/views.py; compare how each handles cursor positions, ordering and page size. Reproduce the listed requests and add regression tests for each input, including the import metadata endpoint. Done means malformed cursors return DRF's invalid-cursor 404, ignored ordering cursors do not affect /api/contentnode, and public content-node pages respect a maximum size.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

DEV: backend

Overview

Cursor pagination passes the cursor's position to the queryset filter without checking it fits the ordering field, and the public contentnode endpoint has no maximum page size. A crafted cursor, or a huge max_results, raises an exception and the request returns 500. Two of the affected endpoints are anonymous.

Complexity: Medium
Target branch: hotfixes

Context

All inputs below were reproduced:

  • ValuesViewsetCursorPagination relies on DRF's CursorPagination.decode_cursor, which validates the cursor's offset and direction but not its position (p). A base64 cursor of p=abc or p=notadate reaches the filter on:
    • /api/public/v2/contentnode/?max_results=2&cursor=cD1hYmM=: ValueError: Field 'lft' expected a number but got 'abc'. Anonymous.
    • /api/channelversion?version__gte=0&max_results=5&cursor=<p=abc>: ValueError on version. Anonymous.
    • /api/communitylibrary_submission?max_results=5&cursor=<p=notadate>: Django ValidationError on the datetime.
    • ImportMetadataPagination on /api/public/v2/importmetadata/<id>/ orders by lft the same way. Anonymous. Not reproduced separately.
  • ContentNodePagination reads the cursor field from the raw ordering param and only checks the value is an integer when that field is lft. On /api/contentnode?parent=<id>&max_results=2:
    • &ordering=foo&foo__gt=abc raises ValueError on lft, because DRF falls back to lft ordering.
    • &ordering=modified&modified__gt=abc raises Django ValidationError.
    • Related: #4854.
  • OptionalContentNodePagination sets no max_page_size. On /api/public/v2/contentnode/, ?max_results=999999999999999999999999999999 raises DataError: bigint out of range. Related: learningequality/kolibri#15826.
The Change
  • A cursor position that doesn't fit the ordering field should get the same response DRF gives for any malformed cursor.
  • ContentNodePagination should take its cursor field from the ordering the viewset applies, not the raw ordering param.
  • OptionalContentNodePagination should cap max_results.
Acceptance Criteria
General
  • Every cursor input in Context, and the same cursor on /api/public/v2/importmetadata/<id>/, returns DRF's invalid-cursor 404 instead of 500.
  • /api/contentnode ignores a cursor param for an ordering it doesn't apply, and returns a 4xx for a cursor value of the wrong type for the ordering it applies.
  • /api/public/v2/contentnode/ with a max_results above the cap returns at most the cap.
Testing
  • Each input in Context has a regression test.

AI usage

I scoped the audit and chose the validation strategy in #6387. Claude Code found and reproduced these failures and drafted this issue.

Ngôn ngữ chính
Python
Star
212
Fork
321
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của learningequality/studio

Tất cả issue của learningequality/studio

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.