trails/apps/planner/app/lib
Ullrich Schäfer 51e6b8a0d7
fix(planner): validate callback/returnUrl + cap session URL-param payloads
Addresses planner audit #3 (SSRF via callbackUrl) and #7 (URL-param
size). Two attack surfaces hardened:

1. /new loader — \`callback\`, \`token\`, \`returnUrl\`, \`gpx\` query
   params now validated:
   - callbackUrl: must be a valid absolute http(s) URL ≤ 2048 chars.
     If \`PLANNER_CALLBACK_ALLOWED_HOSTS\` is set (comma-separated),
     the host must match — defense-in-depth SSRF guard for self-
     hosted instances. Unset = no allowlist (dev / open self-host).
   - token: max 2048 chars.
   - returnUrl: must be a same-origin path or absolute http(s) URL
     ≤ 2048 chars. Rejects \`javascript:\`, \`data:\`, and
     protocol-relative \`//host\` (which would resolve to a remote
     origin on HTTPS pages).
   - gpx: ≤ 2 MB encoded.
   Invalid input throws 400 from the loader.

2. /session/:id default-export component — \`waypoints\`, \`noGoAreas\`,
   \`notes\`, \`returnUrl\` URL params now bounded before
   \`JSON.parse\` / use:
   - waypoints / noGoAreas: ≤ 50KB each; over-cap returns undefined
     (component starts with empty initial state, same as malformed).
   - notes: ≤ 10KB.
   - returnUrl: ≤ 2KB + same scheme rules as #1.

Pulled the URL validation into \`lib/url-validation.server.ts\` so
both routes (and any future caller) share the same rules.

Tests: \`url-validation.server.test.ts\` (14 cases — schemes,
allowlist, length caps, protocol-relative guards, env parsing).

Full repo: pnpm typecheck / lint / test all green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 00:05:47 +02:00
..
__screenshots__/elevation-chart-draw.browser.test.tsx chore: update visual snapshots [skip ci] 2026-05-10 17:15:46 +00:00
brouter.test.ts BRouter host compose + Planner auth + cd-brouter rewrite 2026-04-23 22:52:48 +02:00
brouter.ts fix(planner/brouter): add 30s timeout to outbound fetch 2026-05-25 23:53:19 +02:00
crash-recovery.test.ts Add transactional emails (SMTP) and planner features (no-go areas, notes, crash recovery) 2026-03-26 01:00:42 +01:00
db.ts Add Drizzle ORM with shared db package (#10) 2026-03-22 22:35:50 +00:00
elevation-chart-draw.browser.test.tsx Fix Vitest browser provider setup and test cleanup 2026-05-10 19:01:24 +02:00
elevation-chart-draw.ts Split ElevationChart + PlannerMap into deep modules; add visual regression testing 2026-05-10 16:41:23 +02:00
host-election.test.ts Fix planner production server + use .ts extensions everywhere 2026-03-25 01:41:33 +01:00
host-election.ts Fix waypoint drag, host election, segment routing, debug panel 2026-03-23 08:52:52 +01:00
http.server.test.ts fix(planner/brouter): add 30s timeout to outbound fetch 2026-05-25 23:53:19 +02:00
http.server.ts fix(planner/brouter): add 30s timeout to outbound fetch 2026-05-25 23:53:19 +02:00
logger.server.test.ts feat(planner): per-request requestId propagated through logs 2026-05-25 22:43:58 +02:00
logger.server.ts feat(planner): per-request requestId propagated through logs 2026-05-25 22:43:58 +02:00
metrics.server.ts Failover across multiple Overpass upstreams 2026-04-21 07:36:10 +02:00
overnight.test.ts Add per-day map coloring and remaining unit tests 2026-04-11 00:12:27 +02:00
overnight.ts Add multi-day data model, computeDays, and GPX roundtrip 2026-04-10 23:51:31 +02:00
overpass.server.ts Fix planner build: move Overpass upstream fetch to overpass.server.ts 2026-04-23 22:40:15 +02:00
overpass.test.ts Add per-waypoint notes and nearby POI snap to Planner 2026-05-17 23:58:21 +02:00
overpass.ts Add per-waypoint notes and nearby POI snap to Planner 2026-05-17 23:58:21 +02:00
poi-cache.test.ts Add i18n keys and unit tests for overlays 2026-04-11 01:19:27 +02:00
poi-cache.ts Add Overpass client, POI categories, cache, and usePois hook 2026-04-11 01:15:34 +02:00
poi-categories.test.ts Extract @trails-cool/map-core package from Planner 2026-04-12 22:28:14 +02:00
poi-snap.ts Extract @trails-cool/map-core package from Planner 2026-04-12 22:28:14 +02:00
rate-limit.test.ts Fix planner production server + use .ts extensions everywhere 2026-03-25 01:41:33 +01:00
rate-limit.ts Increase route rate limit from 60 to 300 requests/hour 2026-04-11 02:05:41 +02:00
require-session.test.ts Session-bind /api/route and /api/overpass 2026-04-21 22:18:45 +02:00
require-session.ts Session-bind /api/route and /api/overpass 2026-04-21 22:18:45 +02:00
route-merge.test.ts Cache BRouter segments client-side, fetch only the diff 2026-04-24 17:57:54 +02:00
route-merge.ts Cache BRouter segments client-side, fetch only the diff 2026-04-24 17:57:54 +02:00
segment-cache.test.ts Cache BRouter segments client-side, fetch only the diff 2026-04-24 17:57:54 +02:00
segment-cache.ts Cache BRouter segments client-side, fetch only the diff 2026-04-24 17:57:54 +02:00
sessions.ts Add split export: Export Route vs Export Plan 2026-04-03 10:52:39 +01:00
snap-to-poi.test.ts Add per-waypoint notes and nearby POI snap to Planner 2026-05-17 23:58:21 +02:00
url-validation.server.test.ts fix(planner): validate callback/returnUrl + cap session URL-param payloads 2026-05-26 00:05:47 +02:00
url-validation.server.ts fix(planner): validate callback/returnUrl + cap session URL-param payloads 2026-05-26 00:05:47 +02:00
use-days.ts Add multi-day data model, computeDays, and GPX roundtrip 2026-04-10 23:51:31 +02:00
use-elevation-data.ts Split ElevationChart + PlannerMap into deep modules; add visual regression testing 2026-05-10 16:41:23 +02:00
use-gpx-drop.ts Centralize waypoint Yjs serialization in waypointFromYMap/waypointToYMap 2026-05-18 21:02:27 +02:00
use-host-election.ts Deepen three architectural seams: FIT consolidation, host election extraction, injectable db 2026-05-10 15:52:31 +02:00
use-nearby-pois.ts Add per-waypoint notes and nearby POI snap to Planner 2026-05-17 23:58:21 +02:00
use-pois.ts Session-bind /api/route and /api/overpass 2026-04-21 22:18:45 +02:00
use-profile-defaults.ts Extract @trails-cool/map-core package from Planner 2026-04-12 22:28:14 +02:00
use-routing.ts Deepen three architectural seams: FIT consolidation, host election extraction, injectable db 2026-05-10 15:52:31 +02:00
use-undo.test.ts Add undo/redo to planner 2026-04-04 10:04:01 +01:00
use-undo.ts Add undo/redo to planner 2026-04-04 10:04:01 +01:00
use-waypoint-manager.ts Centralize waypoint Yjs serialization in waypointFromYMap/waypointToYMap 2026-05-18 21:02:27 +02:00
use-yjs-poi-sync.ts Add Yjs sync for POI categories across participants 2026-04-11 02:28:11 +02:00
use-yjs.ts Centralize waypoint Yjs serialization in waypointFromYMap/waypointToYMap 2026-05-18 21:02:27 +02:00
vite-yjs-plugin.ts Fix waypoint drag, host election, segment routing, debug panel 2026-03-23 08:52:52 +01:00
waypoint-ymap.ts Centralize waypoint Yjs serialization in waypointFromYMap/waypointToYMap 2026-05-18 21:02:27 +02:00
yjs-server.test.ts Fix planner_active_sessions gauge drifting negative 2026-04-22 22:37:58 +02:00
yjs-server.ts Fix planner_active_sessions gauge drifting negative 2026-04-22 22:37:58 +02:00