Skip to content

Commit e3ba698

Browse files
committed
refac
1 parent 741b64e commit e3ba698

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

backend/open_webui/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,15 @@ def reachable(host: str, port: int) -> bool:
10241024
RAG_OLLAMA_API_KEY = os.getenv('RAG_OLLAMA_API_KEY', '')
10251025

10261026

1027-
ENABLE_RAG_LOCAL_WEB_FETCH = os.getenv('ENABLE_RAG_LOCAL_WEB_FETCH', 'False').lower() == 'true'
1027+
ENABLE_LOCAL_WEB_FETCH = (
1028+
os.getenv(
1029+
'ENABLE_LOCAL_WEB_FETCH',
1030+
os.getenv('ENABLE_RAG_LOCAL_WEB_FETCH', 'False'),
1031+
).lower()
1032+
== 'true'
1033+
)
1034+
# Deprecated compatibility alias; use ENABLE_LOCAL_WEB_FETCH for new deployments.
1035+
ENABLE_RAG_LOCAL_WEB_FETCH = ENABLE_LOCAL_WEB_FETCH
10281036

10291037

10301038
DEFAULT_WEB_FETCH_FILTER_LIST = [

backend/open_webui/retrieval/web/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from langchain_community.document_loaders.base import BaseLoader
3131
from langchain_core.documents import Document
3232
from open_webui.config import (
33-
ENABLE_RAG_LOCAL_WEB_FETCH,
33+
ENABLE_LOCAL_WEB_FETCH,
3434
EXTERNAL_WEB_LOADER_API_KEY,
3535
EXTERNAL_WEB_LOADER_URL,
3636
FIRECRAWL_API_BASE_URL,
@@ -98,8 +98,8 @@ def validate_url(url: Union[str, Sequence[str]]):
9898
log.warning(f'URL blocked by filter list: {url}')
9999
raise ValueError(ERROR_MESSAGES.INVALID_URL)
100100

101-
if not ENABLE_RAG_LOCAL_WEB_FETCH:
102-
# Local web fetch is disabled, filter out any URLs that resolve to private IP addresses
101+
if not ENABLE_LOCAL_WEB_FETCH:
102+
# Local web fetch is disabled, filter out URLs that resolve to non-global IP addresses.
103103
parsed_url = urllib.parse.urlparse(url)
104104
# Get IPv4 and IPv6 addresses
105105
ipv4_addresses, ipv6_addresses = resolve_hostname(parsed_url.hostname)
@@ -140,7 +140,7 @@ def _ssrf_safe_new_conn(self):
140140
infos = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
141141
if not infos:
142142
raise OSError(f'getaddrinfo for {host!r} returned empty list')
143-
if not ENABLE_RAG_LOCAL_WEB_FETCH:
143+
if not ENABLE_LOCAL_WEB_FETCH:
144144
for _, _, _, _, sa in infos:
145145
if not ipaddress.ip_address(sa[0]).is_global:
146146
raise ValueError(ERROR_MESSAGES.INVALID_URL)
@@ -196,7 +196,7 @@ class _SSRFSafeResolver(aiohttp.resolver.DefaultResolver):
196196

197197
async def resolve(self, host, port=0, family=socket.AF_INET):
198198
results = await super().resolve(host, port, family)
199-
if not ENABLE_RAG_LOCAL_WEB_FETCH:
199+
if not ENABLE_LOCAL_WEB_FETCH:
200200
for entry in results:
201201
if not ipaddress.ip_address(entry['host']).is_global:
202202
raise ValueError(ERROR_MESSAGES.INVALID_URL)

backend/open_webui/routers/images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ async def get_image_data(data: str, headers=None, trusted_base_url: str | None =
428428
# ComfyUI on a private network), skip SSRF validation only when
429429
# the URL shares the exact same origin (scheme + host + port)
430430
# as the admin-configured base. This avoids both the global
431-
# ENABLE_RAG_LOCAL_WEB_FETCH hammer and a blanket trust flag
431+
# ENABLE_LOCAL_WEB_FETCH hammer and a blanket trust flag
432432
# that would follow arbitrary redirects.
433433
if trusted_base_url and _is_same_origin(data, trusted_base_url):
434434
log.debug(f'Skipping URL validation for trusted backend: {data}')

0 commit comments

Comments
 (0)