Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

fix: sanitize base_commit to prevent command injection (CWE-78) (#1325)

Yue (Knox) Liu3ff833d95797
diff --git a/sweagent/environment/repo.py b/sweagent/environment/repo.py
index d32d389f..1d52b04a 100644
--- a/sweagent/environment/repo.py
+++ b/sweagent/environment/repo.py
@@ -1,5 +1,6 @@
import asyncio
import os
+import shlex
from pathlib import Path
from typing import Any, Literal, Protocol
@@ -33,7 +34,7 @@ def _get_git_reset_commands(base_commit: str) -> list[str]:
"git status",
"git restore .",
"git reset --hard",
- f"git checkout {base_commit}",
+ f"git checkout {shlex.quote(base_commit)}",
"git clean -fdq",
]
@@ -172,8 +173,8 @@ class GithubRepoConfig(BaseModel):
f"mkdir /{self.repo_name}",
f"cd /{self.repo_name}",
"git init",
- f"git remote add origin {url}",
- f"git fetch --depth 1 origin {base_commit}",
+ f"git remote add origin {shlex.quote(url)}",
+ f"git fetch --depth 1 origin {shlex.quote(base_commit)}",
"git checkout FETCH_HEAD",
"cd ..",
)