Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(auth): catch joserfc errors only, drop the authlib.jose import

Pouzore27019b78516
diff --git a/backend/app/api/routes/auth.py b/backend/app/api/routes/auth.py
index 727d5d5..669a7fc 100644
--- a/backend/app/api/routes/auth.py
+++ b/backend/app/api/routes/auth.py
@@ -4,7 +4,6 @@ from collections.abc import Mapping
from typing import cast
from authlib.integrations.base_client.errors import OAuthError
-from authlib.jose.errors import JoseError as _AuthlibJoseError # authlib 1.7.x still raises this; drop after 2.0
from fastapi import APIRouter, Depends, HTTPException, Request, Response, status
from joserfc.errors import JoseError
from pydantic import BaseModel
@@ -88,7 +87,7 @@ async def oidc_callback(request: Request) -> Response:
client = get_oidc_client()
try:
token = await client.authorize_access_token(request)
- except (OAuthError, JoseError, _AuthlibJoseError) as exc:
+ except (OAuthError, JoseError) as exc:
logger.warning("OIDC callback rejected: %s", exc.error)
request.session.clear()
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="OIDC authentication failed") from None
diff --git a/backend/requirements.txt b/backend/requirements.txt
index 25187c5..fcba667 100644
--- a/backend/requirements.txt
+++ b/backend/requirements.txt
@@ -9,7 +9,7 @@ pydantic-settings==2.5.2
PyJWT==2.13.0
bcrypt==4.2.1
authlib==1.7.2
-joserfc>=1.6.0
+joserfc==1.7.4
itsdangerous==2.2.0
python-multipart==0.0.31
apscheduler==3.10.4
diff --git a/backend/tests/test_auth.py b/backend/tests/test_auth.py
index bd0e8ad..3e45a08 100644
--- a/backend/tests/test_auth.py
+++ b/backend/tests/test_auth.py
@@ -4,9 +4,9 @@ from urllib.parse import parse_qs, urlparse
import pytest
from authlib.integrations.base_client.errors import OAuthError
-from authlib.jose.errors import ExpiredTokenError, JoseError
from fastapi import WebSocketDisconnect
from httpx import AsyncClient
+from joserfc.errors import BadSignatureError, ExpiredTokenError, JoseError
from starlette.responses import RedirectResponse
from starlette.testclient import TestClient
@@ -326,7 +326,7 @@ async def test_oidc_callback_hides_protocol_error_details(client: AsyncClient, o
async def test_oidc_callback_hides_claim_validation_error_details(client: AsyncClient, oidc_settings):
- fake_client = FakeOIDCClient(error=ExpiredTokenError())
+ fake_client = FakeOIDCClient(error=ExpiredTokenError("exp"))
with patch("app.api.routes.auth.get_oidc_client", return_value=fake_client):
res = await client.get("/api/v1/auth/oidc/callback")
assert res.status_code == 401
@@ -334,6 +334,16 @@ async def test_oidc_callback_hides_claim_validation_error_details(client: AsyncC
assert "expired" not in res.text.lower()
+async def test_oidc_callback_rejects_bad_id_token_signature(client: AsyncClient, oidc_settings):
+ # authlib 1.7 validates ID tokens with joserfc, whose errors are unrelated to
+ # the deprecated authlib.jose ones — they must still end in a clean 401.
+ fake_client = FakeOIDCClient(error=BadSignatureError())
+ with patch("app.api.routes.auth.get_oidc_client", return_value=fake_client):
+ res = await client.get("/api/v1/auth/oidc/callback")
+ assert res.status_code == 401
+ assert res.json() == {"detail": "OIDC authentication failed"}
+
+
async def test_oidc_session_token_cannot_be_used_as_bearer(client: AsyncClient, oidc_settings):
from app.core.security import create_oidc_session_token