Skip to content

Comments

feat(vercel): redirect SSO login to EU when resource not found in US#48650

Merged
MattBro merged 9 commits intomasterfrom
matt/vercel-sso-region-redirect
Feb 23, 2026
Merged

feat(vercel): redirect SSO login to EU when resource not found in US#48650
MattBro merged 9 commits intomasterfrom
matt/vercel-sso-region-redirect

Conversation

@MattBro
Copy link
Contributor

@MattBro MattBro commented Feb 20, 2026

Problem

When a Vercel Marketplace EU user clicks SSO login, Vercel sends them to us.posthog.com/login/vercel/ with a single-use authorization code. The US region doesn't have the EU resource, so SSO fails. We can't proxy the request server-side because the SSO code is consumed on first use — it must be a browser redirect so the code reaches the correct region.

Changes

  • Added VercelRegionProxyMixin to VercelSSOViewSet for region detection (current_region, is_dev_env, EU_DOMAIN)
  • Overrode dispatch to skip the mixin's server-side proxy behavior (SSO needs browser redirects, not proxying)
  • Added _should_redirect_to_eu() check: redirects when US region + resource not found locally
  • In sso_redirect, before consuming the SSO code, checks if redirect is needed and returns 302 to eu.posthog.com/login/vercel/ with all query params preserved

How did you test this code?

Automated tests — 6 new tests in TestSSORegionRedirect:

  • US region, resource not found → redirects to EU with all params
  • US region, resource found → processes normally
  • EU region → processes normally (no redirect)
  • Dev env → processes normally (no redirect)
  • Missing resource_id → processes normally
  • All query params preserved in redirect URL

Manual testing — Used ngrok + cloudflared tunnels to simulate the full Vercel → US → EU redirect flow locally. Verified installation, plans endpoint, and SSO redirect all work through the tunnel infrastructure.

Changelog

Yes — Vercel Marketplace EU SSO login now works when the Configuration URL points to the US region.

🤖 Generated with Claude Code

When Vercel sends an EU user to us.posthog.com/login/vercel/, the SSO
code is single-use and cannot be proxied server-side. This adds a
browser redirect to eu.posthog.com with all query params preserved when
the resource_id does not exist in the US region.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

MattBro and others added 4 commits February 20, 2026 19:01
- Wrap Integration.objects.filter(pk=resource_id) in try/except for
  ValueError/TypeError when resource_id is non-numeric
- Use request.query_params.urlencode() instead of urllib urlencode() to
  correctly handle multi-value query params
- Add test for non-integer resource_id redirect

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix dispatch return type to HttpResponseBase (mypy)
- Add nosemgrep for intentional cross-team Integration lookup
- Parse resource_id as int before DB query to avoid ValueError
- Non-integer resource_id proceeds normally instead of redirecting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change return type from HttpResponse to HttpResponseBase to match
the actual return type of super().dispatch() and allow subclass
overrides without mypy errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MattBro MattBro requested review from a team, fercgomes and rafaeelaudibert and removed request for a team February 23, 2026 15:17
MattBro and others added 2 commits February 23, 2026 10:19
Keep VercelRegionProxyMixin.dispatch as HttpResponse to avoid breaking
existing tests that access .content on the return value. Use
type: ignore in the SSO viewset override instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

🎭 Playwright report · View test results →

⚠️ 2 flaky tests:

  • toggles survey opt in on the survey settings page (chromium)
  • toggles survey opt in on the org settings page (chromium)

These issues are not necessarily caused by your changes.
Annoyed by this comment? Help fix flakies and failures and it'll disappear!

@tests-posthog
Copy link
Contributor

tests-posthog bot commented Feb 23, 2026

Query snapshots: Backend query snapshots updated

Changes: 1 snapshots (1 modified, 0 added, 0 deleted)

What this means:

  • Query snapshots have been automatically updated to match current output
  • These changes reflect modifications to database queries or schema

Next steps:

  • Review the query changes to ensure they're intentional
  • If unexpected, investigate what caused the query to change

Review snapshot changes →

resource_pk = int(resource_id)
except (ValueError, TypeError):
return False
# nosemgrep: idor-lookup-without-team — intentionally cross-team: checking if resource exists anywhere in this region
Copy link
Member

Choose a reason for hiding this comment

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

Does this allow cross enumeration? Make sure we have proper rate limits

@MattBro MattBro merged commit 530be16 into master Feb 23, 2026
177 checks passed
@MattBro MattBro deleted the matt/vercel-sso-region-redirect branch February 23, 2026 22:10
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.

2 participants