Skip to content

Commit 809a6e1

Browse files
committed
fix(plugin-audit): the comment threads cursor decoder accepts only what the encoder writes
L2 round 2 on #39135 (S1, N5). A decodable cursor carrying a filter placeholder ({not_a_token}, {30_days_ago}) or blank text in its creation time or id reached the engine's token resolver as a filter the client never wrote; it is now VALIDATION_ERROR / 400 in the decoder. The schema header names the INVALID_FILTER filter refusal. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzfHCzQWh6PeQnvToFz
1 parent 7b0b230 commit 809a6e1

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎packages/plugins/plugin-audit/src/comment-threads-query.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ describe('the comment threads read — answers given before the engine is asked'
207207
// not left to the engine's temporal door to refuse as a filter.
208208
encodeThreadsCursor({ createdAt: 'x', id: 'y' }),
209209
encodeThreadsCursor({ createdAt: '2026-13-45T99:00:00Z', id: 'y' }),
210+
// Filter placeholders and blanks in either member: the engine's token
211+
// resolver would answer them as a filter the client never wrote.
212+
encodeThreadsCursor({ createdAt: '{not_a_token}', id: 'y' }),
213+
encodeThreadsCursor({ createdAt: '{30_days_ago}', id: 'y' }),
214+
encodeThreadsCursor({ createdAt: ' ', id: 'y' }),
215+
encodeThreadsCursor({ createdAt: '2026-12-02T10:00:02.000Z', id: '{not_a_token}' }),
216+
encodeThreadsCursor({ createdAt: '2026-12-02T10:00:02.000Z', id: '{current_user_id}' }),
217+
encodeThreadsCursor({ createdAt: '2026-12-02T10:00:02.000Z', id: ' ' }),
210218
]) {
211219
const engine = recordingEngine();
212220
const answer = await call(as(ANN, engine), { body: { object: ACCOUNT, cursor } });

‎packages/plugins/plugin-audit/src/comment-threads-query.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type { IHttpRequest, IHttpResponse, IHttpServer } from '@objectstack/spec
2828
import {
2929
VALID_AST_OPERATORS,
3030
apiExposureDenialReason,
31+
classifyFilterToken,
3132
isFilterAST,
3233
parseFilterAST,
3334
resolveDisplayField,
@@ -199,6 +200,13 @@ export function encodeThreadsCursor(position: CursorPosition): string {
199200
return btoa(text).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
200201
}
201202

203+
/**
204+
* The spelling of a stored instant a cursor may carry: a calendar day, a time
205+
* of day and an optional zone, as `toISOString` and the SQL drivers write it.
206+
* A filter placeholder (`{30_days_ago}`) or blank text is not one.
207+
*/
208+
const CURSOR_INSTANT_RE = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}(?::?\d{2})?)?$/;
209+
202210
/** Decode a cursor this read issued; `null` for anything else. */
203211
export function decodeThreadsCursor(cursor: string): CursorPosition | null {
204212
if (!/^[A-Za-z0-9_-]+$/.test(cursor)) return null;
@@ -207,11 +215,13 @@ export function decodeThreadsCursor(cursor: string): CursorPosition | null {
207215
const parsed: unknown = JSON.parse(decodeURIComponent(atob(padded)));
208216
if (!Array.isArray(parsed) || parsed.length !== 2) return null;
209217
const [createdAt, id] = parsed;
210-
if (typeof createdAt !== 'string' || createdAt === '' || typeof id !== 'string' || id === '') return null;
211-
// A creation time the `datetime` rule cannot read was never issued here;
212-
// refused now, not by the engine's temporal door about a condition the
213-
// client never wrote.
214-
if (isUninterpretableTemporalComparand('datetime', createdAt)) return null;
218+
if (typeof createdAt !== 'string' || typeof id !== 'string') return null;
219+
// Only what the encoder writes: a stored instant's text and a stored id.
220+
// Anything else was never issued here, and is refused now rather than by
221+
// the engine (its temporal door, its filter-token resolver) about a
222+
// condition the client never wrote.
223+
if (!CURSOR_INSTANT_RE.test(createdAt) || isUninterpretableTemporalComparand('datetime', createdAt)) return null;
224+
if (id === '' || id.trim() !== id || classifyFilterToken(id) !== null) return null;
215225
return { createdAt, id };
216226
} catch {
217227
return null;

‎packages/spec/docs/references/api/comment-threads.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ none is skipped.
4646

4747
A body key this schema does not declare, any query parameter, a `limit`
4848
out of range or a `cursor` the server did not issue is
49-
`VALIDATION_ERROR` / 400. An unknown object is `OBJECT_NOT_FOUND` / 404,
49+
`VALIDATION_ERROR` / 400; a `filter` the list read cannot lower is
50+
`INVALID_FILTER` / 400, the answer `GET /data/{object}` gives the same
51+
value, and `null` or `[]` is no filter. An unknown object is `OBJECT_NOT_FOUND` / 404,
5052
an object the data door does not serve answers the data door's own refusal,
5153
`sys_comment` itself is `VALIDATION_ERROR` / 400, and an object whose
5254
comments are switched off (`enable.feeds: false`) is `FEEDS_DISABLED` / 403.

‎packages/spec/src/api/comment-threads.zod.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ import { lazySchema } from '../shared/lazy-schema';
4848
*
4949
* A body key this schema does not declare, any query parameter, a `limit`
5050
* out of range or a `cursor` the server did not issue is
51-
* `VALIDATION_ERROR` / 400. An unknown object is `OBJECT_NOT_FOUND` / 404,
51+
* `VALIDATION_ERROR` / 400; a `filter` the list read cannot lower is
52+
* `INVALID_FILTER` / 400, the answer `GET /data/{object}` gives the same
53+
* value, and `null` or `[]` is no filter. An unknown object is `OBJECT_NOT_FOUND` / 404,
5254
* an object the data door does not serve answers the data door's own refusal,
5355
* `sys_comment` itself is `VALIDATION_ERROR` / 400, and an object whose
5456
* comments are switched off (`enable.feeds: false`) is `FEEDS_DISABLED` / 403.

0 commit comments

Comments
 (0)