Skip to content

fix(supabase): enable row level security and fail closed on malformed filters - #38

Merged
PunGrumpy merged 6 commits into
mainfrom
fix/supabase-install-hardening
Sep 25, 2026
Merged

PunGrumpy merged 6 commits into
mainfrom
fix/supabase-install-hardening

Conversation

@PunGrumpy

Copy link
Copy Markdown
Owner

Background

The Supabase adapter targets Edge Functions and the browser. The install script and the docs said row level security "still applies", but vecstore_create_index never enabled it. On Supabase, tables in public usually get grants for anon and authenticated. A freshly created vecstore table therefore let any holder of the public anon key read, overwrite, or delete every namespace, through the RPCs or directly through /rest/v1.

Postgres also grants EXECUTE on new functions to PUBLIC, so the anon key could call the DDL functions vecstore_create_index and vecstore_drop_index.

vecstore_filter_sql built SQL by concatenation. A range leaf with no value compiled to NULL, and array_to_string dropped that NULL from an and. So and(eq("tenant", "a"), lt("price", undefined)) deleted every row with tenant = a.

Stacked on #35.

Summary

  • vecstore_create_index enables row level security on the table it creates. anon and authenticated see and change nothing until a policy exists. The service role bypasses row level security as before.
  • The install script revokes vecstore_create_index and vecstore_drop_index from public, anon, and authenticated, and grants them to service_role. A role check skips this on a plain Postgres, where those roles do not exist.
  • vecstore_filter_sql raises 22023 when a range leaf has no numeric value, and when an and, or, or not child compiles to nothing. The adapter reports 22023 as invalid_argument.
  • The Supabase page explains row level security. It includes a policy example and says how to enable row level security on tables created by earlier versions. The README and the differences page match.

Existing tables are unchanged. Users need to re-run sql/supabase.sql, and the changeset says so.

Verification

  • bun run test in packages/vecstore-sdk shows 398 pass, 0 fail.
  • New PGlite tests cover four cases:
    • A created table has row level security on.
    • anon reads no rows without a policy and reads them with one.
    • anon gets 42501 on vecstore_create_index once the Supabase roles exist.
    • A malformed range leaf raises 22023 and deletes nothing.
  • bun x tsc --noEmit exits 0. bun run check exits 0.
  • Not run against a real Supabase project. Supabase's default grants come from its documentation.

Checklist

  • Tests have been added or updated
  • Documentation has been added or updated
  • A changeset has been added for vecstore-sdk (run bun run changeset in the project root)
  • I have reviewed this pull request myself

@changeset-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63ec40e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
vecstore-sdk Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercel Bot commented Sep 25, 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 Sep 25, 2026 7:24pm UTC

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 52695892-eab4-4c18-9a72-789b85b7c891

📥 Commits

Reviewing files that changed from the base of the PR and between 0f0c636 and 63ec40e.

📒 Files selected for processing (6)
  • .changeset/supabase-install-hardening.md
  • apps/web/content/docs/providers/differences.mdx
  • apps/web/content/docs/providers/supabase.mdx
  • packages/vecstore-sdk/README.md
  • packages/vecstore-sdk/sql/supabase.sql
  • packages/vecstore-sdk/test/postgres/supabase.test.ts

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 Sep 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 63ec40e

@baymiai

baymiai Bot commented Sep 25, 2026

Copy link
Copy Markdown

Security review: nothing to raise.

Read the install script and its test. Row level security is now enabled on new tables, and the revoke step runs conditionally when Supabase roles exist. The filter validation closes the NULL‑dropping escape; the added errors raise 22023 explicitly.

Base automatically changed from fix/pgvector-index-lifecycle to main September 25, 2026 20:03
@PunGrumpy
PunGrumpy force-pushed the fix/supabase-install-hardening branch from ad15865 to 63ec40e Compare September 25, 2026 20:04
@vercel

vercel Bot commented Sep 25, 2026

Copy link
Copy Markdown

Deployment failed for project vecstore-sdk with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/pungrumpy?upgradeToPro=build-rate-limit

@PunGrumpy
PunGrumpy merged commit 0a33d23 into main Sep 25, 2026
11 of 12 checks passed
@PunGrumpy
PunGrumpy deleted the fix/supabase-install-hardening branch September 26, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant