fix(api): require a signed-in user for the BRouter route proxy #43
No reviewers
Labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
public/wanderer!43
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/brouter-auth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
POST /api/v1/brouter/routeanswers anonymous callers (found by the M4 review,docs/fork/m4-brouter-vs-valhalla.mdin #42). That includes therawProfileandparamspaths, which upload a profile into BRouter's custom-profile store. wanderer.bearoverse.com is LAN/tailnet only, so the exposure is internal, but anonymous profile upload is still wrong.The "upload paths" are not separate endpoints. They are branches of the same route handler, which posts to BRouter's
/brouter/profilefrom the server. BRouter itself is a ClusterIP service and the browser never reaches it.Fix
BROUTER_URLconfig and before parsing the body. Without a session it returns401 {"message":"Unauthorized"}and never calls BRouter.locals.user.idpluslocals.pb.authStore.isValid === true.hooks.server.tsfills both from thepb_authcookie or awanderer_keyAPI token, afterauthRefresh. The check moves into$lib/server/session.ts(verifiedUserId).authorizeTrailAnalyzenow calls it; its behaviour does not change, and the 63 trail-analyze tests are unchanged and pass.Why gate the whole endpoint, not only the upload paths
BRouterAdapter, reached throughgetRouter()fromvalhalla_store(calculateRouteBetween),route_editor.svelteandloop_generator.svelte. All three are used only by/trail/edit/[id]. No public trail page, list or profile view requests routes, so an anonymous route has no user to serve.translateBRouterturns every non-neutral preference (technicality, flat, avoid roads) intoparams, andparamsmeans substitute and upload. Gating only uploads would leave just "route with a named profile" open.Not changed: the upstream Valhalla proxy (
/api/v1/valhalla/*) stays anonymous as in upstream. It is upstream code, and it cannot upload anything.Tests (spl-vm03, node 22.23.3, niced)
session.test.ts(8 tests): valid session, plus null for no user, empty locals, an invalid auth store, missingpb, an empty or non-string id, and a truthy non-trueisValid.brouter-route.test.ts(9 tests):paramsupload and arawProfileupload, with no BRouter fetch.BROUTER_URLcheck and before body parsing.locals.npm run check: 0 errors. The 2 warnings are already in an untouched planner file.npm run test:unit -- --run: 69 files passed, 2 skipped; 810 tests passed, 13 skipped.For review
deploy(same commit asdeploy-v0.21.2,ca06282e, as in #41/#42). Production runsdeploy-v0.21.2, so after merging, fast-forwarddeploy-v0.21.2(or build fromdeploy) and roll out an image.POST /api/v1/brouter/routeshould return 401. Signed in, BRouter routing and the loop generator in the trail editor should work as before.uploadedProfileIds) has no size limit. A signed-in user can still grow it with many distinctrawProfiletexts, and BRouter's own profile store grows with them.🤖 Generated with Claude Code
https://claude.ai/code/session_01XMf4EKLnjYyjFp8QGWgFFq