Use CORS origin regex for Tailscale domain #18
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Lineage
plan-mcd-tracker→ Phase 7c (Local Dev Stack)Repo
forgejo_admin/mcd-tracker-apiUser Story
As a developer adding new dev URLs (mcd-tracker-dev, capacitor-dev, future hostnames)
I want the API to accept CORS from any *.tail5b443a.ts.net hostname automatically
So that I never have to update CORS origins and redeploy the API just because I created a new Tailscale funnel
Context
Every new dev URL requires a code change to
main.pyCORS origins + a full CI rebuild. This happened twice in one session (capacitor-dev, mcd-tracker-dev). FastAPI's CORSMiddleware supportsallow_origin_regexwhich solves this permanently. Non-Tailscale origins (capacitor://localhost, http://localhost) stay as explicit entries.File Targets
Files to modify:
src/mcd_tracker_api/main.py— replaceallow_originslist withallow_origin_regexfor Tailscale domain + explicit list for non-Tailscale originsAcceptance Criteria
https://*.tail5b443a.ts.netorigin is accepted by CORScapacitor://localhostandhttp://localhoststill workhttp://localhost:5173still worksTest Expectations
pytestpassescurl -H "Origin: https://anything.tail5b443a.ts.net" -I http://localhost:8000/healthzreturnsAccess-Control-Allow-Originheadercurl -H "Origin: https://evil.com" -I http://localhost:8000/healthzdoes NOT return the headercd ~/mcd-tracker-api && .venv/bin/pytestConstraints
allow_origin_regexfrom FastAPI CORSMiddleware — not a custom middlewaresettings.tailscale_domainor similar)capacitor://localhostandhttp://localhost*as explicit allowed origins (regex can't cover non-https schemes cleanly)Checklist
Related
mcd-tracker— project this affectsplan-mcd-tracker— Phase 7csop-capacitor-mobile-lifecycle— this eliminates the CORS step from dev setup