Skip to main content

supabase-rls-check

PyPI Glama MCP server

Consent-gated, read-only configuration and anonymous-exposure checks for Supabase projects (PostgreSQL 15+, Python 3.11+). No database password or service_role key required.

Why this exists

Supabase applications intentionally ship a public anon JWT or sb_publishable_ key inside browser JavaScript bundles so client code can talk directly to PostgREST (/rest/v1/) and Storage. Because every visitor can read that key from DevTools, access control depends directly on PostgreSQL Row Level Security (RLS), policy expressions, table/function grants, view options, and Storage bucket visibility—along with never bundling a service_role token in frontend code.

During rapid prototyping, AI-assisted schema generation, or manual migrations, it is easy to leave a table in public without RLS, keep a temporary USING (true) policy, or forget that PostgreSQL grants EXECUTE to PUBLIC on new SECURITY DEFINER functions exposed at /rest/v1/rpc/*. supabase-rls-check helps project owners review those patterns safely without modifying data or saving table rows.

Installation

Requires Python 3.11 or newer.

pipx install supabase-rls-check      # or: uvx supabase-rls-check --help

Optional Model Context Protocol (MCP) server support (mcp>=1.2):

pipx install "supabase-rls-check[mcp]"

From source for development:

pip install -e ".[dev]"

Three-step usage

1. Export catalog metadata with check.sql

Print the bundled read-only SQL query (or open src/supabase_rls_check/sql/check.sql):

supabase-rls-check sql --print-sql > check.sql

Paste check.sql into the Supabase SQL Editor, adjust the sensitive-table name pattern if needed, run the SELECT, and export the single result set as CSV or JSON (rule,schema_name,object_name,policy_name). Only catalog metadata is queried—never application rows.

Validate and normalize the export:

supabase-rls-check sql --from export.csv --out sql_results.json --i-own-this-project

2. Optionally verify anonymous read exposure (probe)

Check what an unauthenticated caller can actually read with your public anon JWT or sb_publishable_ key, and optionally inspect your frontend origin for leaked service_role JWTs:

supabase-rls-check probe \
  --url https://YOUR_PROJECT.supabase.co \
  --anon-key YOUR_ANON_OR_PUBLISHABLE_KEY \
  --site https://your-app.example \
  --out probe_results.json \
  --i-own-this-project
  • Pass the project HTTPS origin to --url (not /rest/v1/).
  • Only anon JWTs and sb_publishable_ keys are accepted; service_role and authenticated tokens are rejected before any request is sent.
  • If OpenAPI schema discovery is disabled on PostgREST, pass known table/view names explicitly with --tables todos profiles.

3. Generate the standalone report and dry-run SQL template

supabase-rls-check report \
  --from sql_results.json probe_results.json \
  --out-dir review_out \
  --project "My Supabase App" \
  --i-own-this-project

This writes three files to review_out/:

  • report.html — standalone, offline-ready HTML report (A4 landscape print stylesheet for Print -> Save as PDF)
  • report.md — Markdown summary suitable for issues or pull requests
  • fix.sql — commented review template wrapped in BEGIN; ... ROLLBACK; (never executed by this tool; replace user_id with your real ownership column and test on staging first)

Add --lang vi to generate Vietnamese report text.

Scan your app for secrets in public env variables

Scan a local project directory (read-only, local files only, no network) for service_role JWTs, sb_secret_ keys, and live API secrets exposed through client-bundled environment variables (EXPO_PUBLIC_, NEXT_PUBLIC_, VITE_, REACT_APP_, PUBLIC_, NUXT_PUBLIC_) or hardcoded in client source files:

supabase-rls-check scan-env . --out envscan.json
supabase-rls-check report \
  --from sql_results.json envscan.json \
  --out-dir review_out \
  --project "My Supabase App" \
  --i-own-this-project
  • Inspects .env, .env.*, app.json, app.config.*, eas.json, and client source files (*.js, *.jsx, *.ts, *.tsx, *.mjs, *.cjs, *.vue, *.svelte), skipping node_modules, .git, virtualenvs, build outputs, binary files, and files over 2 MB.
  • Emits public_env_service_role (Critical), public_env_secret_key (High), and service_role_in_client_code (Critical, excluding supabase/functions/, server/, api/, scripts/, and backend/).
  • Requires no consent flag because it only reads local files, and always masks secret values (first 6 chars + … + last 4).

Explaining a rule and optional MCP mode

Inspect the rationale, caveats, and remediation example for any rule without touching a target project:

supabase-rls-check explain rls_disabled
supabase-rls-check explain definer_anon_exec

If installed with supabase-rls-check[mcp], start the local stdio MCP server:

supabase-rls-check mcp

The MCP server exposes only three local, read-only tools: analyze_sql_export(path), explain_rule(rule), and scan_public_env(path). Network probing is intentionally excluded from MCP so AI clients never handle API keys or send HTTP requests through this tool.

Run it in CI (GitHub Action)

The repository is also a composite GitHub Action. It runs the same read-only check.sql with psql (inside a default_transaction_read_only session), writes report.md, report.html and fix.sql, adds a summary table to the job page, and fails the job when a finding is at or above fail-on.

Unlike the three-step flow above, this needs a Postgres connection string. Keep it in a repository secret and point it at a staging project or a read-only role.

name: RLS check
on: [pull_request]
jobs:
  rls:
    runs-on: ubuntu-latest
    steps:
      - uses: Tthanh2k6/supabase-rls-check@main
        with:
          database-url: ${{ secrets.STAGING_DATABASE_URL }}
          i-own-this-project: "true"
          fail-on: High        # Critical, High, Medium, Low or none
      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: rls-report
          path: rls-report/

Outputs: findings (total) and failing (at or above fail-on). The action refuses to run unless i-own-this-project is "true".

Sample report and offline demo

Sample HTML report preview

Try the offline fictional dataset (demo/todo_ai.csv -> demo/report.md and demo/fix.sql):

supabase-rls-check report --from demo/todo_ai.csv --out-dir demo --project "todo-ai (fictional demo)" --i-own-this-project
supabase-rls-check report --from demo/todo_ai.csv --out-dir demo/vi --project "todo-ai (dữ liệu giả)" --lang vi --i-own-this-project

Fourteen checks: SQL catalog rules

check.sql inspects PostgreSQL 15+ system catalogs and storage.buckets in a single read-only CTE query:

Rule ID Severity Meaning
rls_disabled High Table or partitioned table in public has Row Level Security disabled (relrowsecurity = false).
policy_true High Policy in public has an unconditional USING (true) or WITH CHECK (true) expression.
sensitive_anon_policy High Policy granted to anon or public on a table matching common sensitive names (user, profile, order, payment, invoice, customer, patient, secret, token, document) or tagged with a pii table comment.
definer_anon_exec High Non-trigger SECURITY DEFINER function in public is executable by anon (callable via /rest/v1/rpc/*).
definer_search_path High SECURITY DEFINER function in public has no fixed search_path set on the function definition.
view_not_invoker High View in public does not enable security_invoker, so base-table queries run with view-owner privileges.
public_bucket Medium Supabase Storage bucket in storage.buckets is marked public = true.
public_bucket_listable Medium Public Storage bucket in storage.buckets also has an anon or public SELECT (or ALL) policy on storage.objects matching that bucket id or true, letting anyone list every file name in the bucket through the API.
public_extension Low PostgreSQL extension is installed directly in public rather than a dedicated extensions schema.
policy_user_metadata High Policy in public reads user-editable user_metadata from auth.jwt() or request.jwt.claims. Use server-managed app_metadata or a protected authorization table.
policy_auth_per_row Low Policy on an RLS-enabled table in public calls auth.uid(), auth.jwt(), auth.role(), or current_setting() without a sub-select. Performance finding: use (select auth.uid()) for row-independent calls.
auth_users_exposed Critical Public view directly depends on auth.users, allows anon or authenticated to SELECT, and is materialized or lacks security_invoker. Drop it or harden a regular view and revoke access; publish only needed profile columns from a separate table.
matview_api_exposed High Materialized view or foreign table in public allows anon or authenticated to SELECT. Row Level Security does not apply to materialized views, so every row is readable through the Data API. Revoke SELECT from anon/authenticated and serve the data through a regular view with security_invoker = true, or move it to a schema the API does not expose.
policy_any_authenticated Medium Policy in public only checks that the caller is signed in (auth.role() = 'authenticated' or auth.uid() IS NOT NULL), giving every signed-in account the same access. Tie the row to (select auth.uid()) = user_id or a membership table, or document intentional shared access in a table comment.

The six newer rules (policy_user_metadata, policy_auth_per_row, auth_users_exposed, matview_api_exposed, public_bucket_listable, and policy_any_authenticated) add only commented guidance to fix.sql; they never generate automatic DDL. You can also tag tables with COMMENT ON TABLE public.x IS 'pii' so sensitive_anon_policy does not depend on table naming (idea from a reader comment on the dev.to article). Overlap is intentional: a materialized view over auth.users produces both auth_users_exposed and matview_api_exposed (same as regular views over auth.users overlap with view_not_invoker, and listable public buckets produce both public_bucket and public_bucket_listable). Policy expression checks are heuristics over PostgreSQL's deparsed SQL. The authentication performance check recognizes directly SELECT-wrapped calls; complex subqueries need manual review. The Auth exposure check follows direct dependencies and returns no findings when auth.users is absent.

Additional checks from probe

When probe is run, two runtime checks complement the SQL catalog export:

  • anon_readable (High) — PostgREST returned visible rows for an unauthenticated GET/HEAD request using the anon or publishable key (records column names and visible row count only).
  • service_role_exposed (Critical) — A JWT whose payload decodes to role = "service_role" was found in frontend HTML or a directly linked same-origin script.

Tip: pass the anon key through the SUPABASE_ANON_KEY environment variable instead of --anon-key to keep it out of shell history.

How it is tested

  • 89 unit tests (pytest): consent flag enforcement, GET/HEAD-only probing with no redirects, response size limits, row values and keys never written to disk, service_role JWT detection, local scan-env secret detection with masked values, HTML/SQL escaping in reports, identifier quoting in fix.sql, English and Vietnamese output, all 14 catalog rules in reports/explanations, comment-only fixes for the newer rules, and the MCP tool surface (no probe exposed).
  • Catalog query on a real PostgreSQL 15 (GitHub Actions): tests/fixtures/seed_pg.sql plants issues for all 14 rules next to safe controls. CI compares all 26 expected findings exactly, including overlapping view/matview and bucket findings, and rejects extra or missing rows. Cases cover both JWT sources, all four authentication helpers, mixed wrapped/unwrapped calls, signed-in-only policies, materialized views, public bucket listing policies, pii table comments, role grants, and safe app_metadata/sub-select/invoker controls. The query runs with read-only transactions, including separate cases without an auth schema or auth.users table.
  • Abuse cases checked by hand: running any command without --i-own-this-project exits before touching the network; passing a service_role key to probe is refused; the MCP server cannot reach the network.

Ethical boundaries

  • Authorization required: Only scan projects you own or have explicit written authorization to test, including any --site frontend domain. Commands that process project exports or targets require --i-own-this-project or --have-written-consent.
  • Strictly read-only: probe sends GET and HEAD requests only—never POST, PUT, PATCH, DELETE, or RPC invocations. HTTP redirects are not followed, trust_env is disabled, responses are capped at 5 MB, and timeouts are fixed at 20 seconds.
  • No customer row storage: probe requests at most limit=1 row per relation in memory, extracts column names, discards row values immediately, and strips JWT patterns ([REDACTED]) from metadata and error messages.

Limitations (not a penetration test)

This tool is a configuration and anonymous-read review aid, not a penetration test and not a security certification:

  • Configuration findings are review signals, not proof of exploitability; public buckets or anonymous SELECT policies are sometimes intentional.
  • An empty finding list, HTTP 200 [], or 401/403 on a single request does not prove overall safety.
  • Does not test authenticated cross-user / multi-tenant isolation, INSERT/UPDATE/DELETE permissions, SQL function bodies, Edge Functions, custom Auth hooks, or complex storage.objects policy combinations.
  • --site inspects only the entry HTML document and up to 20 directly linked same-origin HTTPS <script src> files. Dynamically imported chunks, source maps, split/obfuscated tokens, and non-JWT secret formats (sb_secret_*) are outside its coverage, and JWT signatures are not verified.
  • fix.sql is a starting template ending in ROLLBACK;. Adding a new permissive policy does not override existing broad permissive policies—always export existing policies/grants and test two-user isolation on staging before committing changes.

Use it from an AI coding agent

Need a human review?

Need a manual review of RLS policies, SECURITY DEFINER function bodies, and two-user staging isolation? Book a fixed-scope review (from $69, report plus a ROLLBACK-wrapped fix script):

License

Code is released under the MIT License (Copyright (c) 2026 Trung Thanh Tran). Bundled Bricolage Grotesque report fonts in assets/ are licensed under the SIL Open Font License 1.1 (assets/BricolageGrotesque-OFL.txt).

Metadata

Release files for supabase-rls-check 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for supabase-rls-check 0.4.0
File Size Uploaded Provenance Actions
supabase_rls_check-0.4.0.tar.gz 150.2 kB With provenance Details for supabase_rls_check-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for supabase-rls-check 0.4.0
File Interpreter ABI Platform Actions
supabase_rls_check-0.4.0-py3-none-any.whl Python 3 none any Details for supabase_rls_check-0.4.0-py3-none-any.whl

Total release size: 290.4 kB

Release files / supabase_rls_check-0.4.0.tar.gz

Download URL supabase_rls_check-0.4.0.tar.gz
Size 150.2 kB
Tags Source
SHA-256 checksum
How to use checksums
58fc2b0fba0248055b77bc66963b36d2170b49812fd331ad7677781242b3a683
BLAKE2b-256 checksum
How to use checksums
cee6fb4fdd2cb53d9e8c595f3008c3fa8dad7473a49e4189a7f95f81c7502295
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / supabase_rls_check-0.4.0-py3-none-any.whl

Download URL supabase_rls_check-0.4.0-py3-none-any.whl
Size 140.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c9125efd9a9619234e5a7ebacc2a9aebbfa2d374fa02192dc3c5c20c73d677b
BLAKE2b-256 checksum
How to use checksums
8af455ca2ed7d93481cc7420f1f3aea75fd68143f6ddb22ab74d6b1a6431155d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for supabase-rls-check 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for supabase_rls_check-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page