Repository navigation
Return 404 for a cursor whose position is invalid for the ordering field - #10124
Open
mohamed-alired wants to merge 2 commits into
Open
mohamed-alired wants to merge 2 commits into
mohamed-alired wants to merge 2 commits into
Conversation
CursorPagination.decode_cursor() validates the offset and reverse parts
of a cursor but passes the position through, and paginate_queryset()
filters on it directly. A client-supplied cursor such as base64('p=abc')
on an integer or UUID ordering field therefore raised ValueError or
django.core.exceptions.ValidationError from queryset.filter(), a 500.
Treat it like any other malformed cursor and raise NotFound with the
"Invalid cursor" message.
auvipy
self-requested a review
November 28, 2026 12:25
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CursorPagination.decode_cursor()validates the offset and reverse parts of a cursor, but the position (p) is passed through unchecked andpaginate_queryset()filters on it directly. A client can send a well-formed cursor whose position is not a valid value for the ordering field, and the request fails with a 500:Neither exception is handled by the exception handler. This change treats such a cursor like any other malformed cursor and raises
NotFoundwithinvalid_cursor_message("Invalid cursor"), which is what DRF already returns for a bad offset or bad base64.Tests:
test_invalid_cursor_positioninCursorPaginationTestsMixinruns against both the mock queryset and the real model queryset. It fails onmainand passes with this change.