From e568ea5a32b26af57f8003c29a6dec62ee57be88 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:07:15 +0900 Subject: [PATCH 1/2] warning WebUI is installed under a dot directory --- webui.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/webui.py b/webui.py index 2c417168aa6..b1e2faa48e9 100644 --- a/webui.py +++ b/webui.py @@ -45,6 +45,42 @@ def api_only(): ) +def warning_if_invalid_install_dir(): + """ + Shows a warning if the webui is installed under a path that contains a leading dot in any of its parent directories. + + Gradio '/file=' route will block access to files that have a leading dot in the path segments. + We use this route to serve files such as JavaScript and CSS to the webpage, + if those files are blocked, the webpage will not function properly. + See https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292 + + This is a security feature was added to Gradio 3.32.0 and is removed in later versions, + this function replicates Gradio file access blocking logic. + + This check should be removed when it's no longer applicable. + """ + from pathlib import Path + + def abspath(path): + """modified from Gradio 3.41.2 gradio.utils.abspath()""" + if path.is_absolute(): + return path + is_symlink = path.is_symlink() or any(parent.is_symlink() for parent in path.parents) + if is_symlink or path == path.resolve(): + return Path.cwd() / path + else: + return path.resolve() + webui_root = Path(__file__).parent + if any(part.startswith(".") for part in abspath(webui_root).parts): + print(f'''{"!"*25} Warning {"!"*25} +WebUI is installed in a directory that has a leading dot (.) in one of its parent directories. +This will prevent WebUI from functioning properly. +Please move the installation to a different directory. +Current path: "{webui_root}" +For more information see: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292 +{"!"*25} Warning {"!"*25}''') + + def webui(): from modules.shared_cmd_options import cmd_opts @@ -53,6 +89,8 @@ def webui(): from modules import shared, ui_tempdir, script_callbacks, ui, progress, ui_extra_networks + warning_if_invalid_install_dir() + while 1: if shared.opts.clean_temp_dir_at_start: ui_tempdir.cleanup_tmpdr() From 67961472a51353ddcfd0630a6f2f3ade7e3dbcd4 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:44:14 +0900 Subject: [PATCH 2/2] add version check --- webui.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/webui.py b/webui.py index b1e2faa48e9..421e3b8334f 100644 --- a/webui.py +++ b/webui.py @@ -59,20 +59,22 @@ def warning_if_invalid_install_dir(): This check should be removed when it's no longer applicable. """ + from packaging.version import parse from pathlib import Path + import gradio - def abspath(path): - """modified from Gradio 3.41.2 gradio.utils.abspath()""" - if path.is_absolute(): - return path - is_symlink = path.is_symlink() or any(parent.is_symlink() for parent in path.parents) - if is_symlink or path == path.resolve(): - return Path.cwd() / path - else: - return path.resolve() - webui_root = Path(__file__).parent - if any(part.startswith(".") for part in abspath(webui_root).parts): - print(f'''{"!"*25} Warning {"!"*25} + if parse('3.32.0') <= parse(gradio.__version__) < parse('4'): + + def abspath(path): + """modified from Gradio 3.41.2 gradio.utils.abspath()""" + if path.is_absolute(): + return path + is_symlink = path.is_symlink() or any(parent.is_symlink() for parent in path.parents) + return Path.cwd() / path if (is_symlink or path == path.resolve()) else path.resolve() + + webui_root = Path(__file__).parent + if any(part.startswith(".") for part in abspath(webui_root).parts): + print(f'''{"!"*25} Warning {"!"*25} WebUI is installed in a directory that has a leading dot (.) in one of its parent directories. This will prevent WebUI from functioning properly. Please move the installation to a different directory.