Skip to content

fix(auth): SSO allow-list and OAuth state check - #495

Merged
butschster merged 2 commits into
masterfrom
fix/sso-allowlist-state
Nov 22, 2026
Merged

butschster merged 2 commits into
masterfrom
fix/sso-allowlist-state

Conversation

@butschster

Copy link
Copy Markdown
Member

Problem

  1. Any provider account gets in. After the provider's login, handleCallback issued a token to every user. With AUTH_PROVIDER=google on a public Ingress (e.g. the Helm chart), any Google account could sign in and read all events.
  2. OAuth state was not checked. It was generated but never verified on the callback, so a forged callback link could log a victim into an attacker's account (login CSRF).

Change

  • New optional config auth.allowed_emails / auth.allowed_domains (env AUTH_ALLOWED_EMAILS, AUTH_ALLOWED_DOMAINS, comma lists; documented in buggregator.yaml.example). Auth has no CLI flags today, so these follow the other auth.* settings: yaml + env.
    • When a list is set, the provider must confirm the email (email_verified; GitHub: the verified primary email from /user/emails, falling back to the public profile email, which GitHub only allows from verified emails).
    • Email match is exact and ignores case. Domain match: Google's hd claim (the Workspace domain) for provider: google, so a personal Google account with a company address does not pass; for other providers, the domain of the verified email.
    • Refused → 403 HTML page naming the account, with a "sign in again" link; no token.
  • Default unchanged: no list = everyone the provider lets in, as before, plus a startup warning saying so. Changing that would lock out current SSO setups on upgrade. Reviewer: say if you think the default should change.
  • State: login sets an HttpOnly, SameSite=Lax cookie bg_oauth_state (path /auth/sso, 10 min, Secure over HTTPS or behind X-Forwarded-Proto: https). The callback refuses a missing or different state with 400 and always clears the cookie.

Verification

  • TestCallback_AllowListAndState (fake OIDC provider via httptest and the real OAuthClient): no list, Google hd allowed or denied, email domain without hd denied for Google, listed email, OIDC email domain, email_verified as a string, unverified email denied, state mismatch, no state cookie. Also TestStateCookieSecureBehindHTTPSProxy, TestGitHubVerifiedEmail, TestEnvList.
  • go vet ./... clean; go test -count=1 ./... green.
  • Live: binary + fake OIDC provider, AUTH_PROVIDER=google AUTH_ALLOWED_DOMAINS=acme.com. Workspace ann@acme.com → redirect to /login?token=…. Personal bob@gmail.com → 403 "bob@gmail.com is not allowed to sign in…". Callback with a forged state and no cookie → 400. /api/events without a token → 401.

Follow-up outside this repo: Helm chart values for the two new env vars.

Made with harnsy

- auth.allowed_emails / auth.allowed_domains (env AUTH_ALLOWED_EMAILS,
  AUTH_ALLOWED_DOMAINS): with a list set, only a provider-verified email on
  the list, or in an allowed domain, gets a token; others get a 403 page.
  Domain = Google's hd claim for provider google, the verified email's
  domain for the rest. No list = as before (anyone the provider signs in),
  with a startup warning.
- GitHub: verified primary email from /user/emails when the scope allows.
- Login sets an HttpOnly SameSite=Lax state cookie; the callback refuses a
  missing or different state (login CSRF) and clears the cookie.
@butschster butschster added type: bug Something is broken or behaves incorrectly security Security-sensitive issue labels Nov 22, 2026
A list set after sign-in now also cuts sessions issued before it: the
token carries email_verified and hd, and TokenStore applies the access
policy in Validate (HTTP middleware) and ExpiresAt (WebSocket connect).
Tokens without email_verified (issued before this change) fail a list.
@butschster

Copy link
Copy Markdown
Member Author

Review fix c26ad45: the token now carries email_verified and hd; TokenStore re-checks the allow-list in Validate (HTTP middleware) and ExpiresAt (WebSocket connect). Setting a list later signs out sessions that do not match it, including tokens issued before this change. Tests: TestMiddleware_AllowListCutsOldTokens, TestHub_AuthOn_AllowListCutsOldToken.

@butschster
butschster merged commit 1f34336 into master Nov 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security Security-sensitive issue type: bug Something is broken or behaves incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant