mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-17 03:03:27 -06:00
fix: requests authenticated with the x-api-key header are missing from the audit log (#32443)
With audit logging on, requests that used an API key in the x-api-key header (what Anthropic SDKs send) worked but never showed up in the audit log, because the audit check only looked for a Bearer token or a session cookie. These requests are now logged with the user the key belongs to, and this also covers a custom header set through CUSTOM_API_KEY_HEADER. Failed attempts with a wrong key in that header now appear in the log without a user, just like a wrong Bearer key. A malformed Authorization header with no other credential is no longer logged, since it can never authenticate.
This commit is contained in:
@@ -264,8 +264,8 @@ class AuditLoggingMiddleware:
|
||||
return False # Do NOT skip logging for auth endpoints
|
||||
|
||||
# Skip logging if the request is not authenticated
|
||||
# Check both Authorization header (API keys) and token cookie (browser sessions)
|
||||
if not request.headers.get('authorization') and not request.cookies.get('token'):
|
||||
# Token is set by AppHTTPMiddleware from any accepted credential
|
||||
if not getattr(request.state, 'token', None):
|
||||
return True
|
||||
|
||||
# Whitelist mode: only log paths that match included_paths
|
||||
|
||||
Reference in New Issue
Block a user