Repository navigation
feat(hub): add opt-in CORS allowlist for the client API - #17
Conversation
Browser apps on other origins, such as the Ares slicer web app sending a plate to a printer, need to call the Bearer-token client API directly. PANDAR_CORS_ALLOWED_ORIGINS takes comma-separated exact http(s) origins; wildcards, paths, and userinfo fail startup, and unset keeps the previous no-CORS behavior. Only /api/v1/me and /api/v1/tenants/... answer CORS, allowing GET/POST/OPTIONS with Authorization and Content-Type and never sending Access-Control-Allow-Credentials. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 349a19f1eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Motivation
The Ares slicer web app (for example
https://ares-cdh.pages.dev, orhttp://127.0.0.1:5173in dev) needs a "send plate to printer" flow through Pandar. To do that it calls the Hub client API straight from the browser withAuthorization: Bearer <tenant token>. The Hub has no CORS layer today, so browsers block these cross-origin calls.Change
New Hub env var
PANDAR_CORS_ALLOWED_ORIGINS:https://ares-cdh.pages.dev,http://127.0.0.1:5173. Whitespace around entries and empty entries are ignored.Access-Control-*headers are sent. This is the current behavior.httporhttpswith a host and optional port.*,null, wildcard hosts, paths (including a trailing/), queries, userinfo, and other schemes all fail startup with an error that names the variable.A
tower-httpCorsLayercovers only the Bearer-token client API,/api/v1/meand/api/v1/tenants/.... It:GET,POST,PATCH,DELETE,OPTIONS(all methods exposed byclient_api_router)authorization,content-typeAccess-Control-Allow-Credentials, and exposes no extra headersPlugin, agent, bootstrap,
/api/v1/summary, join-link accept, onboarding, and observability routes have no CORS headers. The client routes now live in their ownclient_api_routerthat gets merged into the main router; the route definitions themselves are unchanged.tower-httpwas already in the lockfile throughreqwest. It is now a workspace dependency with only thecorsfeature. Also bumped transitiveurlto2.5.9(form_urlencoded1.2.3) inCargo.locksocargo auditclearsRUSTSEC-2026-0592.Security notes
Allow-Credentials, browsers never attach cookies or HTTP auth to these cross-origin requests. A page on a listed origin must supply a tenant token itself, so it can't use ambient credentials (no CSRF-style abuse)./api/v1/tenants/...prefix, allowing every HTTP method exposed byclient_api_router(GET,POST,PATCH,DELETE,OPTIONS). Every route still enforces its own Bearer auth, role, and scope checks; CORS only lets a listed origin read responses to requests it already authenticated.PANDAR_HUB_NO_AUTH=trueshould not set this variable to an untrusted origin.Tests
New route tests in
crates/pandar-hub/src/routes/tests/cors.rs:POST/PATCH/DELETE, andauthorization/content-type, with no credentials header and no auth neededaccess-control-*headersGET /api/v1/tenants/{id}/printersfrom a listed origin returns 200 withAccess-Control-Allow-Originand no credentials header*,null, a wildcard host, a path or trailing slash, a query, userinfo, no scheme,ftp) are rejectedLocal results:
cargo fmt --check: cleancargo clippy --workspace --all-targets -- -D warnings: cleancargo audit: clean (0 vulnerabilities)cargo nextest run --manifest-path "Cargo.toml" --workspace: passedDocs:
docs/development.md(env var semantics),CHANGELOG.md(Unreleased > Added),docs/roadmap.md. NixOS and Helm pass Hub env vars throughextraEnvironment/hub.env, so no new options are needed.