Repository navigation
Same-origin /api/v1 proxy for dashboard mutations (#59) - #60
Merged
Merged
Conversation
5 tasks
Contributor
Author
/review-pr outcomesTwo reviewers ran in parallel: code-reviewer + silent-failure-hunter. Three findings each, five real (some overlapped between reviewers). Addressed in 8470bed
Non-findings explicitly confirmed clean (no action)
|
This was referenced May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #59. Depends on
nemarOrg/nemar-cli#603(cookie auth on/datasets/*,/admin/*).Why
The session cookie is deliberately scoped
Domain=app.nemar.org(host-only against siblings). Browser-side fetches from dashboard JS toapi.nemar.orgtherefore don't carry the cookie even withcredentials: "include"(RFC 6265 forbids it). Broadening toDomain=nemar.orgwould leak the cookie to every*.nemar.orghost and was explicitly designed away.This PR ships the same-origin proxy as the proper fix.
How
New Astro catch-all
src/pages/api/v1/[...path].tsforwards anything under/api/v1/...to${apiBase()}/..., preserving method, body (asarrayBufferso binary uploads survive), and the Cookie + Origin headers. Rejects path-traversal / scheme-injection attempts before the upstream fetch. Set-Cookie passthrough on the response so sliding sessions from/auth/mekeep working if they ever flow through the proxy.New
dashboardApiBase(cookieHeader?)helper insrc/lib/api-base.ts:apiBase()(direct one-hop to api.nemar.org with the caller's explicit Cookie header)./api/v1(same-origin; browser auto-attaches the cookie; the worker forwards it).4 client libs refactored from
apiBase()todashboardApiBase(init.cookieHeader)(SSR-capable) ordashboardApiBase()(client-only):dashboard-api.ts,admin-api.ts,collaborators-api.ts,upload-client.ts. 11 callsites in total.Public-data clients (
api.ts,data-api.ts) deliberately unchanged — those reads are anonymous and edge-cacheable; going through the worker would just add latency.Test plan
bun run typecheck— 0 errorsbun run test— 364/364 (+14 new: proxy path-safety, dashboardApiBase split-resolution, plus updated lib tests that now assert the/api/v1/...URL on the browser path)bun run lint— cleancurl -i https://app.nemar.org/api/v1/datasets→ either 200 (with cookie) or 401 (without) — but not the previous "Origin not allowed" 403 path.app.nemar.org/api/v1/datasets?mine=trueRequest showsCookie: nemar_session=...while the same fetch toapi.nemar.org/datasets?mine=truewould not.Scope notes
app.nemar.org(no env-var change). Sibling subdomains never see it./api/v1/...; per-endpoint same-origin routes under/api/auth/*and/api/dataset/*keep their dedicated handlers and win over the catch-all by Astro's most-specific-route resolution.upload-client.ts::runUploadQueuecontinue to go client → S3 directly (the presigned URL points at S3, not at our backend); onlycreateDraftDatasetandfinalizeDatasetgo through the proxy.