From 2ef6c76f5126ccdef5d1c814004920941275f45d Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 23 Jul 2026 22:52:23 -0400 Subject: [PATCH] refac --- backend/open_webui/env.py | 16 ++++++++++------ backend/open_webui/utils/audit.py | 8 ++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index f20cb2df53..6c41313499 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -1102,15 +1102,19 @@ except ValueError: MAX_BODY_LOG_SIZE = 2048 # Comma separated list for urls to exclude from audit -AUDIT_EXCLUDED_PATHS = os.getenv('AUDIT_EXCLUDED_PATHS', '/chats,/chat,/folders').split(',') -AUDIT_EXCLUDED_PATHS = [path.strip() for path in AUDIT_EXCLUDED_PATHS] -AUDIT_EXCLUDED_PATHS = [path.lstrip('/') for path in AUDIT_EXCLUDED_PATHS] +AUDIT_EXCLUDED_PATHS = [ + path + for path in ( + path.strip().lstrip('/') for path in os.getenv('AUDIT_EXCLUDED_PATHS', '/chats,/chat,/folders').split(',') + ) + if path +] # Comma separated list of urls to include in audit (whitelist mode) # When set, only these paths are audited and AUDIT_EXCLUDED_PATHS is ignored -AUDIT_INCLUDED_PATHS = os.getenv('AUDIT_INCLUDED_PATHS', '').split(',') -AUDIT_INCLUDED_PATHS = [path.strip() for path in AUDIT_INCLUDED_PATHS] -AUDIT_INCLUDED_PATHS = [path.lstrip('/') for path in AUDIT_INCLUDED_PATHS if path] +AUDIT_INCLUDED_PATHS = [ + path for path in (path.strip().lstrip('/') for path in os.getenv('AUDIT_INCLUDED_PATHS', '').split(',')) if path +] # When enabled, GET requests are also audited (disabled by default to avoid log noise) ENABLE_AUDIT_GET_REQUESTS = os.getenv('ENABLE_AUDIT_GET_REQUESTS', 'False').lower() == 'true' diff --git a/backend/open_webui/utils/audit.py b/backend/open_webui/utils/audit.py index d2802613ea..890960bc58 100644 --- a/backend/open_webui/utils/audit.py +++ b/backend/open_webui/utils/audit.py @@ -132,8 +132,12 @@ class AuditLoggingMiddleware: ) -> None: self.app = app self.audit_logger = AuditLogger(logger) - self.excluded_paths = excluded_paths or [] - self.included_paths = included_paths or [] + + def normalize_paths(paths: Optional[list[str]]) -> list[str]: + return [path for path in (path.strip().lstrip('/') for path in paths or []) if path] + + self.excluded_paths = normalize_paths(excluded_paths) + self.included_paths = normalize_paths(included_paths) self.max_body_size = max_body_size self.audited_methods = set(self.DEFAULT_AUDITED_METHODS) if audit_get_requests: