fix(api): allow Tailscale CGNAT origins in dev CORS allow-list (#246)#249
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideExtends the development-only CORS allow_origin_regex to include Tailscale’s CGNAT address space so dev backends reachable over a tailnet are treated like LAN hosts, without affecting production behaviour. Flow diagram for updated dev CORS origin matching (Tailscale CGNAT support)flowchart LR
Browser["Browser with Origin header"] --> App["FastAPI_app (dev)"]
App --> CORS["CORSMiddleware allow_origin_regex"]
CORS -->|matches localhost| Allow["CORS allowed"]
CORS -->|matches RFC1918 10.x 192.168.x 172.16-31.x| Allow
CORS -->|matches Tailscale_CGNAT 100.64.0.0_10| Allow
CORS -->|no match| Block["CORS blocked"]
subgraph Dev_only_configuration
CORS --- Regex["allow_origin_regex includes:<br/>localhost<br/>10.0.0.0_8<br/>192.168.0.0_16<br/>172.16.0.0_12<br/>100.64.0.0_10 (Tailscale)"]
end
subgraph Production_configuration
ProdCORS["CORSMiddleware allow_origins empty"]
ProdCORS --> ProdBlock["No regex; Tailscale not specially allowed"]
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The IP allow-list regex is getting fairly complex; consider extracting it into a named constant or helper (e.g.,
DEV_CORS_IP_REGEX) so it’s easier to maintain or reuse without clutteringcreate_app.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The IP allow-list regex is getting fairly complex; consider extracting it into a named constant or helper (e.g., `DEV_CORS_IP_REGEX`) so it’s easier to maintain or reuse without cluttering `create_app`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Closes #246.
Adds the Tailscale CGNAT range (
100.64.0.0/10) to the dev-onlyallow_origin_regexinapp/main.py, alongside the existing localhost + RFC 1918 ranges. Lets a tailnet-reachable dev backend pass CORS the same as a LAN host.else Noneproduction branch (explicit empty allow-list, no regex) is unchanged.