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.
|
||||
"""
|
||||
if path is None:
|
||||
return path
|
||||
|
||||
if not allow_absolute_path and path.strip().startswith("/"):
|
||||
raise HTTPException(status_code=400, detail=exception_text)
|
||||
|
||||
# Normalize path to use forward slashes
|
||||
path = path.replace('\\', '/')
|
||||
|
||||
if path is None:
|
||||
return path
|
||||
|
||||
# Regular expression to detect patterns like "....", multiple forward slashes, and command injection attempts like $(whoami)
|
||||
suspicious_patterns = re.compile(r'(\.\.+)|(/+/)|(\$\(.*\))')
|
||||
|
Loading…
Reference in New Issue
Block a user