Skip to content

Commit e568ea5

Browse files
committed
warning WebUI is installed under a dot directory
1 parent 984b952 commit e568ea5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

webui.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,42 @@ 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 pathlib import Path
63+
64+
def abspath(path):
65+
"""modified from Gradio 3.41.2 gradio.utils.abspath()"""
66+
if path.is_absolute():
67+
return path
68+
is_symlink = path.is_symlink() or any(parent.is_symlink() for parent in path.parents)
69+
if is_symlink or path == path.resolve():
70+
return Path.cwd() / path
71+
else:
72+
return path.resolve()
73+
webui_root = Path(__file__).parent
74+
if any(part.startswith(".") for part in abspath(webui_root).parts):
75+
print(f'''{"!"*25} Warning {"!"*25}
76+
WebUI is installed in a directory that has a leading dot (.) in one of its parent directories.
77+
This will prevent WebUI from functioning properly.
78+
Please move the installation to a different directory.
79+
Current path: "{webui_root}"
80+
For more information see: https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13292
81+
{"!"*25} Warning {"!"*25}''')
82+
83+
4884
def webui():
4985
from modules.shared_cmd_options import cmd_opts
5086

@@ -53,6 +89,8 @@ def webui():
5389

5490
from modules import shared, ui_tempdir, script_callbacks, ui, progress, ui_extra_networks
5591

92+
warning_if_invalid_install_dir()
93+
5694
while 1:
5795
if shared.opts.clean_temp_dir_at_start:
5896
ui_tempdir.cleanup_tmpdr()

0 commit comments

Comments
 (0)