Skip to content

Commit 28323b7

Browse files
committed
fix(core): reject externalId starting with 'session_' on Session create/update
The session_ prefix identifies internal friendlyIds. Allowing it in a user-supplied externalId would misroute subsequent GET/PATCH/close requests through resolveSessionByIdOrExternalId to a friendlyId lookup, returning null or the wrong session. Reject at the schema boundary so both routes surface a clean 422.
1 parent 3d5873c commit 28323b7

File tree

1 file changed

+21
-2
lines changed
  • packages/core/src/v3/schemas

1 file changed

+21
-2
lines changed

packages/core/src/v3/schemas/api.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,15 @@ export const CreateSessionRequestBody = z.object({
14571457
/** Plain string discriminator — e.g. `"chat.agent"`. Not validated against an enum on the server. */
14581458
type: z.string().min(1).max(64),
14591459
/** User-supplied idempotency key. Unique per environment. Empty strings are rejected. */
1460-
externalId: z.string().trim().min(1).max(256).optional(),
1460+
externalId: z
1461+
.string()
1462+
.trim()
1463+
.min(1)
1464+
.max(256)
1465+
.refine((v) => !v.startsWith("session_"), {
1466+
message: "externalId cannot start with 'session_' (reserved prefix for internal friendlyIds)",
1467+
})
1468+
.optional(),
14611469
/** Optional pointer for task-owned session types. */
14621470
taskIdentifier: z.string().max(128).optional(),
14631471
/** Up to 10 tags for dashboard filtering. */
@@ -1497,7 +1505,18 @@ export const UpdateSessionRequestBody = z.object({
14971505
metadata: z.record(z.unknown()).nullable().optional(),
14981506
// Null explicitly clears the externalId; non-null values must be non-empty.
14991507
externalId: z
1500-
.union([z.literal(null), z.string().trim().min(1).max(256)])
1508+
.union([
1509+
z.literal(null),
1510+
z
1511+
.string()
1512+
.trim()
1513+
.min(1)
1514+
.max(256)
1515+
.refine((v) => !v.startsWith("session_"), {
1516+
message:
1517+
"externalId cannot start with 'session_' (reserved prefix for internal friendlyIds)",
1518+
}),
1519+
])
15011520
.optional(),
15021521
});
15031522
export type UpdateSessionRequestBody = z.infer<typeof UpdateSessionRequestBody>;

0 commit comments

Comments
 (0)