[PR #367] [MERGED] fix(auth): trust registered SSO provider origins and honor deleteFromGitea #8626

Closed
opened 2026-08-26 01:03:05 -05:00 by GiteaMirror · 0 comments
Owner

📋 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)

  • 50acc48 fix(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 the catch never fired. The button flipped back from "Redirecting..." with no toast and nothing in the server log at default level.

Changes

  • Auto-trust registered SSO provider origins (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 the domainVerified flag we set at registration), so this is the sanctioned escape hatch applied automatically. BETTER_AUTH_TRUSTED_ORIGINS still works and is still needed when registering a new internal IdP (documented in SSO-OIDC-SETUP.md).
  • Surface SSO sign-in errors (LoginForm.tsx): server-side rejections now show as an error toast instead of failing silently.
  • Honor deleteFromGitea / CLEANUP_DELETE_FROM_GITEA (repository-cleanup-service.ts): the flag was documented as "Delete repositories from Gitea" with a false default 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 set CLEANUP_DELETE_FROM_GITEA=true to keep it.

Verification

  • Live before/after with a registered IdP on a private IP: POST /api/auth/sign-in/sso returns 400 discovery_private_host on v3.27.1 and 200 with the authorization URL on this branch.
  • Browser test: a failing SSO sign-in now shows the server's error message as a toast.
  • Live cleanup test against an unreachable Gitea URL: delete with 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 repo failed, as before).
  • New unit tests for both pure decision functions (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.

## 📋 Pull Request Information **Original PR:** https://github.com/RayLabsHQ/gitea-mirror/pull/367 **Author:** [@arunavo4](https://github.com/arunavo4) **Created:** 8/21/2026 **Status:** ✅ Merged **Merged:** 8/21/2026 **Merged by:** [@arunavo4](https://github.com/arunavo4) **Base:** `main` ← **Head:** `fix/sso-trusted-origins-cleanup-flags` --- ### 📝 Commits (1) - [`50acc48`](https://github.com/RayLabsHQ/gitea-mirror/commit/50acc48fb3a904d22fe537310be51166136a3dd5) fix(auth): trust registered SSO provider origins and honor deleteFromGitea (#366) ### 📊 Changes **7 files changed** (+305 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 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 the `catch` never fired. The button flipped back from "Redirecting..." with no toast and nothing in the server log at default level. ## Changes - **Auto-trust registered SSO provider origins** (`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 the `domainVerified` flag we set at registration), so this is the sanctioned escape hatch applied automatically. `BETTER_AUTH_TRUSTED_ORIGINS` still works and is still needed when *registering* a new internal IdP (documented in SSO-OIDC-SETUP.md). - **Surface SSO sign-in errors** (`LoginForm.tsx`): server-side rejections now show as an error toast instead of failing silently. - **Honor `deleteFromGitea` / `CLEANUP_DELETE_FROM_GITEA`** (`repository-cleanup-service.ts`): the flag was documented as "Delete repositories from Gitea" with a `false` default 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 set `CLEANUP_DELETE_FROM_GITEA=true` to keep it. ## Verification - Live before/after with a registered IdP on a private IP: `POST /api/auth/sign-in/sso` returns **400 `discovery_private_host`** on v3.27.1 and **200 with the authorization URL** on this branch. - Browser test: a failing SSO sign-in now shows the server's error message as a toast. - Live cleanup test against an unreachable Gitea URL: `delete` with 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 repo `failed`, as before). - New unit tests for both pure decision functions (`extractSsoProviderOrigins`, `planOrphanedRepoAction`); full suite 503 pass / 0 fail. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-08-26 01:03:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea-mirror#8626