Merge pull request #693 from christianlouis/fix-rclone-command-injection-16912117938106238295
🔒 fix(tasks): prevent command injection in rclone commands
This commit is contained in:
@@ -55,12 +55,12 @@ def upload_with_rclone(self, file_path: str, destination: str):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Ensure the remote path exists (create folders if needed)
|
# Ensure the remote path exists (create folders if needed)
|
||||||
mkdir_cmd = ["rclone", "mkdir", "--config", rclone_config_path, destination]
|
mkdir_cmd = ["rclone", "mkdir", "--config", rclone_config_path, "--", destination]
|
||||||
|
|
||||||
subprocess.run(mkdir_cmd, check=True, capture_output=True) # noqa: S603
|
subprocess.run(mkdir_cmd, check=True, capture_output=True) # noqa: S603
|
||||||
|
|
||||||
# Construct the upload command
|
# Construct the upload command
|
||||||
upload_cmd = ["rclone", "copy", "--config", rclone_config_path, file_path, destination, "--progress"]
|
upload_cmd = ["rclone", "copy", "--config", rclone_config_path, "--progress", "--", file_path, destination]
|
||||||
|
|
||||||
log_task_progress(task_id, "rclone_upload", "in_progress", f"Executing rclone copy to {destination}")
|
log_task_progress(task_id, "rclone_upload", "in_progress", f"Executing rclone copy to {destination}")
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ def upload_with_rclone(self, file_path: str, destination: str):
|
|||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
# Try to get a public link if possible
|
# Try to get a public link if possible
|
||||||
try:
|
try:
|
||||||
link_cmd = ["rclone", "link", "--config", rclone_config_path, f"{destination}/{filename}"]
|
link_cmd = ["rclone", "link", "--config", rclone_config_path, "--", f"{destination}/{filename}"]
|
||||||
link_result = subprocess.run(link_cmd, capture_output=True, text=True, check=False) # noqa: S603
|
link_result = subprocess.run(link_cmd, capture_output=True, text=True, check=False) # noqa: S603
|
||||||
public_url = link_result.stdout.strip() if link_result.returncode == 0 else None
|
public_url = link_result.stdout.strip() if link_result.returncode == 0 else None
|
||||||
except (subprocess.SubprocessError, OSError) as e:
|
except (subprocess.SubprocessError, OSError) as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user