Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(auth): strip trailing slash from OIDC issuer before discovery (#18530)

Christian Uhl89d35d1b1714
diff --git a/api/apps/auth/oidc.py b/api/apps/auth/oidc.py
index 2f0808551d..4b86c7f694 100644
--- a/api/apps/auth/oidc.py
+++ b/api/apps/auth/oidc.py
@@ -100,9 +100,12 @@ class OIDCClient(OAuthClient):
def _load_oidc_metadata(issuer):
"""
Load OIDC metadata from `/.well-known/openid-configuration`.
+
+ A configured issuer may carry a trailing slash, which would produce a
+ double slash in the discovery URL and a 404 on most providers.
"""
try:
- metadata_url = f"{issuer}/.well-known/openid-configuration"
+ metadata_url = f"{issuer.rstrip('/')}/.well-known/openid-configuration"
response = sync_request("GET", metadata_url, timeout=7)
response.raise_for_status()
return response.json()
diff --git a/test/testcases/test_web_api/test_auth_app/test_oidc_client_unit.py b/test/testcases/test_web_api/test_auth_app/test_oidc_client_unit.py
index cd6def73de..de45a0b7f3 100644
--- a/test/testcases/test_web_api/test_auth_app/test_oidc_client_unit.py
+++ b/test/testcases/test_web_api/test_auth_app/test_oidc_client_unit.py
@@ -201,6 +201,21 @@ def test_load_oidc_metadata_success_and_wraps_failure(monkeypatch):
assert str(exc_info.value) == "Failed to fetch OIDC metadata: metadata boom"
+def test_load_oidc_metadata_strips_trailing_slash_from_issuer(monkeypatch):
+ _, oidc_module = _load_auth_modules(monkeypatch)
+
+ calls = {}
+
+ def _ok_sync_request(method, url, timeout):
+ calls["url"] = url
+ return _FakeResponse(_metadata("https://issuer.example"))
+
+ monkeypatch.setattr(oidc_module, "sync_request", _ok_sync_request)
+ oidc_module.OIDCClient._load_oidc_metadata("https://issuer.example/")
+ assert calls["url"] == "https://issuer.example/.well-known/openid-configuration"
+
+
@pytest.mark.p2
def test_parse_id_token_success_and_error(monkeypatch):
_, oidc_module = _load_auth_modules(monkeypatch)