mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
Prevent paths beginning with //
or \\
(#7544)
* prevent smb paths on windows * docstring * add changeset * add changeset --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
7cda6ce06d
commit
f84720cd76
5
.changeset/witty-walls-brake.md
Normal file
5
.changeset/witty-walls-brake.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
feat:Prevent paths beginning with `//` or `\\`
|
@ -581,9 +581,9 @@ def compare_passwords_securely(input_password: str, correct_password: str) -> bo
|
||||
|
||||
def starts_with_protocol(string: str) -> bool:
|
||||
"""This regex matches strings that start with a scheme (one or more characters not including colon, slash, or space)
|
||||
followed by ://
|
||||
followed by ://, or start with just // or \\ as they are interpreted as SMB paths on Windows.
|
||||
"""
|
||||
pattern = r"^[a-zA-Z][a-zA-Z0-9+\-.]*://"
|
||||
pattern = r"^(?:[a-zA-Z][a-zA-Z0-9+\-.]*://|//|\\\\)"
|
||||
return re.match(pattern, string) is not None
|
||||
|
||||
|
||||
|
@ -856,7 +856,8 @@ def safe_join(directory: str, path: str) -> str:
|
||||
|
||||
if path == "":
|
||||
raise HTTPException(400)
|
||||
|
||||
if route_utils.starts_with_protocol(path):
|
||||
raise HTTPException(403)
|
||||
filename = posixpath.normpath(path)
|
||||
fullpath = os.path.join(directory, filename)
|
||||
if (
|
||||
|
@ -953,6 +953,9 @@ def test_compare_passwords_securely():
|
||||
("localhost:7860", False),
|
||||
("localhost", False),
|
||||
("C:/Users/username", False),
|
||||
("//path", True),
|
||||
("\\\\path", True),
|
||||
("/usr/bin//test", False),
|
||||
],
|
||||
)
|
||||
def test_starts_with_protocol(string, expected):
|
||||
|
Loading…
Reference in New Issue
Block a user