mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
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:
@@ -1,6 +1,7 @@
|
||||
import { Days } from '../../../db/entities/Days.entity';
|
||||
import type { DaysRepository } from '../../../db/repositories/Days.repository';
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -96,10 +97,9 @@ export class DayScheduleController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ items: DayScheduleItem[] }> {
|
||||
if (!pluginsEnabled()) return { items: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const tripId = toRowId(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { items: [] };
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId))) return { items: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('dayScheduleProvider');
|
||||
if (ids.length === 0) return { items: [] };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Days } from '../../../db/entities/Days.entity';
|
||||
import type { DaysRepository } from '../../../db/repositories/Days.repository';
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -174,10 +175,9 @@ export class DayTintsController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ tints: DayTint[] }> {
|
||||
if (!pluginsEnabled()) return { tints: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const tripId = toRowId(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { tints: [] };
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId))) return { tints: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('dayTintProvider');
|
||||
if (ids.length === 0) return { tints: [] };
|
||||
|
||||
@@ -3,6 +3,7 @@ import { JourneyEntries } from '../../../db/entities/JourneyEntries.entity';
|
||||
import type { JourneyEntriesRepository } from '../../../db/repositories/JourneyEntries.repository';
|
||||
import { AddonsService } from '../../addons/addons.service';
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { JourneyDomainService } from '../../journey/journey-domain.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -91,9 +92,9 @@ export class JournalEntryRowsController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ providers: ProviderResult[] }> {
|
||||
if (!pluginsEnabled() || !(await this.addons.isAddonEnabled(ADDON_IDS.JOURNEY))) return { providers: [] };
|
||||
const entryId = Number(entryIdRaw);
|
||||
const entryId = toRowId(entryIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(entryId) || userId == null) return { providers: [] };
|
||||
if (entryId === null || userId == null) return { providers: [] };
|
||||
|
||||
// The entry's journey must be one the caller can access — same gate as a read.
|
||||
const row = await this.journeyEntries.findById(entryId); // JEC1 — converted (Plan 3g Task 4)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -159,10 +160,9 @@ export class MapLayersController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ layers: MapLayer[] }> {
|
||||
if (!pluginsEnabled()) return { layers: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const tripId = toRowId(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { layers: [] };
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId))) return { layers: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('mapLayerProvider');
|
||||
const perProvider = await Promise.all(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -93,10 +94,9 @@ export class MapMarkersController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ markers: MapMarker[] }> {
|
||||
if (!pluginsEnabled()) return { markers: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const tripId = toRowId(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { markers: [] };
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId))) return { markers: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('mapMarkerProvider');
|
||||
const perProvider = await Promise.all(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -88,9 +89,9 @@ export class PdfSectionsController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ sections: PdfSection[] }> {
|
||||
if (!pluginsEnabled()) return { sections: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const tripId = toRowId(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { sections: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('pdfSectionProvider');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Places } from '../../../db/entities/Places.entity';
|
||||
import type { PlacesRepository } from '../../../db/repositories/Places.repository';
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -80,9 +81,9 @@ export class PlaceDetailsController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ providers: ProviderResult[] }> {
|
||||
if (!pluginsEnabled()) return { providers: [] };
|
||||
const placeId = Number(placeIdRaw);
|
||||
const placeId = toRowId(placeIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(placeId) || userId == null) return { providers: [] };
|
||||
if (placeId === null || userId == null) return { providers: [] };
|
||||
|
||||
// The place must belong to a trip the caller can access — same gate as a read.
|
||||
const tripId = await this.places.findTripId(placeId); // CT7 — Plan 3j
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Plugins } from '../../../db/entities/Plugins.entity';
|
||||
import type { PluginsRepository } from '../../../db/repositories/Plugins.repository';
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -50,9 +51,8 @@ export class PluginRoutesController {
|
||||
): Promise<{ route: PluginRouteOut | null }> {
|
||||
if (!pluginsEnabled()) return { route: null };
|
||||
const userId = req.user?.id;
|
||||
const tripId = Number(body?.tripId);
|
||||
if (userId == null || !Number.isFinite(tripId) || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { route: null };
|
||||
const tripId = toRowId(body?.tripId);
|
||||
if (userId == null || tripId === null || !(await this.trips.findAccessible(tripId, userId))) return { route: null };
|
||||
if (!PROFILE_RE.test(profileId)) return { route: null };
|
||||
const waypoints = readWaypoints(body?.waypoints);
|
||||
if (!waypoints) return { route: null };
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -110,8 +111,8 @@ export class TripCardContributionsController {
|
||||
// are handed to any plugin.
|
||||
const requested = (tripIdsRaw ?? '')
|
||||
.split(',')
|
||||
.map((s) => Number(s.trim()))
|
||||
.filter((n) => Number.isInteger(n) && n > 0)
|
||||
.map((s) => toRowId(s.trim()))
|
||||
.filter((n): n is number => n !== null && n > 0)
|
||||
.slice(0, MAX_TRIP_IDS);
|
||||
const uniqueRequested = [...new Set(requested)];
|
||||
// Sequential, not `Promise.all` (Plan 3c Task 0b, task-0a-review-security.md
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -39,9 +40,9 @@ export class TripWarningsController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ warnings: Warning[] }> {
|
||||
if (!pluginsEnabled()) return { warnings: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const tripId = toRowId(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { warnings: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('warningProvider');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
import { pluginsEnabled } from '../kill-switch';
|
||||
import { PluginHooks } from '../plugin-hooks.service';
|
||||
@@ -148,9 +149,9 @@ export class ViewContributionsController {
|
||||
@Req() req: Request & { user?: { id: number } },
|
||||
): Promise<{ contributions: Contribution[] }> {
|
||||
if (!pluginsEnabled() || !VIEWS.has(view)) return { contributions: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const tripId = toRowId(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { contributions: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('tableContributor');
|
||||
|
||||
Reference in New Issue
Block a user