Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions scripts/gradio_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,25 +1537,20 @@ def list_sessions():
def _safe_session_path(filename):
if not filename or not isinstance(filename, str):
return None
if os.path.isabs(filename):
# Only allow plain safe filenames with approved extensions.
if not re.fullmatch(r"[A-Za-z0-9_.-]+\.(json|md|txt)", filename):
return None
# Only allow plain file names from the session list; no directory components.
if os.path.basename(filename) != filename:
return None
if not filename.endswith((".json", ".md", ".txt")):
return None
base = os.path.realpath(CONV_DIR)
candidate = os.path.realpath(os.path.join(base, filename))
base = Path(CONV_DIR).resolve()
candidate = (base / filename).resolve()
Comment on lines +1543 to +1544
try:
if os.path.commonpath([base, candidate]) != base:
return None
candidate.relative_to(base)
except ValueError:
return None
return candidate
return str(candidate)

def load_session(filename):
path = _safe_session_path(filename)
if not path:
if not path or not os.path.isfile(path):
return [], []
try:
with open(path, encoding="utf-8") as f:
Expand Down
Loading