trails/apps/planner/app/lib
Ullrich Schäfer ed7f6ce153
Session-bind /api/route and /api/overpass
Today both proxies are effectively open to anyone who can set an
Origin header for trails.cool — a third party can use us as a free
BRouter/Overpass relay. Require a live planner session on every call
so abuse traffic costs the scraper a session row (observable,
revocable) before they can issue a single query.

Server:
- New `requireSession(id)` helper — returns the session row or a 401
  Response. Reused by both route handlers.
- `/api/route`: `sessionId` in body is now required and verified;
  rate-limit key always falls back to the session id.
- `/api/overpass`: new `X-Trails-Session` header, verified. Header
  keeps the session out of the request body so the body-keyed cache
  is unaffected.

Client plumbing:
- `useRouting(yjs, sessionId)` — sessionId goes into the /api/route
  body.
- `usePois(sessionId)` → `queryPois(..., sessionId)` → `X-Trails-Session`
  on the proxy call.
- `PlannerMap` + `YjsDebugPanel` gain a `sessionId` prop from
  `SessionView`.

Journal server-to-server:
- Demo-bot and `/api/v1/routes/compute` now POST `/api/sessions` to
  mint a throwaway planner session, then cite it on the forwarded
  `/api/route` call. Planner's `expire-sessions` cron cleans these up
  (7d window) so nothing needs explicit teardown.

Tests:
- 5 unit tests for `requireSession` covering missing / empty /
  non-string / unknown-session / valid-session cases.
- Two integration E2E tests document the 401 for missing session on
  each proxy.
- Pre-existing `/api/route` integration tests updated to mint a
  session first.

Caveat: existing browser tabs lose their /api/route ability until
reload (the old JS doesn't know to send sessionId). Acceptable for
an anonymous planner.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 22:18:45 +02:00
..
brouter.test.ts Add road type color mode to route visualization 2026-04-11 11:13:43 +02:00
brouter.ts Route journal BRouter calls through the planner 2026-04-19 11:11:10 +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
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
logger.server.ts Add observability: health endpoints, structured logging, metrics, Grafana stack 2026-03-26 22:59:44 +01: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.test.ts Quantize Overpass query bbox to align cache keys across clients 2026-04-18 02:18:46 +02:00
overpass.ts Session-bind /api/route and /api/overpass 2026-04-21 22:18:45 +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
sessions.ts Add split export: Export Route vs Export Plan 2026-04-03 10:52:39 +01:00
use-days.ts Add multi-day data model, computeDays, and GPX roundtrip 2026-04-10 23:51:31 +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 Session-bind /api/route and /api/overpass 2026-04-21 22:18:45 +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-yjs-poi-sync.ts Add Yjs sync for POI categories across participants 2026-04-11 02:28:11 +02:00
use-yjs.ts Sync notes through GPX, Journal, and Planner roundtrip 2026-04-11 03:35:40 +02:00
vite-yjs-plugin.ts Fix waypoint drag, host election, segment routing, debug panel 2026-03-23 08:52:52 +01:00
yjs-server.ts Wire planner metrics gauges to actual session/client counts 2026-04-03 09:16:31 +01:00