Skip to content

fix(api): allow Tailscale CGNAT origins in dev CORS allow-list (#246)#249

Merged
w7-mgfcode merged 1 commit into
devfrom
fix/api-tailscale-cors-origins
May 19, 2026
Merged

fix(api): allow Tailscale CGNAT origins in dev CORS allow-list (#246)#249
w7-mgfcode merged 1 commit into
devfrom
fix/api-tailscale-cors-origins

Conversation

@w7-mgfcode
Copy link
Copy Markdown
Owner

@w7-mgfcode w7-mgfcode commented May 19, 2026

Closes #246.

Adds the Tailscale CGNAT range (100.64.0.0/10) to the dev-only allow_origin_regex in app/main.py, alongside the existing localhost + RFC 1918 ranges. Lets a tailnet-reachable dev backend pass CORS the same as a LAN host.

  • Dev-only — the else None production branch (explicit empty allow-list, no regex) is unchanged.
  • No new tests: the regex sits inside the existing dev CORS construction; behaviour is dev-network reachability, not unit-testable logic.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Extends 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
Loading

File-Level Changes

Change Details Files
Extend the development CORS allow-origin regex to allow requests from Tailscale CGNAT addresses.
  • Append a new regex fragment that matches the 100.64.0.0/10 Tailscale CGNAT range to the existing dev allow_origin_regex pattern
  • Keep existing localhost and RFC1918 private network patterns unchanged while adding the new range as an additional alternation
  • Ensure the new Tailscale pattern is only applied when settings.is_development is true, preserving the empty allow-list behaviour in production
app/main.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a37eadc6-0ba1-47cc-8949-84155753b07f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/api-tailscale-cors-origins

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cluttering create_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`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@w7-mgfcode w7-mgfcode merged commit 82c457e into dev May 19, 2026
8 checks passed
@w7-mgfcode w7-mgfcode deleted the fix/api-tailscale-cors-origins branch May 19, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant