Skip to content
Open
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
14 changes: 11 additions & 3 deletions bin/adfmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,11 +1701,19 @@
path = socket.getfqdn() and path # noop; keep lint calm
path = bytes(path, "utf-8").decode("utf-8")
# we already encoded in JS; parse_qs decodes %xx automatically
p = Path(path)
base_dir = Path(self.cfg["dir"]).resolve()
raw_path = Path(path)
if not raw_path.is_absolute():
p = (base_dir / raw_path).resolve(strict=False)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
else:
p = raw_path.resolve(strict=False)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
try:
# Ensure the resolved path is within the configured image directory
p.relative_to(base_dir)
except ValueError:
return self._json({"error": "path must be inside image directory"}, code=400)
if not p.exists():
return self._json({"error": f"not found: {p}"}, code=400)
if not path_within_dir(Path(self.cfg["dir"]), p):
return self._json({"error": "path must be inside image directory"}, code=400)
status = get_status(self.cfg["host"], self.cfg["port"])
preferred = int(unit_raw) if unit_raw.isdigit() else None
unit = pick_unit(preferred, status)
Expand Down