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
@@ -432,6 +432,18 @@ describe('deleteUser', () => {
const result = (await deleteUser('99999', admin.id)) as any;
expect(result.status).toBe(404);
});
it('ADMIN-SVC-017B: an id spelled in hex or with an exponent names no user, so an admin cannot delete their own account that way', async () => {
const { user: admin } = createAdmin(testDb);
// parseInt('0x..') was 0 for the self check while Number() reached the admin's own row.
const spellings = [`0x${admin.id.toString(16)}`, `${admin.id}e0`];
const results = (await Promise.all(spellings.map((spelling) => deleteUser(spelling, admin.id)))) as Array<{
status?: number;
}>;
expect(results.map((r) => r.status)).toEqual([404, 404]);
const kept = (await deleteUser(String(admin.id), admin.id)) as { status?: number };
expect(kept.status).toBe(400);
});
});
// ── getStats ──────────────────────────────────────────────────────────────────
@@ -452,7 +452,7 @@ describe('ImmichMemoriesController (parity with /api/integrations/memories/immic
});
const res = makeRes();
await new ImmichMemoriesController(svc).assetInfo(user, '5', 'a', '2', res);
expect(svc.canAccessUserPhoto).toHaveBeenCalledWith(7, 2, '5', 'a', 'immich');
expect(svc.canAccessUserPhoto).toHaveBeenCalledWith(7, '2', '5', 'a', 'immich');
expect(res.status).toHaveBeenCalledWith(403);
expect(res.json).toHaveBeenCalledWith({ error: 'Forbidden' });
});
@@ -850,7 +850,7 @@ describe('SynologyMemoriesController (parity with /api/integrations/memories/syn
const svc = makeService({ canAccessUserPhoto: vi.fn().mockReturnValue(false) });
const res = makeRes();
await new SynologyMemoriesController(svc).assetInfo(user, '5', 'p1', '2', undefined, res);
expect(svc.canAccessUserPhoto).toHaveBeenCalledWith(7, 2, '5', 'p1', 'synologyphotos');
expect(svc.canAccessUserPhoto).toHaveBeenCalledWith(7, '2', '5', 'p1', 'synologyphotos');
expect(res.status).toHaveBeenCalledWith(403);
expect(res.json).toHaveBeenCalledWith({ error: "You don't have access to this photo" });
});