PostgreSQL security · 10 minute read
Building a browser-native PostgreSQL RLS lab with PGlite (free, no Supabase account)
You want to test whether a Row Level Security policy actually blocks a cross-tenant read. Normally that means spinning up PostgreSQL, configuring roles, loading data and connecting a client — or signing up for Supabase and waiting for a project to provision.
There is a faster way: run PostgreSQL entirely in the browser with PGlite. No account, no server, no install. The database lives in IndexedDB, the SQL engine is WebAssembly, and the whole experiment fits in a single tab. This is the approach behind the RLS lab we run at cekuu35.github.io/rls-seance — a browser-native arena where you summon the anon role against a schema, run read-only probes, and get a LEAK or BLOCKED verdict with the actual rows as evidence.
Why run RLS tests in the browser
RLS bugs are easiest to catch before deployment, but most teams only test them against a staging database they cannot reach on a Tuesday afternoon. A browser-native lab removes that friction:
- No provisioning: open a tab and you have a PostgreSQL engine.
- No credentials: no connection string, no password, no IP allowlist.
- Disposable: close the tab and the database is gone; nothing persists unless you deliberately export it.
- Shareable: export the schema and SQL as a fixture and send it to a reviewer without exposing production data.
The trade-off is scale and durability. PGlite is for experiments and verification, not production workloads or large datasets. For a policy check or a two-user isolation test, it is more than enough — the build story, including the four engine facts that cost the most debugging time, is in how RLS Séance was built with Kiro.
What you need
- A modern browser — anything with WebAssembly and IndexedDB.
- The
@electric-sql/pglitepackage, or a CDN build. - A schema and a few seed rows representing your tenants.
That is it. No Supabase account, no Docker container, no local Postgres install.
A minimal PGlite RLS setup
First the table and the policy. One statement per call — PGlite's query() path refuses multi-statement scripts, so use exec() when you want to run a whole file at once:
import { PGlite } from '@electric-sql/pglite';
const db = new PGlite('local://rls-lab');
await db.query(`
create table if not exists documents (
id serial primary key,
owner_id text not null,
title text not null
);
`);
await db.query(`alter table documents enable row level security;`);
await db.query(`
create policy documents_own_row
on documents
for all
to public
using (current_setting('app.current_user_id', true) = owner_id);
`);Then seed two tenants:
await db.query(`insert into documents (owner_id, title)
values ('alice', 'Alice budget')`);
await db.query(`insert into documents (owner_id, title)
values ('bob', 'Bob forecast')`);Now the probe. The session variable is what stands in for the request-scoped identity your API would normally set, so set it before each read and reset it after— a probe that runs with the previous tenant's identity produces a confident, wrong verdict:
async function readAs(tenant) {
await db.query(`select set_config('app.current_user_id', $1, false)`, [tenant]);
const result = await db.query(`select id, owner_id, title from documents`);
await db.query(`select set_config('app.current_user_id', '', false)`);
return result.rows;
}
const alice = await readAs('alice');
const bob = await readAs('bob');If the policy works, Alice sees one row and Bob sees one row — never each other's. If both see both rows, the policy is not doing what it reads like it does, and you have found the leak before it reached production. The full test matrix, including the negative cases most suites skip, is in how to test Supabase RLS policies before launch.
The four things to check in every lab session
- The owner sees their own rows. Baseline: the policy does not block legitimate access.
- A second tenant sees zero rows of the first tenant. This is the isolation guarantee you are actually buying with RLS.
- The
anonrole sees nothing by default. Ifanoncan SELECT, your table is public to anyone with the API key. - A policy written for one role does not silently cover another. In PostgreSQL,
to authenticatedandto publicare different targets; mixing them up is one of the most common RLS misconfigurations — see the always-true authenticated policy for the case where the confusion leaks everything.
What a browser lab cannot prove
A PGlite lab validates the SQL policy against the engine you run:
- It cannot prove that your Supabase project's deployed policies match the ones you tested.
- It cannot prove that your middleware sets the RLS session variable correctly on every request.
- It cannot prove that your Edge Functions or API routes do not bypass RLS with the service role.
For those you need a runtime check against a real staging database. The lab is for fast, cheap iteration; the staging harness is for final verification. Supabase's Row Level Security documentation covers the server-side half of that contract.
Where this fits in a review workflow
A review works the same way the lab does, in the opposite order: the source-and-policy pass first (what a browser lab can verify), then a two-user runtime harness against your project (what it cannot). The lab is where you prototype the check; the harness is where you collect evidence. If you would rather have that runtime pass run for you, the Supabase RLS review from $95 covers the same two steps against your project.
Take the lab offline, into your own schema
Run these checks against your real policies
Supabase RLS Audit Kit · $29 one-time
Seven commented SQL audits, a 60-check workflow and remediation templates — the same checks you prototype in PGlite, then run against staging for the runtime verdict.
Get the kit - $29 ↗Review the files, scope and license →Rather have the runtime verdict from your live project than the lab run?
Fixed-price reviews with the evidence, the SQL and the written verdict. Fixes are quoted separately. Instant checkout, no account needed.
Related reading: the build story behind the public lab, the RLS test matrix, the always-true authenticated policy and the public repository at github.com/cekuu35/rls-seance, which contains the fixtures the lab runs.