关于 supabase-audit-authenticated
用于以认证用户身份审计 Supabase 访问权限的安全技能。它创建测试账户,对比认证与匿名访问,并检查 IDOR、跨用户数据暴露和权限提升;操作前须获得明确同意。
主要功能
- 01经同意后创建测试用户
- 02对比认证与匿名访问
- 03检查 IDOR 和跨用户访问
- 04测试 Storage 与 Realtime 访问
- 05渐进记录审计日志和证据
适用场景
- 01检查 RLS 是否限制用户访问自身数据
- 02查找 Supabase 表中的 IDOR
- 03比较认证访问与匿名访问结果
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ yoanbernabeu/ supabase-pentest-skills --skill supabase-audit-authenticated安装后在 Claude Code 中输入/supabase-audit-authenticated确认已加载。
详细介绍
已认证用户审计
🔴 严重:必须逐步更新文件
你必须在执行过程中写入上下文文件,而不是只在最后写入。
- 每次测试后立即写入
.sb-pentest-context.json- 每项操作前后都记录到
.sb-pentest-audit.log- 不要等到技能完成后才更新文件
- 如果技能崩溃或中断,此前的所有发现都必须已保存
这不是可选项。未能逐步写入属于严重错误。
此技能会创建一个测试用户(已获得明确许可),用于比较已认证与匿名访问,并检测 IDOR 漏洞。
⚠️ 重要:必须征得用户同意
╔═══════════════════════════════════════════════════════════════════╗
║ 🔐 USER CREATION CONSENT REQUIRED ║
╠═══════════════════════════════════════════════════════════════════╣
║ ║
║ This skill will CREATE A TEST USER in your Supabase project. ║
║ ║
║ The user will be created with: ║
║ • Email: pentest-[random]@security-audit.local ║
║ • Password: Strong random password (32+ chars) ║
║ • Purpose: Testing authenticated access vs anonymous ║
║ ║
║ At the end of the audit, you will be asked if you want to ║
║ DELETE the test user (recommended). ║
║ ║
║ Do you authorize the creation of a test user? ║
║ Type "yes, create test user" to proceed. ║
║ ║
╚═══════════════════════════════════════════════════════════════════╝
未经用户明确同意,不要继续。
何时使用此技能
- 完成匿名访问测试后
- 检测 IDOR(不安全的直接对象引用)漏洞
- 测试跨用户数据访问
- 验证 RLS 策略对已认证用户是否有效
- 查找权限提升问题
前提条件
- 必须开放注册(或使用邀请流程)
- 可获取 Anon 密钥
- 已完成匿名审计(建议)
为什么已认证测试很重要
许多漏洞只有在已认证状态下才会出现:
| 漏洞 | 匿名 | 已认证 |
|---|---|---|
| 绕过 RLS(未启用 RLS) | ✓ 可检测 | ✓ 可检测 |
| IDOR | ✗ 不可见 | ✓ 仅此时可见 |
| 跨用户访问 | ✗ 不可见 | ✓ 仅此时可见 |
| 权限提升 | ✗ 不可见 | ✓ 仅此时可见 |
| RLS 过于宽松 | 部分可检测 | ✓ 可完整检测 |
创建测试用户
电子邮件格式
pentest-[8-char-random]@security-audit.local
生成密码
使用强密码,要求:
- 至少 32 个字符
- 包含大写字母、小写字母、数字和符号
- 通过密码学安全的方式随机生成
示例:Xk9$mP2#vL5@nQ8&jR4*wY7!hT3%bU6^
密码只显示一次,并会保存为证据。
执行的测试
1. 创建用户并登录
# Create user
curl -X POST "$SUPABASE_URL/auth/v1/signup" \
-H "apikey: $ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "[STRONG_PASSWORD]"}'
# Login and get JWT
curl -X POST "$SUPABASE_URL/auth/v1/token?grant_type=password" \
-H "apikey: $ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "[STRONG_PASSWORD]"}'
2. 比较已认证与匿名访问
对于每个表:
| 测试 | 匿名 | 已认证 | 发现 |
|---|---|---|---|
| SELECT | 0 行 | 1,247 行 | 🔴 仅已认证时暴露 |
| 自有数据 | 不适用 | 仅自己的行 | ✅ RLS 正常工作 |
| 其他用户的数据 | 不适用 | 所有行 | 🔴 跨用户访问 |
3. IDOR 测试
# As test user, try to access other user's data
curl "$SUPABASE_URL/rest/v1/orders?user_id=eq.[OTHER_USER_ID]" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer [TEST_USER_JWT]"
# If returns data: IDOR vulnerability!
4. 跨用户访问
# Get test user's ID from JWT
TEST_USER_ID=$(echo $JWT | jq -r '.sub')
# Try to access data belonging to a different user
curl "$SUPABASE_URL/rest/v1/profiles?id=neq.$TEST_USER_ID" \
-H "Authorization: Bearer [TEST_USER_JWT]"
# If returns other users' profiles: Cross-user access!
5. 已认证状态下的存储
# Test authenticated storage access
curl "$SUPABASE_URL/storage/v1/object/list/documents" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer [TEST_USER_JWT]"
# Compare with anonymous results
6. 已认证状态下的 Realtime
// Subscribe to table changes as authenticated user
const channel = supabase.channel('test')
.on('postgres_changes', {
event: '*',
schema: 'public',
table: 'orders'
}, payload => console.log(payload))
.subscribe()
// Does it receive OTHER users' order changes?
输出格式
═══════════════════════════════════════════════════════════
AUTHENTICATED USER AUDIT
═══════════════════════════════════════════════════════════
─────────────────────────────────────────────────────────
Test User Creation
─────────────────────────────────────────────────────────
Status: ✅ User created successfully
Test User Details:
├── Email: [email protected]
├── User ID: 550e8400-e29b-41d4-a716-446655440099
├── Password: [Saved to evidence - shown once]
└── JWT obtained: ✅
─────────────────────────────────────────────────────────
Anonymous vs Authenticated Comparison
─────────────────────────────────────────────────────────
Table: users
├── Anonymous access: 0 rows
├── Authenticated access: 1,247 rows ← ALL USERS!
└── Status: 🔴 P0 - Data hidden from anon but exposed to any auth user
Table: orders
├── Anonymous access: 0 rows (blocked)
├── Authenticated access: 1 row (own orders only)
└── Status: ✅ RLS working correctly
Table: profiles
├── Anonymous access: 0 rows
├── Authenticated access: 1,247 rows ← ALL PROFILES!
├── Own profile only expected: ❌ NO
└── Status: 🔴 P0 - Cross-user profile access
─────────────────────────────────────────────────────────
IDOR Testing
─────────────────────────────────────────────────────────
Test: Access other user's orders by ID
├── Request: GET /orders?user_id=eq.[other-user-id]
├── Auth: Test user JWT
├── Response: 200 OK - 15 orders returned
└── Status: 🔴 P0 - IDOR VULNERABILITY
Proof:
curl "$URL/rest/v1/orders?user_id=eq.other-user-uuid" \
-H "Authorization: Bearer [test-user-jwt]"
# Returns orders belonging to other-user-uuid!
Test: Access admin endpoints
├── Request: GET /functions/v1/admin-panel
├── Auth: Test user JWT (regular user)
├── Response: 200 OK - Admin data returned!
└── Status: 🔴 P0 - PRIVILEGE ESCALATION
─────────────────────────────────────────────────────────
Storage with Authentication
─────────────────────────────────────────────────────────
Bucket: documents
├── Anonymous: ❌ 0 files (blocked)
├── Authenticated: ✅ 523 files visible ← ALL USERS' FILES!
└── Status: 🔴 P1 - Auth users see all documents
Bucket: user-uploads
├── Anonymous: ❌ 0 files
├── Authenticated: 3 files (own files only)
└── Status: ✅ RLS working correctly
─────────────────────────────────────────────────────────
Summary
─────────────────────────────────────────────────────────
New Findings (Auth-only):
├── 🔴 P0: users table - all users visible to any auth user
├── 🔴 P0: profiles table - cross-user access
├── 🔴 P0: IDOR in orders - can access any user's orders
├── 🔴 P0: Privilege escalation in admin-panel
└── 🟠 P1: documents bucket - all files visible to auth users
Comparison:
├── Issues found (Anonymous): 3
├── Issues found (Authenticated): 8 ← 5 NEW ISSUES!
└── Auth-only vulnerabilities: 5
Recommendation:
These issues were NOT visible in anonymous testing!
Always test with authenticated users.
─────────────────────────────────────────────────────────
Cleanup
─────────────────────────────────────────────────────────
⚠️ Test user still exists in database.
Do you want to delete the test user?
Email: [email protected]
[This requires service_role key or manual deletion]
═══════════════════════════════════════════════════════════
上下文输出
{
"authenticated_audit": {
"timestamp": "2025-01-31T12:00:00Z",
"test_user": {
"email": "[email protected]",
"user_id": "550e8400-e29b-41d4-a716-446655440099",
"created_at": "2025-01-31T12:00:00Z",
"deleted": false
},
"comparison": {
"tables": {
"users": {
"anon_access": 0,
"auth_access": 1247,
"expected_auth_access": "own_row_only",
"severity": "P0",
"finding": "All users visible to any authenticated user"
},
"orders": {
"anon_access": 0,
"auth_access": 1,
"expected_auth_access": "own_rows_only",
"severity": null,
"finding": "RLS working correctly"
}
},
"idor_tests": [
{
"test": "access_other_user_orders",
"vulnerable": true,
"severity": "P0",
"proof": "curl command..."
}
],
"privilege_escalation": [
{
"endpoint": "/functions/v1/admin-panel",
"vulnerable": true,
"severity": "P0"
}
]
},
"summary": {
"anon_issues": 3,
"auth_issues": 8,
"auth_only_issues": 5
}
}
}
RLS 策略示例
正确:用户只能查看自己的数据
-- This RLS policy is correct
CREATE POLICY "Users see own data"
ON users FOR SELECT
USING (auth.uid() = id);
-- Result:
-- Anonymous: 0 rows
-- Authenticated: 1 row (own data)
错误:所有已认证用户都能查看所有数据
-- This RLS policy is WRONG
CREATE POLICY "Authenticated users see all"
ON users FOR SELECT
USING (auth.role() = 'authenticated'); -- ❌ Too permissive!
-- Result:
-- Anonymous: 0 rows
-- Authenticated: ALL rows ← VULNERABILITY!
正确的修复:
-- Fix: Add user ownership check
CREATE POLICY "Users see own data"
ON users FOR SELECT
USING (auth.uid() = id); -- ✅ Only own row
清理选项
选项 1:手动删除(控制台)
Supabase Dashboard → Authentication → Users → Find test user → Delete
选项 2:通过 service_role 密钥删除(如果可用)
curl -X DELETE "$SUPABASE_URL/auth/v1/admin/users/[USER_ID]" \
-H "apikey: $SERVICE_ROLE_KEY" \
-H "Authorization: Bearer $SERVICE_ROLE_KEY"
选项 3:稍后处理
测试用户使用非功能性电子邮件域名(security-audit.local),无法被用于恶意用途。
必须执行:收集证据
📁 证据目录: .sb-pentest-evidence/05-auth-audit/authenticated-tests/
要创建的证据文件
| 文件 | 内容 |
|---|---|
test-user-created.json | 测试用户详情(密码安全保存) |
anon-vs-auth-comparison.json | 并排比较 |
idor-tests/[table].json | IDOR 测试结果 |
privilege-escalation.json | 权限提升测试 |
证据格式
{
"evidence_id": "AUTH-TEST-001",
"timestamp": "2025-01-31T12:00:00Z",
"category": "auth-audit",
"type": "authenticated_testing",
"test_user": {
"email": "[email protected]",
"user_id": "550e8400-...",
"password": "[STORED SECURELY - DO NOT COMMIT]"
},
"comparison_test": {
"table": "users",
"anonymous": {
"curl_command": "curl '$URL/rest/v1/users' -H 'apikey: $ANON_KEY'",
"response_status": 200,
"rows_returned": 0
},
"authenticated": {
"curl_command": "curl '$URL/rest/v1/users' -H 'apikey: $ANON_KEY' -H 'Authorization: Bearer $JWT'",
"response_status": 200,
"rows_returned": 1247
},
"finding": {
"severity": "P0",
"issue": "All users visible to any authenticated user",
"expected": "Only own row should be visible",
"impact": "Full user enumeration for any authenticated user"
}
}
}
添加到 curl-commands.sh
# === AUTHENTICATED TESTING ===
# NOTE: Replace [JWT] with test user's JWT
# Compare anonymous vs authenticated access
curl -s "$SUPABASE_URL/rest/v1/users?select=*&limit=5" -H "apikey: $ANON_KEY"
curl -s "$SUPABASE_URL/rest/v1/users?select=*&limit=5" -H "apikey: $ANON_KEY" -H "Authorization: Bearer [JWT]"
# IDOR test - access other user's data
curl -s "$SUPABASE_URL/rest/v1/orders?user_id=eq.[OTHER_USER_ID]" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer [JWT]"
# Cross-user profile access
curl -s "$SUPABASE_URL/rest/v1/profiles?id=neq.[TEST_USER_ID]" \
-H "apikey: $ANON_KEY" \
-H "Authorization: Bearer [JWT]"
必须执行:逐步更新上下文文件
⚠️ 此技能必须在执行期间逐步更新跟踪文件,而不是只在最后更新。
关键规则:边做边写
不要把所有写入操作都留到最后。请按以下步骤操作:
- 创建用户前 → 将同意和操作记录到
.sb-pentest-audit.log - 创建用户后 → 立即将用户详细信息保存到上下文和证据中
- 每次对比测试后 → 使用测试结果更新
.sb-pentest-context.json - 每次 IDOR 测试后 → 立即保存证据
这样可以确保即使技能被中断、崩溃或超时,截至当时的所有发现都能得到保留。
必需操作(逐步进行)
-
记录用户创建:
[TIMESTAMP] [supabase-audit-authenticated] [CONSENT] User authorized test user creation [TIMESTAMP] [supabase-audit-authenticated] [CREATED] Test user [email protected] -
立即将测试用户保存到上下文中:
{ "authenticated_audit": { "test_user": { "email": "...", "user_id": "...", "created_at": "..." } } } -
发现问题时立即逐项记录:
[TIMESTAMP] [supabase-audit-authenticated] [FINDING] P0: IDOR in orders table
不逐步更新上下文文件是不可接受的。
相关技能
supabase-audit-auth-signup— 首先测试注册是否开放supabase-audit-tables-read— 与匿名结果进行对比supabase-audit-rls— 深入检查 RLS 策略supabase-audit-functions— 测试经过身份验证的函数访问权限supabase-report— 在报告中纳入仅限身份验证的发现
评论
支持 Markdown