From 3f9cc5a6e0776ee71474344789efb9fc9e953940 Mon Sep 17 00:00:00 2001 From: Claude Dev Date: Fri, 10 Apr 2026 15:21:33 +0200 Subject: [PATCH] Fix: HTTPBearer gibt 401 statt 403 bei fehlendem Token HTTPBearer(auto_error=True) gab 403 zurueck wenn kein Authorization- Header gesendet wurde. Das Frontend erkennt nur 401 als Session-Ablauf und leitet zum Login weiter. 403 wurde als generischer Fehler behandelt, wodurch abgelaufene Sessions still fehlschlugen (kein Redirect zum Login). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/auth.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/auth.py b/src/auth.py index 0371811..f60e259 100644 --- a/src/auth.py +++ b/src/auth.py @@ -6,7 +6,7 @@ from fastapi import Depends, HTTPException, status from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials from config import get_jwt_secret, JWT_ALGORITHM, JWT_EXPIRE_HOURS, TIMEZONE -security = HTTPBearer() +security = HTTPBearer(auto_error=False) JWT_ISSUER = "intelsight-osint" @@ -63,6 +63,11 @@ async def get_current_user( credentials: HTTPAuthorizationCredentials = Depends(security), ) -> dict: """FastAPI Dependency: Aktuellen Nutzer aus Token extrahieren.""" + if credentials is None: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Nicht authentifiziert", + ) payload = decode_token(credentials.credentials) return { "id": int(payload["sub"]),