Do you need to sign a Relay pagination cursor?
Before starting the main topic I would like to clarify that in this article when I say: Encoding (base64, MessagePack), it means change the format only. But anyone can reverse it, there is no secret. Signing (here HMAC with a secret), it means letting the server to detect a cursor that was edited or forged. But we are not not trying to hide the content. TL;DR No . The Relay Cursor Connections…
The Relay Cursor Connections specification never requires a signed cursor. It simply states that a cursor represents an item's position in a list. Each edge has an opaque cursor, which does not reveal any information about the contents. The spec does not mandate encryption or tying the cursor to the query that issued it. The cursor is just an opaque string meant to be unreadable by the client.
In NodeJS/NestJS, developers used to encode and sign every cursor to add security. For example, a cursor might look like "eyJhIjoiTVMyWVo3Wkl5WkZSMW1fM1FkaHhubSIsImsiOlsiMWM3NjJlMTgtNzZiMS00YWU4LTg1ZjctZWRmYmUzMjAxODBmIl19.KZX-ximd3leLM_1k0SXAPxZjaysKAvHzEcMrGf3-Tjk". This cursor is a combination of a base64url-encoded JSON payload and a base64url-encoded HMAC-SHA256 signature.
The payload contains the cursor's key-value pairs: k (position of the cursor) and a (audience, identifying the query). The signature ensures that the cursor cannot be forged or edited. However, anyone can still reverse the encoding and view the contents of the payload.
Switching to the Ent framework, signed cursors were dropped in favor of unsigned cursors. These unsigned cursors are MessagePack, base64-encoded and contain the row's ID and sort value. For instance, the cursor "gqFpxBD9fOCeg+NNroyEqHImBq4uoXajWlpa" holds the novel ID and the value of the field the list is ordered by. Since there is no signature, anyone can decode, edit, and re-encode the cursor.
This poses no significant security risk, as the server applies the query's filters and permissions regardless. The cursor's generation in Ent is handled through the `entgql.Cursor[uuid.UUID]` type.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to