fix(api): read body, query and handler-parsed ids with toRowId instead of Number() and parseInt

The services and controllers that took an id from a request with Number(), parseInt() or not at all now use toRowId. That covers admin users, notifications (and their limit and offset), trip members and guests, day notes, assignments, memories (photo owner, album link, body photo_id), photos, mail-ingest, the assistant id parsers, dawarich, registration invites, the plugin contribution routes and the collab reply.

The accommodation update body is open, so AccommodationsService reads the place and day refs of every stay write with toRowId and answers a refused one with the create schema's 400.

AdminService.deleteUser checked the caller with parseInt and deleted with Number(), so an admin could delete their own account by spelling its id in hex; both now use one parse.

The OAuth session revoke called Number(id) first and so revoked session 5 for '0x5'; the service now reads the id as sent.
This commit is contained in:
Maurice
2026-11-18 13:20:06 +01:00
parent 3973741509
commit 6dfba51f21
36 changed files with 242 additions and 112 deletions
@@ -5,6 +5,7 @@ import { RequireAddon } from '../addons/require-addon.decorator';
import { getClientIp } from '../audit/client-ip';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { toRowId } from '../common/row-id';
import { DawarichSuggestionsService, AcceptError } from './dawarich-suggestions.service';
import { DawarichSyncService } from './dawarich-sync.service';
import { DawarichTracksService } from './dawarich-tracks.service';
@@ -267,16 +268,17 @@ function toHttp(err: unknown): HttpException {
/** Ids are integers. `parseInt` would turn "12abc" into 12 and log a request nobody made. */
function parseId(raw: string): number {
if (!/^\d+$/.test(raw)) throw new HttpException({ error: 'Invalid id' }, 400);
const id = Number(raw);
if (!Number.isSafeInteger(id) || id <= 0) throw new HttpException({ error: 'Invalid id' }, 400);
const id = toRowId(raw);
if (id === null || id <= 0) throw new HttpException({ error: 'Invalid id' }, 400);
return id;
}
function parseOptionalId(raw: string | undefined, label: string): number | undefined {
if (raw === undefined || raw === '') return undefined;
if (!/^\d+$/.test(raw)) throw new HttpException({ error: `Invalid ${label}` }, 400);
return Number(raw);
// toRowId: digits alone let a number past 2^53 through, which Postgres refuses as out of range.
const id = toRowId(raw);
if (id === null) throw new HttpException({ error: `Invalid ${label}` }, 400);
return id;
}
/** An unknown state is a 400 rather than a silently unfiltered list. */