fix(shared): refuse a malformed row id in every request schema

Request fields that hold a row id took z.union([z.number(), z.string()]), a bare z.string() or z.array(z.number()), so '0x5', '5e0', 1.5 and 1e20 reached the handler and from there SQL, where SQLite matches nothing, Postgres 14 and 15 refuse the cast and 16 and later read hex and underscores as a number. Two primitives join idParamSchema: rowIdInputSchema takes a safe integer or its digits and keeps the value as sent, so field types do not change; rowIdStringSchema takes digits only, for multipart fields. Both refuse with 'Invalid id'. The accommodation, assignment, reservation position, admin invite, collab reply, vacay, file and memories photo ids now use them, and every list of ids is z.array(z.number().int()). idParamSchema takes only the decimal spelling or a whole number, and the trip-journal-link and tour library ids use it. A body id spelled '0x5' is now a 400 on SQLite too.
This commit is contained in:
Maurice
2026-11-18 13:20:05 +01:00
parent 3eac508baf
commit 3973741509
20 changed files with 149 additions and 75 deletions
+5 -4
View File
@@ -1,3 +1,4 @@
import { rowIdInputSchema } from '../common/primitives.schema';
import { assignmentPlaceSchema } from '../place/place.schema';
import { stationKeySchema } from '../tours/tours.schema';
@@ -74,7 +75,7 @@ export const assignmentSchema = z.object({
export type Assignment = z.infer<typeof assignmentSchema>;
export const assignmentCreateRequestSchema = z.object({
place_id: z.union([z.number().int(), z.string()]),
place_id: rowIdInputSchema,
notes: z.string().nullable().optional(),
/**
* MDT-02: puts one stage of a multi-day tour on the day instead of the whole
@@ -86,12 +87,12 @@ export const assignmentCreateRequestSchema = z.object({
export type AssignmentCreateRequest = z.infer<typeof assignmentCreateRequestSchema>;
export const assignmentReorderRequestSchema = z.object({
orderedIds: z.array(z.number()),
orderedIds: z.array(z.number().int()),
});
export type AssignmentReorderRequest = z.infer<typeof assignmentReorderRequestSchema>;
export const assignmentMoveRequestSchema = z.object({
new_day_id: z.union([z.number(), z.string()]),
new_day_id: rowIdInputSchema,
// The client api types this `number | null` (assignmentsApi.move) and the
// legacy route accepted null (`orderIndex || 0`) — keep null on the wire.
order_index: z.number().int().nullable().optional(),
@@ -157,6 +158,6 @@ export const assignmentRouteRequestSchema = z.object({
export type AssignmentRouteRequest = z.infer<typeof assignmentRouteRequestSchema>;
export const assignmentParticipantsRequestSchema = z.object({
user_ids: z.array(z.number()),
user_ids: z.array(z.number().int()),
});
export type AssignmentParticipantsRequest = z.infer<typeof assignmentParticipantsRequestSchema>;