From a7e51207c01769eae2b1bfd88f9bd138832cc99d Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:19:24 +0100 Subject: [PATCH] fix: audit log records API keys and tokens in plain text (#33746) With request auditing turned on, only fields whose name ends in "password" were masked, so API keys and tokens saved in the admin settings (OpenAI and Ollama connections, Jupyter, web search and others) were written to the audit log as they were. A secret cut off by the body size limit also had its beginning logged. Fields whose name ends in password, secret, token, key or authorization are now masked, including lists of keys and values cut off by the size limit. Co-authored-by: xfscott <229475069+xfscott@users.noreply.github.com> --- backend/open_webui/utils/audit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/utils/audit.py b/backend/open_webui/utils/audit.py index 7f492822e8..edd0cbffe4 100644 --- a/backend/open_webui/utils/audit.py +++ b/backend/open_webui/utils/audit.py @@ -141,11 +141,11 @@ def log_model_usage(request: Request, user: UserModel, model_id: str, usage: Opt logger.error('Failed to log model usage: {}', e) -def redact_passwords(body: str) -> str: - if 'password' not in body.lower(): - return body +def redact_secrets(body: str) -> str: + # Secrets cut off by the size limit have no closing quote. + quoted = r'"(?:[^"\\]|\\.)*\\?(?:"|$)' return re.sub( - r'"(\w*password)"\s*:\s*"(?:[^"\\]|\\.)*"', + rf'"(\w*(?:password|secret|token|key|authorization)s?)"\s*:\s*(?:{quoted}|\[(?:{quoted}|[^\]"])*(?:\]|$))', r'"\1": "********"', body, flags=re.IGNORECASE, @@ -330,8 +330,8 @@ class AuditLoggingMiddleware: response_body = context.response_body.decode('utf-8', errors='replace') # Redact sensitive information - request_body = redact_passwords(request_body) - response_body = redact_passwords(response_body) + request_body = redact_secrets(request_body) + response_body = redact_secrets(response_body) entry = AuditLogEntry( id=request.state.audit_request_id,