Supabase RLS as the Access Control Boundary for a Headless Analytics Backend With No Frontend to Hide Behind
RLS policies must filter rows before analytics APIs expose data to dashboards, scripts, and agents.

For API-first and agent-first teams, a Supabase headless analytics backend needs RLS as its database access boundary. Without an application server to pre-filter requests, a policy gap can expose raw data directly. The sound architecture pairs RLS with governed, pre-calculated datasets, giving dashboards, scripts, and agents API access without treating production tables as the analytics interface.
Why a headless analytics backend has no fallback when RLS fails
A conventional application server checks identity in code and decides which query to run. A headless Supabase setup has no such intermediary by default, so the database must enforce the distinction between an allowed request and an unauthorized one. There is no application-level fallback for a missing policy. Analytics sharpens that risk because human dashboards, scheduled scripts, and AI agents can all reach the same backend.
The anon key is embedded in client bundles by design and reaches scripts, agents, and API consumers too. It is not a private credential that conceals the database. Under the older automatic-grant model, that key alone makes public-schema tables reachable through the generated REST and GraphQL APIs. RLS must then restrict the rows available to each caller. Matt Palmer’s CVE-2025-48757 research tested for this exposure by sending direct API requests without a user token to find tables that returned private rows.
What the 2026 Data API change does and does not fix
Supabase’s 2026 Data API change tightens table reachability. The change became available as an opt-in in late April 2026 and the default for new projects on May 30, 2026. New public-schema tables in those projects require explicit grants before the Data API exposes them. Existing projects move to the same default on 30 October 2026, but existing tables retain their grants.
Grants allow a caller to reach a table for an operation, while RLS restricts the rows that operation can affect or return. The prescribed lock-down sequence therefore enables RLS, revokes broad grants from anon and authenticated, and grants back only the operations needed. Both controls need deliberate configuration. A backend built before the change can still have tables governed by the earlier exposure model until those tables are audited and remediated.
How RLS actually enforces the boundary from client to row
The request path begins when a client sends the anon or publishable key, with an Authorization header if a user is signed in. PostgREST then opens its Postgres connection as authenticator, a role with very limited access. Next, it verifies the JWT and issues SET LOCAL ROLE for the transaction, selecting anon without a valid user token or authenticated with one.
PostgREST then places the token payload in the transaction-local setting request.jwt.claims. The auth.uid() function reads sub from those claims and casts it to UUID. Finally, Postgres executes the query as the selected role, injecting the policy’s USING expression as a per-row predicate. RLS acts as an implicit filter AND-ed onto the query as the table is scanned.
Enabling RLS without policies causes queries from callers subject to RLS to return zero rows and their writes to be rejected, including requests from authenticated users. Testing through the dashboard SQL editor can obscure this behavior because it skips PostgREST’s role switching and claim setup. Three access paths need to be checked separately, service-role requests, direct database connections, and ORMs connecting directly to Postgres. The service-role key bypasses RLS, and direct connections must be checked for the database role they use because they do not rely on API identity handling.
The service-role key as the silent bypass that undoes all policy work
The service-role key bypasses RLS completely by design. If an agent receives it as its database credential, tenant policies no longer constrain that agent’s table access. A prompt-injection or tool-misuse incident then has unrestricted read and write scope. The application can still look as though it works normally. There is no error or dedicated bypass log entry to show that row policies no longer protect those requests.
The same failure occurs when the key reaches a browser bundle or a publicly committed environment file. Policy correctness cannot compensate for a credential that bypasses policy enforcement. The required boundary is therefore categorical. The service-role key belongs exclusively in trusted server-side code, never in a client artifact, public repository, agent tool configuration, or agent context window.
Why analytics tables created outside the Table Editor ship without RLS
Supabase automatically enables RLS through its dashboard table-creation workflow, including the Table Editor. SQL editor statements, migration files, and ORM-created tables do not receive that protection by default. Without that trigger, SQL-created tables require explicit enablement. Analytics engineers commonly work through SQL and migrations, placing their normal workflow directly in this gap.
AI-generated SQL can reproduce the same omission by leaving out ALTER TABLE... ENABLE ROW LEVEL SECURITY. This security-default gap in scaffolding can occur across tools. Palmer’s research on CVE-2025-48757 used an observable test rather than assumptions about how an application had been built. The API response exposed the missing boundary. A private table returning rows to an unauthenticated request demonstrated the failure.
For an existing backend, the first detection step is Supabase’s built-in Security Advisor. It flags disabled RLS, overly permissive policies, SECURITY DEFINER views, and anon-callable SECURITY DEFINER functions at no cost. A direct REST request using only the publishable or anon key, without a user auth token, should not return private rows. A positive result confirms exposure.
Four RLS policy failures that are specific to analytics workloads
Unindexed policy predicates are the first failure. Analytics queries can touch millions of rows, turning a tolerable per-user filter into a query-breaking cost. Wrapping the auth call in a subquery lets Postgres evaluate it once per statement, while indexing the policy’s filter column supports the scan. Together, these changes can produce order-of-magnitude improvement on large tables. A policy must be practical to execute as well as logically correct.
Aggregate leakage is the second and more fundamental failure. RLS has no native concept of allowing COUNT(*) while prohibiting access to the underlying rows needed to compute it. A row predicate determines eligibility. Permission to access rows and permission to publish metrics are different contracts. Aggregation across dimensions can reveal distributions that the analytics interface was not intended to disclose.
This is not simply a malformed USING expression. RLS alone cannot let callers see only aggregates, so rewriting the same row policy cannot close that gap in the architecture. Expose pre-aggregated, pre-governed datasets. Those datasets define the metrics and dimensions available to callers.
Column exposure is the third failure. A metrics table may include cost data or PII that must remain hidden even when its other fields are available. Row filtering cannot make that distinction within an allowed row. A view or column-level GRANT must provide the additional restriction.
The fourth failure is the loss of caller context. Analytics interfaces frequently rely on views and functions, which require their own access review. A view or SECURITY DEFINER function can execute with owner privileges, losing the caller’s role context. Each exposed object must be audited for the identity under which it accesses data.
What happens when AI agents become callers in a headless analytics backend
An MCP endpoint exposing an insufficiently scoped database connection adds a caller with no required human review between request and result. Agents can run into gaps in naming and permissions through their tool calls as well as through the paths a dashboard was built to use. Their credentials set the limits on what those calls can do. An endpoint is therefore an access interface.
The 2026-07-28 MCP specification removes protocol-level sessions and the initialize handshake, establishing a stateless core. Each request carries the protocol version, client identity, and client capabilities in _meta, while OAuth tokens handle authentication separately. There is no protocol session to restore missing identity. For Supabase-backed calls, RLS must resolve identity from the JWT on every request.
The reference Postgres MCP server wrapped queries in read-only transactions, but its client accepted multiple semicolon-delimited statements, allowing COMMIT; to escape that envelope. In the February 2026 drizzle-kit incident, a coding agent pushed a schema change with --force to production Postgres, wiping 60+ tables. RLS does not protect against schema-level destruction. Write-path controls and point-in-time recovery infrastructure help deal with this kind of failure.
The NSA’s May 2026 report, “Model Context Protocol (MCP): Security Design Considerations for AI-Driven Automation”, identified confused-deputy risks in MCP proxy servers and token passthrough paths to privilege escalation. That concern connects directly to caller identity. A proxy must not turn a narrowly authorized caller into a broadly privileged database request. JWT resolution cannot protect a request already executed through a bypass credential.
What should the analytics boundary look like for API-first and agent-first teams
RLS remains necessary wherever callers reach protected Postgres rows, but it cannot define what a metric means. Two agents can respect the same row policy and still calculate different numbers from the same table. Access control does not establish metric consistency. Rate limiting, conditional access based on external state, and column suppression also do not fit cleanly into SQL USING expressions. These requirements belong elsewhere in the stack.
RLS secures the data that remains in Postgres, while a governed, pre-modeled layer exposes pre-calculated metrics to dashboards and agents. Callers consume defined datasets rather than inventing queries against live production rows. Full API control need not mean unrestricted SQL.
Pre-calculated datasets queryable through DuckDB over governed Parquet files, exposed through a single MCP server, provide a concrete implementation of that separation. Agents can get fast, accurate context that is cheap to query without touching the production database. Governance determines which aggregates and dimensions are published. Withholding raw rows removes direct access to their distributions, while the published aggregates still require disclosure-aware design. The stronger boundary is controlled data publication.
The practical audit sequence for an existing headless analytics backend
The audit starts with Supabase’s Security Advisor, then tests grants through direct REST requests against each table that should be private. Each request uses the publishable or anon key without an Authorization header. Returned private rows confirm an exposure requiring remediation. The fix follows the explicit lock-down sequence, enabling RLS, revoking broad anon and authenticated grants, and restoring only needed operations. Existing grants still require review under the 2026 default.
Next, RLS enablement requires inspection on every public-schema table, especially those created through SQL, migrations, ORMs, or AI-generated code. Missing enablement is corrected with ALTER TABLE your_table ENABLE ROW LEVEL SECURITY;. Policy correctness then requires testing through the API caller path. Views and functions also need to be checked for the role context they use. Objects that discard caller identity require correction before they can serve as protected analytics interfaces.
The bypass review searches the codebase, CI environment, and agent tool configurations for the service-role key. Any location outside trusted server-side execution fails the boundary test and requires removing the key from that artifact or configuration. Direct database and ORM connections also need to be checked for the roles they use. Checking these connections separately from PostgREST policy tests establishes which callers actually encounter the policies being audited.
Missing indexes and per-row auth evaluation call for indexed filter columns and statement-level auth subqueries. Raw-table access that permits unwanted inference calls for governed, pre-aggregated datasets. Sensitive columns require views or column-scoped grants. Finally, each agent path needs a cold-request test showing that auth.uid() resolves from its JWT without prior session context, using the minimum role needed.


