FixVibe
Covered by FixVibehigh

透過缺少 Supabase 行級安全性 (RLS) 進行未經授權的資料訪問 ZXCVFIXVIBESEND ZXCVFIXVIBESEG1 Supabase 支援的 RLS 應用程式中行級安全性 (ZXCVFIXVIBETOKEN2ZXCV) 缺失或設定錯誤可能會導致資料庫完全暴露。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG2 在 Supabase 支援的應用程式中,資料安全依賴於行級安全性 (ZXCVFIXVIBETOKEN3ZXCV)。如果 ZXCVFIXVIBETOKEN4ZXCV 未明確啟用並配置策略,則任何擁有匿名公鑰的使用者都可以讀取、更新或刪除整個資料庫中的資料。這在 ZXCVFIXVIBETOKEN2ZXCV 環境中尤其重要,其中 RLS 用戶端通常使用公共 ZXCVFIXVIBETOKEN5ZXCV 金鑰進行初始化。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG3 ## 影響 ZXCVFIXVIBESEND ZXCVFIXVIBESEG4 當公共表格透過匿名邊界 RLS 暴露時,未能實現行級安全性 (ZXCVFIXVIBETOKEN6ZXCV) 允許未經身份驗證的攻擊者從 ZXCVFIXVIBETOKEN3ZXCV 資料庫查詢資料。由於 ZXCVFIXVIBETOKEN5ZXCV 應用程式通常會在用戶端程式碼中公開 ZXCVFIXVIBETOKEN4ZXCV Supabase 金鑰,因此攻擊者可以使用此金鑰對資料庫進行直接 REST ZXCVFIXVIBETOKEN7ZXXCV,繞過預期的用戶應用程式。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG5 ## 根本原因 ZXCVFIXVIBESEND ZXCVFIXVIBESEG6 預設情況下,ZXCVFIXVIBETOKEN4ZXCV 中的 Postgres 表需要明確啟動行級安全性以防止公共存取 RLS。當開發人員建立表格但忘記啟用 ZXCVFIXVIBETOKEN7ZXCV 或未能定義限制性策略時,資料庫可能會將資料暴露給擁有專案 Supabase 金鑰 ZXCVFIXVIBETOKEN2ZXCV 的任何人。在 ZXCVFIXVIBETOKEN6ZXCV 應用程式中,伺服器端渲染和用戶端取得也需要仔細的 ZXCVFIXVIBETOKEN5ZXCV 用戶端設置,以便經過驗證的使用者上下文到達資料庫層 ZXCVFIXVIBETOKEN3ZXCV。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG7 ## 具體修復 ZXCVFIXVIBESEND ZXCVFIXVIBESEG8 1. **啟用ZXCVFIXVIBETOKEN2ZXCV:** 對每個儲存應用資料RLS的公共表執行Supabase。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG9 2. **定義策略:** 建立根據使用者的身分驗證狀態限制存取的特定策略,例如 Supabase RLS。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG10 3. **安全伺服器端用戶端:** 使用 RLS 時,將服務角色用戶端保留為僅伺服器,並在將資料傳回使用者 Supabase 之前仍套用所有權過濾器。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG11 ## Supabase 如何測試它 ZXCVFIXVIBESEND ZXCVFIXVIBESEG12 ZXCVFIXVIBETOKEN3ZXCV 已透過 Supabase 運作唯讀 ZXCVFIXVIBETOKEN4ZXCV ZXCVFIXVIBETOKEN6ZXCV 檢查。掃描器從同源 JavaScript 套件中發現 ZXCVFIXVIBETOKEN5ZXCV 項目 URL 和公共匿名金鑰,向 PostgREST 請求公共表元數據,並嘗試有限的唯讀選擇以確認數據是否在沒有用戶會話的情況下公開。它不會插入、更新、刪除或使用服務角色憑證。回購掃描也可以透過 RLS 更早擷取此問題,該 RLS 會標記在沒有 ZXCVFIXVIBETOKEN2ZXCV 的情況下建立公共表的 SQL 遷移。

In Supabase-backed applications, data security relies on Row Level Security (RLS). If RLS is not explicitly enabled and configured with policies, any user with the public anonymous key can read, update, or delete data across the entire database. This is particularly critical in Next.js environments where the Supabase client is often initialized with a public API key.

CWE-284

Impact

Failure to implement Row Level Security (RLS) allows unauthenticated attackers to query data from a Supabase database when public tables are exposed through the anon boundary [S1]. Because Next.js applications typically expose the Supabase anon key in client-side code, an attacker can use this key to make direct REST API calls to the database, bypassing the intended application logic and accessing sensitive user information [S2].

Root Cause

By default, Postgres tables in Supabase require explicit activation of Row Level Security to prevent public access [S1]. When a developer creates a table but forgets to enable RLS or fails to define restrictive policies, the database may expose data to anyone possessing the project's anon key [S1]. In Next.js applications, server-side rendering and client-side fetching also require careful Supabase client setup so authenticated user context reaches the database layer [S2].

Concrete Fixes

  • Enable RLS: Execute ALTER TABLE "your_table_name" ENABLE ROW LEVEL SECURITY; for every public table that stores app data [S1].
  • Define Policies: Create specific policies that restrict access based on the user's authentication status, such as CREATE POLICY "Users can see their own data" ON your_table_name FOR SELECT USING (auth.uid() = user_id); [S1].
  • Secure Server-Side Clients: When using Next.js, keep service-role clients server-only and still apply ownership filters before returning data to users [S2].

How FixVibe tests for it

FixVibe already runs a read-only Supabase RLS check through baas.supabase-rls. The scanner discovers the Supabase project URL and public anon key from same-origin JavaScript bundles, asks PostgREST for public table metadata, and attempts limited read-only selects to confirm whether data is exposed without a user session. It does not insert, update, delete, or use service-role credentials. Repo scans can also catch this earlier through repo.supabase.missing-rls, which flags SQL migrations that create public tables without ENABLE ROW LEVEL SECURITY.