AI 建構的應用程式中,如何用雙帳戶測試檢查 Supabase、Firebase 及自訂 API 的用戶資料隔離
Can one user see another user's data in your AI-built app? The two-account test for Supabase, Firebase and custom APIs
ProofForge 提出以兩個帳戶測試 Supabase、Firebase 及自訂 API 的存取控制,檢查其他用戶或未登入訪客能否讀取私人資料。做法是先以帳戶 A 建立私人資料,再以帳戶 B 使用 A 的 ID 嘗試讀取、修改或刪除,並以未登入狀態重測;單純掃描 URL 無法檢查資料庫政策或伺服器端權限。
You can log in to your app, see your own data, and everything looks right. That tells you nothing about whether a second user can see yours.
This is called broken access control, or IDOR (insecure direct object reference) when it happens through an ID in a request. It is one of the most common serious bugs in apps built quickly with AI tools, because the app works fine for the one person testing it.
Why a URL scan can't find it
A scanner that checks your public site sees what a visitor sees: JavaScript, headers, public files. Whether user B can read user A's orders depends on your database policies and your server checks, and those only show up when two real accounts are used. Anyone who tells you a scan of a URL proves your users are separated is guessing.
The manual two-account test (15 minutes)
You need two test accounts, A and B. Use throwaway emails, and do this on a staging copy if you can.
- Sign in as A. Create something private: an order, a note, a profile field. Write down the ID that shows up in the URL or in the network tab.
- Sign in as B in a different browser profile.
- Try to open A's item directly. Paste A's URL, or call the same API request with A's ID using B's session.
- Try to change A's item as B (edit, delete). Reads and writes are separate checks.
- Sign out and repeat step 3 with no session at all.
If B or a signed-out visitor gets A's data, you have the bug.
Supabase: where it usually lives
With Supabase, the browser talks to your database directly using the anon key. That is normal. What protects the data is row level security (RLS). Check these:
- RLS is on for every table with user data.
- Each policy compares the row owner to the signed-in user, like
user_id = auth.uid(). - No policy says
using (true)on a table that holds private rows. - Storage buckets with private files are not public.
The test for Supabase: sign in as B and run select on A's rows with the Supabase client. You should get zero rows back, not A's data.
Firebase
Open your Firestore and Storage rules. allow read, write: if true; means everyone. A safe rule ties access to request.auth.uid matching the owner field of the document.
Custom APIs (Next.js, Express, serverless)
Do not trust an ID sent by the browser. On the server, take the user from the session, then look up the record with both the ID and that user. If the record does not belong to the user, return 404.
A free script that does the test for you
ProofForge has a free two-account test for Supabase projects: you enter your project URL, your private tables and the owner column, and it builds a read-only script in your browser. You run it on your own computer with two throwaway test accounts. No keys or passwords go into the form, and it never reports an unclear result as a pass. It only reads, and signing in as test users can write to your authentication logs. It does not test writes, deletes or storage. https://proofforge.live/two-account-test
What each tool can and cannot see
| Question | Outside scan | Two-account test |
|---|---|---|
| Keys in public JavaScript | Yes | No |
| Public tables open to everyone | Yes | Partly |
| User B reading user A's rows | No | Yes |
| Server-side logic bugs | No | No |
Use both. The outside scan is free at https://proofforge.live. Neither replaces a code review.
來源:DEV Community · dev.to