fix: resolve this instance's own file URLs in edit_image regardless of the URL host (#29691)

The native edit_image tool fails with "400: [ERROR: Error loading image]" whenever the model hands it an absolute URL for an image Open WebUI already stores. Such a URL is treated as local only when its host string matches the incoming request's host exactly, so a default-port form, a container name or any host the model composed itself falls through to an outbound HTTP fetch instead. That fetch asks /api/v1/files/{id}/content without a session, gets a 401, and the user sees the generic 400.

Match the file URL on its path and let the existing local branch resolve it. Fetching that endpoint over the network can never succeed for a local or a remote instance, because it requires an authenticated user, so the host comparison only decided which way the request failed. Access control is unchanged: the local branch still goes through get_file_content_by_id, which enforces owner, admin or shared access.

Fixes #29220
This commit is contained in:
Classic298
2026-09-21 08:32:38 -04:00
committed by GitHub
parent d9ea46f92d
commit 7fa8673296
+2 -5
View File
@@ -920,11 +920,8 @@ async def image_edits(
if data.startswith('http://') or data.startswith('https://'):
parsed = urlparse(data)
if (
parsed.netloc == urlparse(str(request.base_url)).netloc
and parsed.path.startswith('/api/v1/files/')
and '/content' in parsed.path
):
# Fetching /api/v1/files/{id}/content over the network would be unauthenticated.
if parsed.path.startswith('/api/v1/files/') and '/content' in parsed.path:
return await load_url_image(parsed.path)
# Validate URL to prevent SSRF attacks against local/private networks.