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
9 changes: 7 additions & 2 deletions web/download.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
die("Missing required parameters");
}

// This prevents command injection and directory traversal attacks.
if (!preg_match('/^[a-zA-Z0-9_-]+$/', $agent_id)) {
die("Invalid agent id format");
}

// Construct full path
$base_path = "/rtMount/$agent_id";
$full_path = "$base_path/$path";
$full_path = realpath($base_path . '/' . $path);

// Security checks
if (!str_starts_with(realpath($full_path), realpath($base_path))) {
Expand Down Expand Up @@ -38,4 +43,4 @@
echo fread($handle, 8192);
flush();
}
fclose($handle);
fclose($handle);