fix(db): read every request row id through toRowId, at the trip guards and the repository lookups

toRowId moves to src/db/row-id.ts so repositories can use it (src/db sits below src/nest), together with a new withRowId helper; src/nest/common/row-id.ts re-exports both. Its docstring is rewritten to state the rule plainly. TripsRepository read its number | string trip ids raw: SQLite matched '0x1' against nothing, Postgres 14 and 15 refused the cast with a 500, and 16 and later read it as trip 1. Its access reads, DaysRepository.existsInTrip and the packing template lookups now parse the id first, so an id toRowId refuses is no row on every engine. TripAccessGuard, TripOwnerGuard and JourneyAssistantGuard used Number(), which read '0x1' and '1e0' as row 1; they now use toRowId.
This commit is contained in:
Maurice
2026-11-18 13:20:05 +01:00
parent f2cfbc4041
commit 7f6f2eb97c
16 changed files with 218 additions and 201 deletions
+4 -3
View File
@@ -481,7 +481,7 @@ describe('Roadtrip e2e (real guard chain + temp SQLite)', () => {
// raw-bind statement's affinity never converts a hex string, so it
// always answered empty. Every one of these three now answers the
// legacy empty shape for the same hex id, not the real trip's rows.
it("L1 — vias/tracks by a hex-spelled trip id answer the legacy empty shape, not trip 5's real rows", async () => {
it("vias/tracks by a hex-spelled trip id answer the guard's 404, not trip 5's real rows", async () => {
const created = await request(server)
.post('/api/trips/5/roadtrip/days/3/vias')
.set('Cookie', cookie())
@@ -490,8 +490,9 @@ describe('Roadtrip e2e (real guard chain + temp SQLite)', () => {
const hexTripId = '0x' + (5).toString(16);
const res = await request(server).get(`/api/trips/${hexTripId}/roadtrip/vias`).set('Cookie', cookie());
expect(res.status).toBe(200);
expect(res.body).toEqual({ vias: [], tracks: [] });
// TripAccessGuard reads :tripId through toRowId, so the hex spelling is no trip at all.
expect(res.status).toBe(404);
expect(res.body).toEqual({ error: 'Trip not found' });
const hexDayId = '0x' + (3).toString(16);
const dayRes = await request(server).get(`/api/trips/5/roadtrip/days/${hexDayId}/vias`).set('Cookie', cookie());