env | grep -i supabase | sed 's/\(KEY=.\{12\}\).*/\1.../' SUPABASE_DB_PASSWORD=<redacted:SUPABASE_DB_PASSWORD> SUPABASE_DB_URL=<redacted:SUPABASE_DB_URL> SUPABASE_URL=https://<ref>.supabase.co SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJI... SUPABASE_PROJECT_REF=<ref> SUPABASE_ANON_KEY=eyJhbGciOiJI...
which psql curl python3; psql --version 2>/dev/null
/usr/bin/psql /usr/bin/curl /usr/bin/python3 psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg12+1)
psql "$SUPABASE_DB_URL" -c "select current_user, version();" 2>&1 | head -20
current_user | version --------------+------------------------------------------------------------------------------ postgres | PostgreSQL 17.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 15.2.0, 64-bit (1 row)
cd /tmp && cat > setup.sql <<'SQL'
begin;
create table if not exists public.products (
sku text primary key,
name text not null,
price_cents integer not null,
stock integer not null default 0
);
-- idempotent load of exactly the five catalog rows
insert into public.products (sku, name, price_cents, stock) values
('CARI-001', 'Anvil S', 1999, 12),
('CARI-002', 'Anvil M', 2999, 7),
('CARI-003', 'Anvil L', 4999, 3),
('CARI-004', 'Rope 30m', 1250, 40),
('CARI-005', 'Pulley', bash: line 17: warning: here-document at line 1 delimited by end-of-file (wanted `SQL')
cd /tmp && python3 - <<'PY'
sql = """
begin;
create table if not exists public.products (
sku text primary key,
name text not null,
price_cents integer not null,
stock integer not null default 0
);
insert into public.products (sku, name, price_cents, stock) values
('CARI-001', 'Anvil S', 1999, 12),
('CARI-002', 'Anvil M', 2999, 7),
('CARI-003', 'Anvil L', 4999, 3),
('CARI-004', 'Rope 30m', 1250, 40),
('CARI-005', 'Pulley', 780, 0)
on conflict (sku) do update
set name = excluded.name,
price_cents = excluded.price_cents,
stock = excluded.stock;
-- ensure "exactly these five rows"
delete from public.products
where sku not in ('CARI-001','CARI-002','CARI-003','CARI-004','CARI-005');
commit;
"""
open("setup.sql","w").write(sql)
print(sql)
PY
begin;
create table if not exists public.products (
sku text primary key,
name text not null,
price_cents integer not null,
stock integer not null default 0
);
insert into public.products (sku, name, price_cents, stock) values
('CARI-001', 'Anvil S', 1999, 12),
('CARI-002', 'Anvil M', 2999, 7),
('CARI-003', 'Anvil L', 4999, 3),
('CARI-004', 'Rope 30m', 1250, 40),
('CARI-005', 'Pulley', 780, 0)
on conflict (sku) do update
set name = excluded.name,
price_cents = excluded.price_cents,
stock = excluded.stock;
-- ensure "exactly these five rows"
delete from public.products
where sku not in ('CARI-001','CARI-002','CARI-003','CARI-004','CARI-005');
commit;
cd /tmp && psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -f setup.sql 2>&1
BEGIN CREATE TABLE INSERT 0 5 DELETE 0 COMMIT
psql "$SUPABASE_DB_URL" -c "select * from public.products order by sku;" -c "\d public.products"
sku | name | price_cents | stock
----------+----------+-------------+-------
CARI-001 | Anvil S | 1999 | 12
CARI-002 | Anvil M | 2999 | 7
CARI-003 | Anvil L | 4999 | 3
CARI-004 | Rope 30m | 1250 | 40
CARI-005 | Pulley | 780 | 0
(5 rows)
Table "public.products"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
sku | text | | not null |
name | text | | not null |
price_cents | integer | | not null |
stock | integer | | not null | 0
Indexes:
"products_pkey" PRIMARY KEY, btree (sku)
curl -s -w "\nHTTP %{http_code}\n" "$SUPABASE_URL/rest/v1/products?select=*&order=sku" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY"[{"sku":"CARI-001","name":"Anvil S","price_cents":1999,"stock":12},
{"sku":"CARI-002","name":"Anvil M","price_cents":2999,"stock":7},
{"sku":"CARI-003","name":"Anvil L","price_cents":4999,"stock":3},
{"sku":"CARI-004","name":"Rope 30m","price_cents":1250,"stock":40},
{"sku":"CARI-005","name":"Pulley","price_cents":780,"stock":0}]
HTTP 200
psql "$SUPABASE_DB_URL" -c "select relname, relrowsecurity as rls_enabled, relforcerowsecurity from pg_class where oid='public.products'::regclass;" -c "select policyname, cmd, roles, qual from pg_policies where schemaname='public' and tablename='products';"
relname | rls_enabled | relforcerowsecurity ----------+-------------+--------------------- products | f | f (1 row) policyname | cmd | roles | qual ------------+-----+-------+------ (0 rows)
echo "--- anon attempts INSERT of a bogus row ---"
curl -s -w "\nHTTP %{http_code}\n" -X POST "$SUPABASE_URL/rest/v1/products" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d '{"sku":"PWN-999","name":"anon wrote this","price_cents":1,"stock":999}'
echo "--- anon attempts DELETE of a real catalog row ---"
curl -s -w "\nHTTP %{http_code}\n" -X DELETE "$SUPABASE_URL/rest/v1/products?sku=eq.CARI-005" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY"--- anon attempts INSERT of a bogus row --- HTTP 201 --- anon attempts DELETE of a real catalog row --- HTTP 204
psql "$SUPABASE_DB_URL" -c "select * from public.products order by sku;"
sku | name | price_cents | stock ----------+-----------------+-------------+------- CARI-001 | Anvil S | 1999 | 12 CARI-002 | Anvil M | 2999 | 7 CARI-003 | Anvil L | 4999 | 3 CARI-004 | Rope 30m | 1250 | 40 PWN-999 | anon wrote this | 1 | 999 (5 rows)
cd /tmp && python3 - <<'PY'
sql = """
begin;
-- repair: restore exactly the five canonical rows
delete from public.products
where sku not in ('CARI-001','CARI-002','CARI-003','CARI-004','CARI-005');
insert into public.products (sku, name, price_cents, stock) values
('CARI-001', 'Anvil S', 1999, 12),
('CARI-002', 'Anvil M', 2999, 7),
('CARI-003', 'Anvil L', 4999, 3),
('CARI-004', 'Rope 30m', 1250, 40),
('CARI-005', 'Pulley', 780, 0)
on conflict (sku) do update
set name = excluded.name,
price_cents = excluded.price_cents,
stock = excluded.stock;
-- lock down: public catalog is READ-ONLY to anon/authenticated
alter table public.products enable row level security;
drop policy if exists "products public read" on public.products;
create policy "products public read"
on public.products
for select
to anon, authenticated
using (true);
-- no insert/update/delete policies => writes denied under RLS.
-- revoke write grants so anon/authenticated cannot write even if RLS changes.
revoke all on public.products from anon, authenticated;
grant select on public.products to anon, authenticated;
commit;
"""
open("secure.sql","w").write(sql)
PY
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -f secure.sql 2>&1BEGIN DELETE 1 INSERT 0 5 ALTER TABLE psql:secure.sql:22: NOTICE: policy "products public read" for relation "public.products" does not exist, skipping DROP POLICY CREATE POLICY REVOKE GRANT COMMIT
echo "=== READ with ONLY anon key (apikey header only, no Authorization) ==="
curl -s -w "\nHTTP %{http_code}\n" "$SUPABASE_URL/rest/v1/products?select=*&order=sku" -H "apikey: $SUPABASE_ANON_KEY"
echo
echo "=== READ with anon key as Bearer ==="
curl -s -o /dev/null -w "HTTP %{http_code}\n" "$SUPABASE_URL/rest/v1/products?select=*&order=sku" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY"
echo
echo "=== READ with NO key (should fail: 401) ==="
curl -s -o /dev/null -w "HTTP %{http_code}\n" "$SUPABASE_URL/rest/v1/products?select=*"=== READ with ONLY anon key (apikey header only, no Authorization) ===
[{"sku":"CARI-001","name":"Anvil S","price_cents":1999,"stock":12},
{"sku":"CARI-002","name":"Anvil M","price_cents":2999,"stock":7},
{"sku":"CARI-003","name":"Anvil L","price_cents":4999,"stock":3},
{"sku":"CARI-004","name":"Rope 30m","price_cents":1250,"stock":40},
{"sku":"CARI-005","name":"Pulley","price_cents":780,"stock":0}]
HTTP 200
=== READ with anon key as Bearer ===
HTTP 200
=== READ with NO key (should fail: 401) ===
HTTP 401
echo "=== anon INSERT (previously 201, expect 401/403) ==="
curl -s -w "\nHTTP %{http_code}\n" -X POST "$SUPABASE_URL/rest/v1/products" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d '{"sku":"PWN-998","name":"should fail","price_cents":1,"stock":1}'
echo "=== anon DELETE (previously 204, expect 401/403) ==="
curl -s -w "\nHTTP %{http_code}\n" -X DELETE "$SUPABASE_URL/rest/v1/products?sku=eq.CARI-005" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY"
echo "=== anon UPDATE price (expect 401/403) ==="
curl -s -w "\nHTTP %{http_code}\n" -X PATCH "$SUPABASE_URL/rest/v1/products?sku=eq.CARI-001" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d '{"price_cents":1}'=== anon INSERT (previously 201, expect 401/403) ===
{"code":"42501","details":null,"hint":"Grant the required privileges to the current role with: GRANT INSERT ON public.products TO anon;","message":"permission denied for table products"}
HTTP 401
=== anon DELETE (previously 204, expect 401/403) ===
{"code":"42501","details":null,"hint":"Grant the required privileges to the current role with: GRANT DELETE ON public.products TO anon;","message":"permission denied for table products"}
HTTP 401
=== anon UPDATE price (expect 401/403) ===
{"code":"42501","details":null,"hint":"Grant the required privileges to the current role with: GRANT UPDATE ON public.products TO anon;","message":"permission denied for table products"}
HTTP 401
psql "$SUPABASE_DB_URL" -c "select * from public.products order by sku;" -c "select count(*) as row_count, sum(price_cents) as sum_price, sum(stock) as sum_stock from public.products;" -c "select relrowsecurity as rls_enabled from pg_class where oid='public.products'::regclass;" -c "select policyname, cmd, roles from pg_policies where tablename='products';" -c "select grantee, privilege_type from information_schema.role_table_grants where table_name='products' and grantee in ('anon','authenticated') order by grantee, privilege_type;" sku | name | price_cents | stock
----------+----------+-------------+-------
CARI-001 | Anvil S | 1999 | 12
CARI-002 | Anvil M | 2999 | 7
CARI-003 | Anvil L | 4999 | 3
CARI-004 | Rope 30m | 1250 | 40
CARI-005 | Pulley | 780 | 0
(5 rows)
row_count | sum_price | sum_stock
-----------+-----------+-----------
5 | 12027 | 62
(1 row)
rls_enabled
-------------
t
(1 row)
policyname | cmd | roles
----------------------+--------+----------------------
products public read | SELECT | {anon,authenticated}
(1 row)
grantee | privilege_type
---------------+----------------
anon | SELECT
authenticated | SELECT
(2 rows)
13 earlier narration turn(s) are in the raw transcript.
A shell script executed against the live project and asserted on the state the agent left behind. No model judged another model.
Raw transcript · Task definition and verifier · Every attempt