mirror of
https://github.com/ParisNeo/lollms.git
synced 2025-01-21 03:55:01 +00:00
Update security.py
This commit is contained in:
parent
f8720878dd
commit
d577405d6a
@ -123,14 +123,15 @@ def sanitize_path(path: str, allow_absolute_path: bool = False, error_text="Abso
|
|||||||
-----
|
-----
|
||||||
This function checks for patterns like "....", multiple forward slashes, and command injection attempts like $(whoami). It also checks for unauthorized punctuation characters, excluding the dot (.) character.
|
This function checks for patterns like "....", multiple forward slashes, and command injection attempts like $(whoami). It also checks for unauthorized punctuation characters, excluding the dot (.) character.
|
||||||
"""
|
"""
|
||||||
|
if path is None:
|
||||||
|
return path
|
||||||
|
|
||||||
if not allow_absolute_path and path.strip().startswith("/"):
|
if not allow_absolute_path and path.strip().startswith("/"):
|
||||||
raise HTTPException(status_code=400, detail=exception_text)
|
raise HTTPException(status_code=400, detail=exception_text)
|
||||||
|
|
||||||
# Normalize path to use forward slashes
|
# Normalize path to use forward slashes
|
||||||
path = path.replace('\\', '/')
|
path = path.replace('\\', '/')
|
||||||
|
|
||||||
if path is None:
|
|
||||||
return path
|
|
||||||
|
|
||||||
# Regular expression to detect patterns like "....", multiple forward slashes, and command injection attempts like $(whoami)
|
# Regular expression to detect patterns like "....", multiple forward slashes, and command injection attempts like $(whoami)
|
||||||
suspicious_patterns = re.compile(r'(\.\.+)|(/+/)|(\$\(.*\))')
|
suspicious_patterns = re.compile(r'(\.\.+)|(/+/)|(\$\(.*\))')
|
||||||
@ -237,4 +238,4 @@ if __name__=="__main__":
|
|||||||
sanitize_path_from_endpoint("cat/main")
|
sanitize_path_from_endpoint("cat/main")
|
||||||
print("Main passed")
|
print("Main passed")
|
||||||
sanitize_path_from_endpoint(".../user")
|
sanitize_path_from_endpoint(".../user")
|
||||||
print("hi")
|
print("hi")
|
||||||
|
Loading…
Reference in New Issue
Block a user