Skip to content

Commit 91de919

Browse files
authored
Warn if WebUI is installed under a dot directory (AUTOMATIC1111#16584)
1 parent aa52408 commit 91de919

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

webui.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,44 @@ def api_only():
4545
)
4646

4747

48+
def warning_if_invalid_install_dir():
49+
"""
50+
Shows a warning if the webui is installed under a path that contains a leading dot in any of its parent directories.
51+
52+
Gradio '/file=' route will block access to files that have a leading dot in the path segments.
53+
We use this route to serve files such as JavaScript and CSS to the webpage,
54+
if those files are blocked, the webpage will not function properly.
55+
See https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292
56+
57+
This is a security feature was added to Gradio 3.32.0 and is removed in later versions,
58+
this function replicates Gradio file access blocking logic.
59+
60+
This check should be removed when it's no longer applicable.
61+
"""
62+
from packaging.version import parse
63+
from pathlib import Path
64+
import gradio
65+
66+
if parse('3.32.0') <= parse(gradio.__version__) < parse('4'):
67+
68+
def abspath(path):
69+
"""modified from Gradio 3.41.2 gradio.utils.abspath()"""
70+
if path.is_absolute():
71+
return path
72+
is_symlink = path.is_symlink() or any(parent.is_symlink() for parent in path.parents)
73+
return Path.cwd() / path if (is_symlink or path == path.resolve()) else path.resolve()
74+
75+
webui_root = Path(__file__).parent
76+
if any(part.startswith(".") for part in abspath(webui_root).parts):
77+
print(f'''{"!"*25} Warning {"!"*25}
78+
WebUI is installed in a directory that has a leading dot (.) in one of its parent directories.
79+
This will prevent WebUI from functioning properly.
80+
Please move the installation to a different directory.
81+
Current path: "{webui_root}"
82+
For more information see: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292
83+
{"!"*25} Warning {"!"*25}''')
84+
85+
4886
def webui():
4987
from modules.shared_cmd_options import cmd_opts
5088

@@ -53,6 +91,8 @@ def webui():
5391

5492
from modules import shared, ui_tempdir, script_callbacks, ui, progress, ui_extra_networks
5593

94+
warning_if_invalid_install_dir()
95+
5696
while 1:
5797
if shared.opts.clean_temp_dir_at_start:
5898
ui_tempdir.cleanup_tmpdr()

0 commit comments

Comments
 (0)