From 45f4a87e85ebfecef3a3ea9713576d02b24fea1e Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 25 Aug 2026 21:50:27 +0200 Subject: [PATCH] fix: bound extracted document metadata by the upload size limit by default (#29025) "RAG_METADATA_MAX_VALUE_CHARS" ships unset, and unset means no bound at all, so the limit only protects the deployments that already knew to configure it. A small Office document is a zip archive, and one crafted to expand enormously during extraction can turn a few hundred kilobytes into gigabytes of metadata held in memory; uploading it a handful of times is enough to exhaust a server and take Open WebUI down with it. When no explicit limit is configured, the bound now follows "RAG_FILE_MAX_SIZE" instead of being absent, on the reasoning that a document cannot legitimately carry more metadata than the file itself is allowed to be. That keeps the number from being an arbitrary guess: it is whatever the administrator already decided an upload may weigh. Setting "RAG_METADATA_MAX_VALUE_CHARS" explicitly still wins, and a deployment that leaves both unset is unchanged, which is the same posture the upload limit itself takes. "RAG_FILE_MAX_SIZE" is in MB and is treated as unset when it is zero, matching how the document loader already reads it. --- backend/open_webui/env.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 02b822196b..b17df7340a 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -823,8 +823,13 @@ BYPASS_RETRIEVAL_ACCESS_CONTROL = os.getenv('BYPASS_RETRIEVAL_ACCESS_CONTROL', ' # denied — closing the legacy unscoped namespace. ENABLE_RETRIEVAL_UNSCOPED_COLLECTIONS = os.getenv('ENABLE_RETRIEVAL_UNSCOPED_COLLECTIONS', 'False').lower() == 'true' +# Falls back to the upload size limit, because a document cannot legitimately carry more metadata +# than the file itself is allowed to be. Left unbounded, a small archive that expands enormously +# during extraction can exhaust memory. RAG_FILE_MAX_SIZE is in MB. RAG_METADATA_MAX_VALUE_CHARS = ( - int(os.getenv('RAG_METADATA_MAX_VALUE_CHARS')) if os.getenv('RAG_METADATA_MAX_VALUE_CHARS') else None + int(os.getenv('RAG_METADATA_MAX_VALUE_CHARS')) + if os.getenv('RAG_METADATA_MAX_VALUE_CHARS') + else ((int(os.getenv('RAG_FILE_MAX_SIZE', '0')) or 0) * 1024 * 1024 or None) ) MINERU_MAX_MARKDOWN_BYTES = (