@@ -45,6 +45,44 @@ def api_only():
45
45
)
46
46
47
47
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
+
48
86
def webui ():
49
87
from modules .shared_cmd_options import cmd_opts
50
88
@@ -53,6 +91,8 @@ def webui():
53
91
54
92
from modules import shared , ui_tempdir , script_callbacks , ui , progress , ui_extra_networks
55
93
94
+ warning_if_invalid_install_dir ()
95
+
56
96
while 1 :
57
97
if shared .opts .clean_temp_dir_at_start :
58
98
ui_tempdir .cleanup_tmpdr ()
0 commit comments