From 79b03851e27785bedbfda590519546d8e7ba5e39 Mon Sep 17 00:00:00 2001 From: Kev365 <48181394+kev365@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:44:15 -0600 Subject: [PATCH] Refuse every OIDC login of a disabled user, not only the first oidc_callback answered 401 "User account disabled" only in the branch that creates the user on a first login. A later login of the same, still disabled user, or of a user an admin had disabled, fell through and got a yeti_session cookie. The cookie reached /auth/me only, since the routers require an enabled user. The callback now checks enabled before issuing the session and answers the same 401. Co-Authored-By: Claude Fable 5.2 --- core/web/apiv2/auth.py | 7 +++++++ tests/apiv2/auth.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/core/web/apiv2/auth.py b/core/web/apiv2/auth.py index 5bb1c4e27..ab9b96b45 100644 --- a/core/web/apiv2/auth.py +++ b/core/web/apiv2/auth.py @@ -289,6 +289,13 @@ async def oidc_callback(request: Request) -> RedirectResponse: detail="User account disabled. Please contact your server admin.", ) + # Also covers every login after the first, until an admin enables the user. + if not db_user.enabled: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="User account disabled. Please contact your server admin.", + ) + access_token = create_access_token( data={"sub": db_user.username, "enabled": db_user.enabled}, expires_delta=BROWSER_TOKEN_EXPIRE_DELTA, diff --git a/tests/apiv2/auth.py b/tests/apiv2/auth.py index d2db6ddb4..af35173da 100644 --- a/tests/apiv2/auth.py +++ b/tests/apiv2/auth.py @@ -437,6 +437,20 @@ def test_unverified_email(self) -> None: response.json()["detail"], ) + def test_disabled_user_gets_no_session(self) -> None: + """A first login creates a disabled user. Until an admin enables it, + every later login is refused as well, with no session cookie.""" + for attempt in ("first", "second"): + with self.subTest(login=attempt): + response = self.browser_login({"email": "bob@example.com"}) + self.assertEqual(response.status_code, 401) + self.assertNotIn("set-cookie", response.headers) + self.assertEqual( + response.json()["detail"], + "User account disabled. Please contact your server admin.", + ) + self.assertFalse(UserSensitive.find(username="bob@example.com").enabled) + def test_unverified_email_creates_no_user(self) -> None: self.browser_login({"email": "mallory@example.com", "email_verified": False}) self.assertIsNone(UserSensitive.find(username="mallory@example.com"))