mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-11-16 14:45:02 -06:00
[PR #367] [MERGED] fix(auth): trust registered SSO provider origins and honor deleteFromGitea #7935
Reference in New Issue
Block a user
📋 Pull Request Information
Original PR: https://github.com/RayLabsHQ/gitea-mirror/pull/367
Author: @arunavo4
Created: 8/21/2026
Status: ✅ Merged
Merged: 8/21/2026
Merged by: @arunavo4
Base:
main← Head:fix/sso-trusted-origins-cleanup-flags📝 Commits (1)
50acc48fix(auth): trust registered SSO provider origins and honor deleteFromGitea (#366)📊 Changes
7 files changed (+305 additions, -71 deletions)
View changed files
📝
docs/ENVIRONMENT_VARIABLES.md(+1 -1)📝
docs/SSO-OIDC-SETUP.md(+1 -0)📝
src/components/auth/LoginForm.tsx(+10 -1)📝
src/lib/auth-origins.test.ts(+56 -1)📝
src/lib/auth.ts(+76 -1)📝
src/lib/repository-cleanup-service.test.ts(+33 -1)📝
src/lib/repository-cleanup-service.ts(+128 -66)📄 Description
Fixes #366.
What broke
better-auth 1.6.23 (shipped in v3.21.0) added SSRF hardening to the SSO plugin: every SSO sign-in now DNS-resolves the IdP's token/userinfo/jwks endpoints and rejects them with a 400 if they resolve to a private address, unless the IdP origin is in
trustedOrigins. Homelab split-DNS setups (IdP domain resolving to a LAN IP from inside the container) break on every sign-in. Because sessions last 30 days, the breakage only surfaces when someone actually has to sign in again, which is why it looks like a recent regression.On top of that, the login form swallowed the error entirely: the auth client resolves with
{ data, error }instead of throwing, so thecatchnever fired. The button flipped back from "Redirecting..." with no toast and nothing in the server log at default level.Changes
src/lib/auth.ts):resolveTrustedOrigins()now includes the issuer and endpoint origins of every registered SSO provider. Registering a provider is an explicit operator action (same trust model as thedomainVerifiedflag we set at registration), so this is the sanctioned escape hatch applied automatically.BETTER_AUTH_TRUSTED_ORIGINSstill works and is still needed when registering a new internal IdP (documented in SSO-OIDC-SETUP.md).LoginForm.tsx): server-side rejections now show as an error toast instead of failing silently.deleteFromGitea/CLEANUP_DELETE_FROM_GITEA(repository-cleanup-service.ts): the flag was documented as "Delete repositories from Gitea" with afalsedefault but was never read — cleanup always archived/deleted orphans on the Gitea side. It now gates the Gitea-side operation: when disabled (the default), orphans are only marked archived or removed in gitea-mirror's own database and the Gitea/Forgejo copies stay untouched. Note this is a deliberate behavior change: installs relying on the old unconditional Gitea-side archive must setCLEANUP_DELETE_FROM_GITEA=trueto keep it.Verification
POST /api/auth/sign-in/ssoreturns 400discovery_private_hoston v3.27.1 and 200 with the authorization URL on this branch.deletewith the flag off removes only the DB row (Gitea never contacted); with the flag on, the Gitea call is attempted (fails with network error and marks the repofailed, as before).extractSsoProviderOrigins,planOrphanedRepoAction); full suite 503 pass / 0 fail.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.