add logging for client host validation in authentication module

This commit is contained in:
2026-06-10 10:27:37 +02:00
parent 4c0c86b8ec
commit 7c19d80e20
+5
View File
@@ -1,5 +1,6 @@
import grp
import ipaddress
import logging
import os
import pwd
import re
@@ -8,6 +9,8 @@ from datetime import datetime, timedelta, UTC
from typing import List
import time
logger = logging.getLogger("aareDAQ")
import jwt
from fastapi import Depends, HTTPException, Request, status
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
@@ -101,7 +104,9 @@ def authenticate_from_proxy_header(request: Request) -> str:
only the Apache proxy running on the same host can supply it.
"""
client_host = request.client.host if request.client else None
logger.debug(f"[auth] /token client_host={client_host!r} request.client={request.client!r}")
if not _is_loopback(client_host):
logger.warning(f"[auth] Rejecting X-Remote-User: client_host {client_host!r} is not loopback")
raise AuthenticationException(
message="X-Remote-User header is only trusted from the localhost proxy",
status_code=401,