Seedworks Labs Wiki The engineering referenceStudio website ↗
Studio & ecosystem

Authorization boundaries

RLS, restrictive OAuth policies, request guards and legacy-session limits.

Engineering documentation • Reviewed 2026-11-29

Authentication is not authorization#

A verified Supabase access token identifies the user and can include a signed OAuth client_id. Neither a public API key nor the presence of an email scope decides which finance/meal rows that token may read.

The reviewed system combines:

  1. Owner or membership RLS.
  2. Restrictive OAuth app-client policies.
  3. A PostgREST pre-request guard.
  4. Checks inside sensitive RPCs and Edge Functions.

These layers cover different routes; none should be removed merely because another exists.

Personal and shared RLS#

Coconut personal rows are associated with the authenticated owner. Shared Space rows require appropriate membership. Banana's later shared-life model authorizes data identities, allowing personal ownership or household membership.

UUID knowledge is not access. A client-provided user_id is not trusted merely because the UI supplied it. Both existing rows and proposed writes must satisfy server policies (USING and WITH CHECK).

App schemas prevent naming collisions, but a schema name by itself is not a security boundary. Grants, exposure configuration, RLS and RPC checks make the difference.

Restrictive OAuth policies#

20261121120000_oauth_client_isolation.sql defines seed_oauth_app_allowed(p_app):

  • No client_id claim: preserve existing password/native behavior.
  • Registered Coconut client: allow the Coconut app boundary.
  • Unknown or cross-app OAuth client: deny.

It adds seed_oauth_client_boundary as a restrictive policy on existing app tables. PostgreSQL combines restrictive policies with the permitted owner/membership result using AND. Adding an ordinary permissive policy instead could broaden access via OR and defeat the intended boundary.

New app tables need their own boundary review. The migration iterates over tables existing when it runs; it does not magically protect every future table.

Why a REST request guard is also necessary#

Security-definer functions can execute with elevated privileges and bypass ordinary table RLS. Blocking only table SELECT is not enough if a cross-app RPC can return the same protected data.

seed_oauth_request_guard examines signed claims and PostgREST request metadata:

  • GET/HEAD select schema through Accept-Profile.
  • Other methods select schema through Content-Profile.
  • Missing profile defaults to public.
  • The registered Coconut client can target coconut.
  • Narrow public RPC exceptions are explicit.
  • Other delegated requests fail with insufficient privilege.

The initial public exception is Coconut's app-usage report. The picture migration later wraps the guard with a precise POST exception for the caller's own seed_get_profile_picture read.

The hook is configured through the authenticator role's pgrst.db_pre_request. The migration refuses to overwrite an unrelated existing hook; an operator must explicitly compose checks.

Sensitive RPCs defend themselves#

The OAuth migration renames internal implementations of usage reporting/account overview, revokes API execution on those internals and exposes guarded wrappers.

seed_report_app_usage independently checks that the delegated client can report the requested app. seed_account_overview rejects OAuth-client sessions independently of the request hook.

The picture setter rejects all sessions carrying client_id; the getter restricts registered access and always reads the caller's row. The deletion Edge Function verifies Auth first, rejects delegated clients, and requires server-side password reauthentication.

This matters for direct invocation paths and future APIs that might not pass through the same PostgREST guard.

Session capability matrix#

Session Own Coconut rows Banana data Central overview/profile writes Own picture read Account deletion
Anonymous No private access No private access No No No
Password/native, no client_id Owner/member rules Personal/household rules Existing central permissions Yes Only with password/confirmation
Registered Coconut OAuth Owner/member rules plus app boundary Denied Denied Narrow permitted RPC Denied
Unknown OAuth client Denied Denied Denied Denied Denied

This summarizes intended reviewed contracts, not a substitute for testing the deployed schema, grants, hook and function versions.

The legacy-session limitation#

Password/native tokens do not contain app-specific client_id, so the backend cannot distinguish Banana's password session from the central website's password session using that claim.

Those tokens retain platform-wide authority subject to user/membership rules. Current OAuth isolation does not retrofit app-scoped credentials onto every existing native session.

Strict website-only management for those sessions would require a new trusted central-session mechanism. Checking browser Origin, hiding buttons or shipping a different publishable key does not solve it.

Readiness is a rollout safeguard#

seed_oauth_sso_ready() requires an authenticated non-OAuth central user, the expected loaded pre-request hook and restrictive boundaries on the checked app tables. The consent UI fails closed when it is missing or false.

It is not a formal security proof. It cannot replace real requests covering profile-header routing, RPC execution privileges, new schemas, Edge Functions, GraphQL/realtime surfaces and future migrations.

Regression checks#

supabase/tests/oauth-isolation.sql covers ownership, app-client restrictions, unknown clients, central denials, profile-header behavior and legacy-session compatibility. profile-pictures.sql exercises the image contract.

Run fixtures only in an isolated local database after the migrations. They roll back, but are not authorized for production. Then test actual PostgREST requests in staging: setting SQL request variables is not evidence that the running API loaded the hook.

Do not loosen production RLS to investigate a UI bug. Reproduce with isolated fixtures and inspect the denied boundary first.