ThemeHackers/CVE-2026-34038
GitHub: ThemeHackers/CVE-2026-34038
该项目是 Coolify 平台 CVE-2026-34038 命令注入漏洞的完整分析文档,涵盖漏洞原理、利用条件和修复方案。
Stars: 1 | Forks: 0
# CVE-2026-34038:Coolify 中的已认证远程命令注入
此仓库包含有关 **CVE-2026-34038** 的文档和分析,这是 Coolify 中的一个严重命令注入漏洞。
## 摘要
Coolify 中的已认证远程命令注入漏洞 (CWE-78) 允许拥有应用程序 **“write”** 权限的用户实现 **远程代码执行 (RCE)** 并通过部署日志**提取**敏感环境变量(例如,数据库凭据、API keys),即使构建环境隔离了 Docker socket。
* **漏洞类型:** CWE-78 (OS 命令注入)
* **严重程度:** Critical (CVSS 10.0)
* **向量:** `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H`
## 前置条件与限制
* **最低所需权限:** `write`(用于更新配置)和 `read:sensitive`(用于通过日志读取提取的数据)。
* **绕过:** 存在一种机制,允许没有显式 `deploy` 权限的 tokens 触发构建。
* **攻击面:** 由于不需要 administrative/root 权限,总体攻击面比最初估计的要大。
## 技术细节
### 1. `dockerfile_location` 注入
**文件:** `app/Jobs/ApplicationDeploymentJob.php`
输入缺乏适当的 shell 转义或输入验证,允许使用 `;`、`&&` 和 pipes 等 metacharacters 进行直接命令注入。
```
// Lines 2976-2978: Traditional build with args
$build_command = $this->wrap_build_command_with_env_export(
"docker build {$this->buildTarget} --network {$this->destination->network} -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->build_image_name {$this->workdir}"
);
// Lines 526: Also used in simple dockerfile deployment
executeInDocker($this->deployment_uuid, "echo '$dockerfile_base64' | base64 -d | tee {$this->workdir}{$this->dockerfile_location} > /dev/null"),
```
### 2. `pre_deployment_command` 执行
**文件:** `app/Jobs/ApplicationDeploymentJob.php`(第 3882-3909 行)
虽然执行了基本的转义,但该函数会自然地运行原生 shell 命令,这使得将数据直接转储到构建日志中成为可能。
```
private function run_pre_deployment_command()
{
if (empty($this->application->pre_deployment_command)) {
return;
}
// ...
$cmd = "sh -c '".str_replace("'", "'\\''", $this->application->pre_deployment_command)."'";
$exec = "docker exec {$containerName} {$cmd}";
$this->execute_remote_command(
[
'command' => $exec,
'hidden' => true,
],
);
}
```
## 修复建议
### 1. 净化 `dockerfile_location` 输入(在 `ApplicationDeploymentJob.php` 中):
使用严格的正则表达式验证输入,并对 shell 参数进行转义:
```
if ($this->application->dockerfile_location) {
if (!preg_match('/^[a-zA-Z0-9._\-\/]+$/', $this->application->dockerfile_location)) {
throw new \RuntimeException("Invalid dockerfile_location: contains forbidden characters");
}
if (str_contains($this->application->dockerfile_location, '..')) {
throw new \RuntimeException("Invalid dockerfile_location: path traversal detected");
}
$this->dockerfile_location = escapeshellarg($this->application->dockerfile_location);
}
```
### 2. API 级别验证(`bootstrap/helpers/api.php`):
```
'dockerfile_location' => [
'string',
'nullable',
'regex:/^[a-zA-Z0-9._\-\/]+$/',
'max:255'
],
```
### 3. 其他准则:
* 实施严格的 allowlists 以阻止 shell metacharacters。
* 修复部署权限绕过逻辑。
* 审计等效字段,例如 `docker_compose_location`。
## 引用与致谢
* **报告人 / 致谢:** [ThemeHackers](https://github.com/ThemeHackers)
* **官方公告:** [GitHub Security Advisory (GHSA-qqrq-r9h4-x6wp)](https://github.com/coollabsio/coolify/security/advisories/GHSA-qqrq-r9h4-x6wp)
标签:CVE, OpenVAS, PHP, StruQ, 命令注入, 数字签名, 漏洞分析, 请求拦截, 路径探测