fix(planner): scheme-check the booking URL, and stop the serial routing calls

A booking's url is rendered as a plain href to every other member of the trip
and nothing ever checked its scheme, so a collaborator could store
javascript: there. The place website next to it has been going through
safeHttpUrl for exactly this reason, with a comment saying stored values
predate the server check - this is the surface that was left. Both ends now:
safeHttpUrl at the render site, and the scheme in the shared contract so
nothing new gets stored, additively so existing rows still load.

The per-leg routing rewrite turned one multi-waypoint request per run into
one serial request per leg. A twelve-stop day is eleven round trips to a
public OSRM in sequence before a single connector appears, and toggling km/mi
does it all again. Group consecutive legs that resolve to the same mode into
one request and fire the groups concurrently, keeping leg order on the join.

Transport reordering wrote to the store and persisted with a bare catch, so
a failed PUT left the sidebar showing an order the server never got; it
reconciles now. Plus the smaller ones: the OSM menu_url rendered unchecked,
expand/collapse-all persisting to a different storage than the day list reads,
the debounced address search with no ordering guard, the accommodation save
chain with no error path, and window.__trek_map holding a destroyed map.
This commit is contained in:
Maurice
2026-08-23 10:07:43 +02:00
committed by Maurice
parent 47a4276e84
commit 61d4fd4d64
18 changed files with 407 additions and 63 deletions
@@ -1,5 +1,6 @@
import {
reservationCreateRequestSchema,
reservationUpdateRequestSchema,
reservationPositionsRequestSchema,
accommodationCreateBodySchema,
accommodationCreateRequestSchema,
@@ -20,6 +21,23 @@ describe('reservationCreateRequestSchema', () => {
).toBe(true);
expect(reservationCreateRequestSchema.safeParse({ location: 'x' }).success).toBe(false);
});
it('rejects a booking url that executes instead of navigating, on create and update', () => {
expect(reservationCreateRequestSchema.safeParse({ title: 'Hotel', url: 'javascript:alert(1)' }).success).toBe(false);
expect(reservationCreateRequestSchema.safeParse({ title: 'Hotel', url: 'JavaScript:alert(1)' }).success).toBe(false);
expect(reservationCreateRequestSchema.safeParse({ title: 'Hotel', url: ' \tjava\nscript:alert(1)' }).success).toBe(false);
expect(reservationCreateRequestSchema.safeParse({ title: 'Hotel', url: 'data:text/html,<script>x</script>' }).success).toBe(false);
expect(reservationUpdateRequestSchema.safeParse({ url: 'vbscript:msgbox' }).success).toBe(false);
});
it('keeps every link people actually paste valid (no stored row becomes unsavable)', () => {
for (const url of ['https://hotel.example/booking', 'http://hotel.example', 'www.hotel.com', 'hotel.example/x?a=b', '']) {
expect(reservationCreateRequestSchema.safeParse({ title: 'Hotel', url }).success).toBe(true);
expect(reservationUpdateRequestSchema.safeParse({ url }).success).toBe(true);
}
expect(reservationUpdateRequestSchema.safeParse({ url: null }).success).toBe(true);
expect(reservationUpdateRequestSchema.safeParse({ location: 'x' }).success).toBe(true);
});
});
describe('reservationPositionsRequestSchema', () => {
+22 -2
View File
@@ -202,11 +202,31 @@ export const accommodationSchema = z.object({
});
export type Accommodation = z.infer<typeof accommodationSchema>;
/**
* A booking link, as it is rendered into an href by the reservations panel. It
* deliberately stays free-form — people paste bare hosts ("www.hotel.com") and
* provider deep links, and rows written before this check exist — so the contract
* only rejects the schemes that execute in this origin instead of opening a page.
* Same class of bug as placeWebsiteSchema, one step narrower so nobody's stored
* link becomes unsavable.
*/
export const reservationUrlSchema = z.string().refine(
// Browsers strip control characters and whitespace before they resolve the
// scheme, so a tab spliced into 'javascript:' still runs.
v => !/^(javascript|data|vbscript):/i.test(v.replace(/[\u0000-\u0020]/g, '')),
{ message: 'must not be a javascript:, data: or vbscript: URL' },
);
/** Reservation create: title is required; the many optional fields stay open. */
export const reservationCreateRequestSchema = open.and(z.object({ title: z.string().min(1) }));
export const reservationCreateRequestSchema = open.and(z.object({
title: z.string().min(1),
url: reservationUrlSchema.nullable().optional(),
}));
export type ReservationCreateRequest = z.infer<typeof reservationCreateRequestSchema>;
export const reservationUpdateRequestSchema = open;
export const reservationUpdateRequestSchema = open.and(z.object({
url: reservationUrlSchema.nullable().optional(),
}));
export type ReservationUpdateRequest = z.infer<typeof reservationUpdateRequestSchema>;
/** Assign trip members/guests to a reservation (mirrors budget's PUT :id/members). */