Cenk Kurtoğlu©26

Kiro · PostgreSQL security · 9 minute read

Building RLS Séance with Kiro: a PostgreSQL Row Level Security lab that runs in your browser tab

This post is written as part of the Kiroween 2026 hackathon (Kiroween Hackathon 2026). RLS Séance is a bug-hunt arena for Supabase/PostgreSQL Row Level Security. You summon a ghost — the anon role, or authenticated — against a schema, and watch a real PostgreSQL 17.5 instance running as WebAssembly return a verdict for every attack vector: LEAK or BLOCKED, with the rows that came back as evidence. This is a write-up of how the build was structured, and of the four PGlite facts that cost the most debugging time.

Why a database in the browser changes the conversation

Most RLS advice ends with "here is a query you can run in the SQL editor". That is a fine way to read a policy. It is a poor way to feel what a policy does to the row that belongs to somebody else, because the reader has to keep three things in their head at once: which role the session is running as, which policy applies to that role, and what the returned row set actually says.

PGlite changes the arithmetic. It is a real PostgreSQL build compiled to WebAssembly, so it runs in a browser tab with no server, no connection string and no data leaving the machine. The moment you can boot the actual engine, the attack becomes a button press instead of a mental simulation:

The product principle that fell out of this is simple: a verdict is derived from what the database did, never from what we expected it to do. The fixture declares an expectation; the engine reports an observation; the two are compared and any disagreement stays visible in the output instead of being smoothed over. A tool that can be caught being wrong is worth trusting when it says something is wrong.

How Kiro shaped the build

The repository keeps the whole .kiro/ directory, because for this project the way it was built is part of the artifact. Three things did the heavy lifting.

1. The spec came before the code

Under .kiro/specs/rls-seance/ the requirements define the verdict model, design.md fixes the architecture (React UI over a runner over a PGlite engine, with SQL confined to fixture files), and tasks.md breaks the work into independently verifiable phases. The spec was the thing we came back to. When a new attack vector was added, it had to land in the battery, in a fixture and in a test — and tasks.md said so before the code did.

Under .kiro/steering/ three more documents kept every session consistent: product.md(who the user is, and what "evidence, not claims" means for this product), tech.md (the fixed stack and the hard engine invariants) and structure.md (the repository layout, plus the rule that fixtures are self-contained and the UI never contains SQL).

2. Two agents that are not allowed to do each other's job

.kiro/agents/ holds two custom agents. fixture-author composes the scenarios — schema, broken policies, fixed policies, expected verdicts and the explanatory notes — following a fixed template so the fixtures stay comparable. verifier re-checks each fixture against the live engine and reports any mismatch instead of trusting the author. Authoring and verification are deliberately separate: the one that writes a fixture is not the one that signs it off, and the verifier is not even allowed to write files.

.kiro/hooks/hooks.json wires three automated checks into the workflow. Saving a fixture re-runs the fixture regression suite; saving an engine file re-runs the property invariants; a session end triggers a typecheck. A fixture that disagrees with the engine fails loudly at the moment it is created, instead of surfacing during judging.

3. Property-based tests for the invariants a table cannot cover

Beyond the per-vector unit tests, fast-check covers the properties that no enumeration of examples will reach: that no verdict path can ever be hardcoded, that row output stays capped with an explicit truncation marker, that the role is always reset after a probe, and that a mismatch between expected and observed verdicts stays visible rather than disappearing into a boolean.

Four PGlite facts that cost real time

These are the things I would have liked to know before writing the engine, and they are all reproducible in about twenty lines. Each one was measured, not assumed — the script is in the repository.

1. db.query() refuses multiple statements

The prepared-statement path will not accept a script. A fixture file that contains a CREATE TABLE, an INSERT and a CREATE POLICY fails with cannot insert multiple commands into a prepared statement. The fix is to use the exec path for scripts and the query path for individual probes:

// scripts: one call, many statements
await db.exec(schemaSql);
await db.exec(policiesSql);

// probes: one statement, parameters allowed
const result = await db.query(sql, params);

The error message points at the wrong culprit, because it does not say which statement in the batch was the problem. Splitting the script into individual calls and running them one at a time turns it into a readable failure.

2. RLS default deny really works — and that is worth verifying

With ROW LEVEL SECURITY enabled and no matching policy, the anon role reads zero rows. Not an error, not a denial — an empty result. This is the behaviour the whole security model rests on, and it is cheap to prove:

await db.exec('CREATE ROLE anon NOLOGIN');
await db.exec('GRANT USAGE ON SCHEMA public TO anon');
await db.exec('GRANT SELECT ON notes TO anon');
await db.exec('ALTER TABLE notes ENABLE ROW LEVEL SECURITY');

await db.exec('SET ROLE anon');
const rows = await db.query('SELECT * FROM notes');
// rows.rows.length === 0   -> default deny
await db.exec('RESET ROLE');

SET ROLE and RESET ROLE both work in PGlite, which is what makes role simulation possible at all. The discipline that matters is that every probe runs inside an explicit role block and the role is always reset afterwards — a probe that runs with the wrong identity produces a confident, wrong verdict, which is the single most dangerous failure mode this product could ship.

3. A permission error is evidence, not a crash

When RLS does block an operation, Postgres answers with an error (permission denied for table notes), not with an empty result set. That error is the proof of enforcement, so the engine treats it as a BLOCKED verdict with the message preserved. A runner that let that error escape would turn every correctly-protected table into a failed scan, and the tool would report noise instead of findings.

4. A failed statement rolls back the whole script — and a mistyped DROP POLICY keeps the old policy

Two more facts came from the same afternoon of measurement, and both of them are about what a test harness is allowed to lie about.

The first is a gift. db.exec() does not swallow SQL errors: a syntax error throws, a missing relation throws, a duplicate table throws. Better, a multi-statement script that fails halfway is rolled back entirely— the table created by the first statement does not survive the failure of the third. That is exactly the guarantee a fixture loader wants, so the engine loads a fixture's schema, policies and seed rows in one transaction and refuses to produce a verdict for a fixture that did not load. A verdict computed on a half-built schema would be a confident lie.

The second is a trap, and it cost more time than the other three together. DROP POLICY requires the table name:

DROP POLICY p_read;         -- syntax error, the policy stays
DROP POLICY p_read ON notes; -- correct

Get that wrong and the old policy silently survives. The nextCREATE POLICYthen fails with "already exists", the test runs against the policy you meant to remove, and the readings look impossible: permissive policies are combined with OR, so one stale USING (false) next to a freshUSING (true) still lets every row through. The engine therefore reads pg_policies after every policy change and asserts that the catalog matches the intent. Measuring the harness is as important as measuring the database.

Why a security tool wants to look like a séance

The submission category for this project was the Costume Contest, and the honest answer is that the metaphor does real work. A séance has a summoning console, a spirit-level engine chip, evidence cards that flip to a verdict, and a room that goes quiet when the answer is no. Every one of those elements is a status, a transition or a badge — decoration that carries information rather than decoration that covers it. The interface is dark and lit like candlelight, but the constraint that decided every colour was readability: the evidence table, the SQL and the row counts have to stay legible, because that is what the user came for.

Broken and fixed, side by side

Every fixture ships the policy set as it is commonly written and the corrected policy set, with notes on what went wrong, why the fix works and what risk remains. The pedagogical point is that the difference between the two is usually one clause, and that clause is invisible until you watch it move rows:

If you want the longer version of those three, with the read-only SQL that finds each one in a live project, it is in why an UPDATE policy passes because it has no WITH CHECK and what a free anon-key check can — and cannot — prove.

Where it is now

The arena is a static site: no backend, no telemetry, no account. The engine runs entirely in the tab, the fixtures ship with the repository, and a Markdown and JSON report export turns a séance into something you can paste into a security ticket. The repository is public and contains the full .kiro/ directory — steering documents, specs, hooks and both custom agents — because the method is part of the submission:

github.com/cekuu35/rls-seance · live demo (GitHub Pages)

The build continues through the Kiroween 2026 submission period, and the demo video that goes with the submission shows the whole loop: pick a fixture, summon the ghost, read the verdicts with their row evidence, flip to the corrected policy set, paste your own schema, export the report. If you have a Supabase project and want to know what the anon role can really read in it, that loop is the whole product.

Written as part of the Kiroween 2026 hackathon. The post will stay updated as the build lands.

Template bundle

Review all 20 frontend starters in one bundle

20 editable frontend starters with live demos are $79 — one payment, no subscription.

View the Bundle — $79↗