Skip to content

Fix saved-route id collisions, lock down OSM cache writes, close login open redirect, add web CI - #17

Merged
SpencerLiang0114 merged 4 commits into
SpencerLiang0114:mainfrom
victory-c:fix/saved-ids-osm-cache-redirect-ci
Oct 5, 2026
Merged

SpencerLiang0114 merged 4 commits into
SpencerLiang0114:mainfrom
victory-c:fix/saved-ids-osm-cache-redirect-ci

Conversation

@victory-c

@victory-c victory-c commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Four independent fixes, one commit each.

1. Saved routes overwrite each other (6289909)

Problem. POST /api/saved-routes upserted on the route id the client sent. Those ids repeat:

  • Generated routes are generated-loop-1, generated-loop-2, … in every run, from both the Rust and Java engines.
  • Uploads are uploaded-<slug>.
  • Strava routes are strava-segment-<id>.

The global saved_routes.id primary key turned that into two bugs:

Fix (backend). SavedRouteRepository.create always inserts a new row with a server-assigned id, saved-<uuid>. The ownership lookup and ON CONFLICT are gone. Existing rows, PATCH, DELETE and shares are unchanged and still scoped by user_id.

Fix (frontend).

  • The returned saved copy replaces its candidate in the persisted results, and activeRouteId follows it. After switching routes or reloading, the view still shows "Saved" and Share uses the real saved id.
  • ExportButtons no longer matches the library by client id. That match would hand a new loop refactor: backend owns route generation, restructure to apps/web layout #1 last week's share.
  • Save is disabled while the request is in flight.
  • Deleting a route turns a reopened copy back into a candidate that can be saved again.
  • Logout clears the library state, so the next account in the same tab doesn't see the previous user's routes or their "Saved" state.

2. Anyone could rewrite the OSM street graph (b76877f)

Problem. PUT /api/osm-graph-cache was anonymous and exempt from CSRF. It replaced existing rows and accepted any elements with a TTL of up to 24h, and route generation reads that cache before Overpass. Anyone could swap the street graph for a popular start point.

Fix. The PUT moved to OsmGraphCacheSeedController. That controller is only registered when ROUTECRAFT_OSM_CACHE_WRITE_ENABLED=true, which only services/routing-compat/compose.test.yml sets, for seed-smoke.py. Otherwise the endpoint returns 405 and never parses the body. GET is unchanged.

3. Open redirect after login (9acd53c)

Problem. sanitizeNext let these through:

  • /\evil.com and /<tab>/evil.com: browsers read \ as / and drop tabs.
  • /.//evil.com and /x/%2e%2e//evil.com: dot segments normalize to the path //evil.com, which the Next router then navigates to.

So /login?next=/%5Cevil.com sent signed-in users off-site.

Fix. Login, Register and AuthGate now share lib/safeNextPath.ts. It rejects backslashes and control characters, resolves the value against a fixed origin, and checks and returns the normalized path.

4. CI (642dd5e)

  • New Web workflow running pnpm lint, tsc --noEmit, vitest and next build for apps/web. None of these ran in CI before.
  • Postgres readiness race. The healthcheck now goes over TCP. During init the image runs a temporary server that listens only on the Unix socket and passes the socket check just before shutting down. The integration job's createdb could then fail with "the database system is shutting down" (seen on main in run 35743597468).

Tests

  • ./mvnw clean test: 49 tests, 0 failures, 1 skipped (the opt-in integration test).
    • New SavedRouteRepositoryTests: the server assigns the id, and repeat saves get distinct ids.
    • New OsmGraphCacheSeedTests: PUT returns 405 when disabled and works when enabled.
  • pnpm lint, tsc --noEmit and pnpm build are clean. pnpm test runs 25 tests.
    • New safeNextPath tests cover every bypass above.
    • New routeStore tests cover save swap, delete, clearLibrary, and repeated client ids.
  • Before pushing, I ran an adversarial review of this diff in three separate passes: correctness, security and CI. All four issues it confirmed are fixed in these commits.

Note

This is based on main. Until #16 (the CSRF fix) lands, every saved-route write from the browser still gets a CSRF 403, so test the saving flow end to end with both merged.

🤖 Generated with Claude Code

victory-c and others added 4 commits October 3, 2026 21:32
Saves upserted on the client route id, but generated (generated-loop-N),
uploaded (uploaded-<slug>) and Strava ids repeat across generations and
users: a new save silently overwrote an earlier one with the same id, and
any other user got a permanent 403. POST /api/saved-routes now inserts a
new saved-<uuid> row.

On the frontend, the saved copy replaces its candidate in the persisted
results, so the view stays "Saved" and shares the real saved id after
switching routes or reloading, instead of matching the library by client
id. Save is guarded while in flight, deleting a route turns a reopened copy
back into a savable candidate, and logout clears the library state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Route generation trusts cached Overpass elements, and PUT
/api/osm-graph-cache let anyone replace them for any bbox for up to 24h.
The PUT now lives in a controller that is only registered when
ROUTECRAFT_OSM_CACHE_WRITE_ENABLED=true, which only the offline smoke test
compose override sets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Browsers treat "\" as "/" and drop tabs, so /login?next=/%5Cevil.com
passed the old prefix checks and sent signed-in users off-site. Login,
register and the auth gate now share one check that also rejects
backslashes, control characters and anything resolving to another origin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a Web workflow running lint, tsc, vitest and next build for apps/web.
Check Postgres health over TCP: the image's init-time server listens only
on the socket, so socket checks passed just before it shut down and the
integration job's createdb could hit "the database system is shutting
down".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 4, 2026

Copy link
Copy Markdown

@victory-c is attempting to deploy a commit to the spencerliang0114's projects Team on Vercel.

A member of the Team first needs to authorize it.

@SpencerLiang0114
SpencerLiang0114 merged commit 5e58541 into SpencerLiang0114:main Oct 5, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants