Skip to content

test(supabase): check the sql security claims, then drop the header - #65

Merged
PunGrumpy merged 2 commits into
mainfrom
test/supabase-sql-security-claims
Oct 23, 2026
Merged

PunGrumpy merged 2 commits into
mainfrom
test/supabase-sql-security-claims

Conversation

@PunGrumpy

@PunGrumpy PunGrumpy commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Background

sql/supabase.sql ships in the npm package and opened with a seven-line comment. The repository keeps no comments in code, and every sentence of this one is already in the docs. The install command is on the Supabase page and in the README, and the security model is in that page's "Which key to use" section. Two of its sentences were security promises that no test checked:

  • "Every function runs with the privileges of the caller." All 11 functions declare security invoker, but nothing failed if one became security definer. A definer function runs as its owner. When that owner bypasses row level security, as a superuser or the table's owner does, anon reads every row through it.
  • "The anon and authenticated roles read and write nothing until you add one [a policy]." The suite checked only a direct select count(*) as anon. Writes, the authenticated role, and the adapter's calls through the vecstore_* functions went unchecked.

Summary

Two commits:

  1. test(supabase): check that the sql functions honour row level security:
    • A catalog test fails if any vecstore_* function is security definer. A function added later is covered without editing the test.
    • A test.each over anon and authenticated runs query, fetch, upsert, and delete through the adapter against a secured table that has table grants and no policy. It expects empty reads, an unauthorized upsert, and a delete that removes nothing.
    • The asAnon helper becomes asRole(role, fn).
  2. chore(sql): drop the header that repeats the supabase docs deletes the comment and the blank line after it. No function body changes, so Supabase users do not need to re-run the file.

No changeset. Users see no behavior change, and the gate counts only src/ and package.json.

Verification

  • bun test --timeout 30000 test/postgres/supabase.test.ts: 26 pass (23 before). bun run test in the package: 636 pass, 0 fail.
  • Each claim fails the tests when broken, run on PGlite:
    • vecstore_fetch switched to security definer fails the catalog test and both role tests.
    • The enable row level security statement replaced with null fails both role tests and the two existing row level security tests.
  • bun run check and the package typecheck pass.

This runs on PGlite (Postgres 18 with pgvector), not on a hosted Supabase project.

Checklist

  • Tests have been added or updated
  • Documentation has been added or updated (the docs already state both claims)
  • A changeset has been added for vecstore-sdk (tests and a SQL comment only)
  • I have reviewed this pull request myself

Summary by CodeRabbit

  • Tests
    • Expanded checks for Supabase access behavior across anonymous and authenticated roles, including row visibility before and after a read policy is applied.
    • Added verification of expected query, fetch, upsert, and delete outcomes, as well as function security settings and permissions.
    • These updates strengthen coverage of existing access-control behavior; they do not change application functionality.

@PunGrumpy PunGrumpy added the refactor Changes structure or removes dead code without changing behavior label Oct 22, 2026
@changeset-bot

changeset-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a909519

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
vecstore-sdk Ready Ready Preview Oct 23, 2026 2:22am UTC

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f50c90cb-0d66-4720-b3e7-0bcff6d7d6de
📥 Commits

Reviewing files that changed from the base of the PR and between f71e62b and a909519.

📒 Files selected for processing: 2
  • packages/vecstore-sdk/sql/supabase.sql
  • packages/vecstore-sdk/test/postgres/supabase.test.ts
+--------------------------------+
| Overly attached code reviewer. |
+--------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/vecstore-sdk@65

commit: a909519

The install script declares security invoker on every function and
enables row level security on the tables createIndex makes, but nothing
failed if either stopped being true. A security definer function runs
as its owner, and when that owner bypasses row level security, as a
superuser or the table's owner does, anon reads every row through it.

One test reads pg_proc and fails if any vecstore_ function is security
definer, so a new function is covered without editing the test. A second
test, run for anon and authenticated, calls query, fetch, upsert, and
delete through the adapter against a secured table that has table
grants and no policy. It expects empty reads, an unauthorized upsert,
and a delete that removes nothing. The anon check before this read the
table directly and never went through the vecstore_ functions.

I saw both claims fail on purpose. Changing vecstore_fetch to security
definer fails the catalog test and both role tests. Replacing the alter
table statement that enables row level security fails both role tests
and the two existing row level security tests.
The install command and the note that the script runs once per project
are in the Supabase docs page and the README. The security model, that
every function runs as the caller and that created tables have row level
security with no policy, is in the "Which key to use" section of the
same page. The previous commit made those two security sentences tests,
so the comment no longer carries anything the docs and the suite do not.
@PunGrumpy
PunGrumpy force-pushed the test/supabase-sql-security-claims branch from c788342 to a909519 Compare October 23, 2026 02:22
@PunGrumpy
PunGrumpy merged commit 28ad8e2 into main Oct 23, 2026
12 of 14 checks passed

This branch was successfully deployed

1 active deployment
Preview — a9095191 Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Changes structure or removes dead code without changing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant