supabase-rls-check 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. supabase_rls_check-0.2.0/LICENSE +21 -0
  2. supabase_rls_check-0.2.0/PKG-INFO +203 -0
  3. supabase_rls_check-0.2.0/README.md +176 -0
  4. supabase_rls_check-0.2.0/assets/BricolageGrotesque-Bold.ttf +0 -0
  5. supabase_rls_check-0.2.0/assets/BricolageGrotesque-OFL.txt +93 -0
  6. supabase_rls_check-0.2.0/assets/BricolageGrotesque-Regular.ttf +0 -0
  7. supabase_rls_check-0.2.0/assets/__init__.py +1 -0
  8. supabase_rls_check-0.2.0/pyproject.toml +69 -0
  9. supabase_rls_check-0.2.0/setup.cfg +4 -0
  10. supabase_rls_check-0.2.0/src/supabase_rls_check/__init__.py +52 -0
  11. supabase_rls_check-0.2.0/src/supabase_rls_check/__main__.py +7 -0
  12. supabase_rls_check-0.2.0/src/supabase_rls_check/cli.py +151 -0
  13. supabase_rls_check-0.2.0/src/supabase_rls_check/mcp_server.py +93 -0
  14. supabase_rls_check-0.2.0/src/supabase_rls_check/probe.py +196 -0
  15. supabase_rls_check-0.2.0/src/supabase_rls_check/report.py +205 -0
  16. supabase_rls_check-0.2.0/src/supabase_rls_check/rules.py +488 -0
  17. supabase_rls_check-0.2.0/src/supabase_rls_check/sql/__init__.py +1 -0
  18. supabase_rls_check-0.2.0/src/supabase_rls_check/sql/check.sql +106 -0
  19. supabase_rls_check-0.2.0/src/supabase_rls_check.egg-info/PKG-INFO +203 -0
  20. supabase_rls_check-0.2.0/src/supabase_rls_check.egg-info/SOURCES.txt +23 -0
  21. supabase_rls_check-0.2.0/src/supabase_rls_check.egg-info/dependency_links.txt +1 -0
  22. supabase_rls_check-0.2.0/src/supabase_rls_check.egg-info/entry_points.txt +2 -0
  23. supabase_rls_check-0.2.0/src/supabase_rls_check.egg-info/requires.txt +7 -0
  24. supabase_rls_check-0.2.0/src/supabase_rls_check.egg-info/top_level.txt +1 -0
  25. supabase_rls_check-0.2.0/tests/test_audit.py +442 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trung Thanh Tran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: supabase-rls-check
3
+ Version: 0.2.0
4
+ Summary: Consent-gated, read-only RLS, policy, and anonymous exposure checks for Supabase projects.
5
+ Author: Trung Thanh Tran
6
+ License: MIT
7
+ Keywords: supabase,postgresql,row-level-security,rls,postgrest,security,audit,mcp
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Database
17
+ Classifier: Topic :: Security
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: requests<3,>=2.31
22
+ Provides-Extra: mcp
23
+ Requires-Dist: mcp>=1.2; extra == "mcp"
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest<10,>=7; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # supabase-rls-check
29
+
30
+ 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.
31
+
32
+ ## Why this exists
33
+
34
+ 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.
35
+
36
+ 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.
37
+
38
+ ## Installation
39
+
40
+ Requires Python 3.11 or newer.
41
+
42
+ Not on PyPI yet. Install from the GitHub release tag:
43
+
44
+ ```bash
45
+ pipx install "git+https://github.com/Tthanh2k6/supabase-rls-check@v0.2.0"
46
+ ```
47
+
48
+ Optional Model Context Protocol (MCP) server support (`mcp>=1.2`):
49
+
50
+ ```bash
51
+ pipx install "supabase-rls-check[mcp] @ git+https://github.com/Tthanh2k6/supabase-rls-check@v0.2.0"
52
+ ```
53
+
54
+ From source for development:
55
+
56
+ ```bash
57
+ pip install -e ".[dev]"
58
+ ```
59
+
60
+ ## Three-step usage
61
+
62
+ ### 1. Export catalog metadata with `check.sql`
63
+
64
+ Print the bundled read-only SQL query (or open [`src/supabase_rls_check/sql/check.sql`](src/supabase_rls_check/sql/check.sql)):
65
+
66
+ ```bash
67
+ supabase-rls-check sql --print-sql > check.sql
68
+ ```
69
+
70
+ 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.
71
+
72
+ Validate and normalize the export:
73
+
74
+ ```bash
75
+ supabase-rls-check sql --from export.csv --out sql_results.json --i-own-this-project
76
+ ```
77
+
78
+ ### 2. Optionally verify anonymous read exposure (`probe`)
79
+
80
+ 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:
81
+
82
+ ```bash
83
+ supabase-rls-check probe \
84
+ --url https://YOUR_PROJECT.supabase.co \
85
+ --anon-key YOUR_ANON_OR_PUBLISHABLE_KEY \
86
+ --site https://your-app.example \
87
+ --out probe_results.json \
88
+ --i-own-this-project
89
+ ```
90
+
91
+ - Pass the project HTTPS origin to `--url` (not `/rest/v1/`).
92
+ - Only `anon` JWTs and `sb_publishable_` keys are accepted; `service_role` and `authenticated` tokens are rejected before any request is sent.
93
+ - If OpenAPI schema discovery is disabled on PostgREST, pass known table/view names explicitly with `--tables todos profiles`.
94
+
95
+ ### 3. Generate the standalone report and dry-run SQL template
96
+
97
+ ```bash
98
+ supabase-rls-check report \
99
+ --from sql_results.json probe_results.json \
100
+ --out-dir review_out \
101
+ --project "My Supabase App" \
102
+ --i-own-this-project
103
+ ```
104
+
105
+ This writes three files to `review_out/`:
106
+
107
+ - `report.html` — standalone, offline-ready HTML report (A4 landscape print stylesheet for **Print -> Save as PDF**)
108
+ - `report.md` — Markdown summary suitable for issues or pull requests
109
+ - `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)
110
+
111
+ Add `--lang vi` to generate Vietnamese report text.
112
+
113
+ ### Explaining a rule and optional MCP mode
114
+
115
+ Inspect the rationale, caveats, and remediation example for any rule without touching a target project:
116
+
117
+ ```bash
118
+ supabase-rls-check explain rls_disabled
119
+ supabase-rls-check explain definer_anon_exec
120
+ ```
121
+
122
+ If installed with `supabase-rls-check[mcp]`, start the local stdio MCP server:
123
+
124
+ ```bash
125
+ supabase-rls-check mcp
126
+ ```
127
+
128
+ The MCP server exposes only two local, read-only tools: `analyze_sql_export(path)` and `explain_rule(rule)`. Network probing is intentionally excluded from MCP so AI clients never handle API keys or send HTTP requests through this tool.
129
+
130
+ ## Sample report and offline demo
131
+
132
+ ![Sample HTML report preview](docs/demo-report.png)
133
+
134
+ Try the offline fictional dataset ([`demo/todo_ai.csv`](demo/todo_ai.csv) -> [`demo/report.md`](demo/report.md) and [`demo/fix.sql`](demo/fix.sql)):
135
+
136
+ ```bash
137
+ supabase-rls-check report --from demo/todo_ai.csv --out-dir demo --project "todo-ai (fictional demo)" --i-own-this-project
138
+ 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
139
+ ```
140
+
141
+ ## Eleven checks: SQL catalog rules
142
+
143
+ `check.sql` inspects PostgreSQL 15+ system catalogs and `storage.buckets` in a single read-only CTE query:
144
+
145
+ | Rule ID | Severity | Meaning |
146
+ | --- | --- | --- |
147
+ | `rls_disabled` | High | Table or partitioned table in `public` has Row Level Security disabled (`relrowsecurity = false`). |
148
+ | `policy_true` | High | Policy in `public` has an unconditional `USING (true)` or `WITH CHECK (true)` expression. |
149
+ | `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`). |
150
+ | `definer_anon_exec` | High | Non-trigger `SECURITY DEFINER` function in `public` is executable by `anon` (callable via `/rest/v1/rpc/*`). |
151
+ | `definer_search_path` | High | `SECURITY DEFINER` function in `public` has no fixed `search_path` set on the function definition. |
152
+ | `view_not_invoker` | High | View in `public` does not enable `security_invoker`, so base-table queries run with view-owner privileges. |
153
+ | `public_bucket` | Medium | Supabase Storage bucket in `storage.buckets` is marked `public = true`. |
154
+ | `public_extension` | Low | PostgreSQL extension is installed directly in `public` rather than a dedicated `extensions` schema. |
155
+ | `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. |
156
+ | `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. |
157
+ | `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. |
158
+
159
+ The three new rules add only commented guidance to `fix.sql`; they never generate automatic DDL. 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.
160
+
161
+ ### Additional checks from `probe`
162
+
163
+ When `probe` is run, two runtime checks complement the SQL catalog export:
164
+
165
+ - `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).
166
+ - `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.
167
+
168
+ Tip: pass the anon key through the `SUPABASE_ANON_KEY` environment variable instead of `--anon-key` to keep it out of shell history.
169
+
170
+ ## How it is tested
171
+
172
+ - **66 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, HTML/SQL escaping in reports, identifier quoting in `fix.sql`, English and Vietnamese output, all 11 catalog rules in reports/explanations, comment-only fixes for the new rules, and the MCP tool surface (no `probe` exposed).
173
+ - **Catalog query on a real PostgreSQL 15** (GitHub Actions): `tests/fixtures/seed_pg.sql` plants issues for all 11 rules next to safe controls. CI compares all 19 expected findings exactly, including overlapping view findings, and rejects extra or missing rows. Cases cover both JWT sources, all four authentication helpers, mixed wrapped/unwrapped calls, materialized views, 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.
174
+ - **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.
175
+
176
+ ## Ethical boundaries
177
+
178
+ - **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`.
179
+ - **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.
180
+ - **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.
181
+
182
+ ## Limitations (not a penetration test)
183
+
184
+ This tool is a configuration and anonymous-read review aid, **not a penetration test** and **not a security certification**:
185
+
186
+ - Configuration findings are review signals, not proof of exploitability; public buckets or anonymous `SELECT` policies are sometimes intentional.
187
+ - An empty finding list, HTTP `200 []`, or `401`/`403` on a single request does not prove overall safety.
188
+ - 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.
189
+ - `--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.
190
+ - `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.
191
+
192
+ ## Use it from an AI coding agent
193
+
194
+ - **Agent skill** (Claude Code, Cursor, Codex and other SKILL.md agents): [Supabase RLS Review on Agensi](https://www.agensi.io/skills/supabase-rls-review) walks the agent through the review, policy fixes and a two-user isolation test on staging.
195
+ - **MCP server listing**: [supabase-rls-check on Glama](https://glama.ai/mcp/servers/Tthanh2k6/supabase-rls-check).
196
+
197
+ ## Need a human review?
198
+
199
+ Need a manual review of RLS policies, `SECURITY DEFINER` function bodies, and two-user staging isolation? Book a fixed-scope review here: https://contra.com/s/sFUXWqOZ-supabase-security-check-for-lovable-bolt-and-v0-apps
200
+
201
+ ## License
202
+
203
+ Code is released under the [MIT License](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`](assets/BricolageGrotesque-OFL.txt)).
@@ -0,0 +1,176 @@
1
+ # supabase-rls-check
2
+
3
+ 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.
4
+
5
+ ## Why this exists
6
+
7
+ 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.
8
+
9
+ 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.
10
+
11
+ ## Installation
12
+
13
+ Requires Python 3.11 or newer.
14
+
15
+ Not on PyPI yet. Install from the GitHub release tag:
16
+
17
+ ```bash
18
+ pipx install "git+https://github.com/Tthanh2k6/supabase-rls-check@v0.2.0"
19
+ ```
20
+
21
+ Optional Model Context Protocol (MCP) server support (`mcp>=1.2`):
22
+
23
+ ```bash
24
+ pipx install "supabase-rls-check[mcp] @ git+https://github.com/Tthanh2k6/supabase-rls-check@v0.2.0"
25
+ ```
26
+
27
+ From source for development:
28
+
29
+ ```bash
30
+ pip install -e ".[dev]"
31
+ ```
32
+
33
+ ## Three-step usage
34
+
35
+ ### 1. Export catalog metadata with `check.sql`
36
+
37
+ Print the bundled read-only SQL query (or open [`src/supabase_rls_check/sql/check.sql`](src/supabase_rls_check/sql/check.sql)):
38
+
39
+ ```bash
40
+ supabase-rls-check sql --print-sql > check.sql
41
+ ```
42
+
43
+ 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.
44
+
45
+ Validate and normalize the export:
46
+
47
+ ```bash
48
+ supabase-rls-check sql --from export.csv --out sql_results.json --i-own-this-project
49
+ ```
50
+
51
+ ### 2. Optionally verify anonymous read exposure (`probe`)
52
+
53
+ 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:
54
+
55
+ ```bash
56
+ supabase-rls-check probe \
57
+ --url https://YOUR_PROJECT.supabase.co \
58
+ --anon-key YOUR_ANON_OR_PUBLISHABLE_KEY \
59
+ --site https://your-app.example \
60
+ --out probe_results.json \
61
+ --i-own-this-project
62
+ ```
63
+
64
+ - Pass the project HTTPS origin to `--url` (not `/rest/v1/`).
65
+ - Only `anon` JWTs and `sb_publishable_` keys are accepted; `service_role` and `authenticated` tokens are rejected before any request is sent.
66
+ - If OpenAPI schema discovery is disabled on PostgREST, pass known table/view names explicitly with `--tables todos profiles`.
67
+
68
+ ### 3. Generate the standalone report and dry-run SQL template
69
+
70
+ ```bash
71
+ supabase-rls-check report \
72
+ --from sql_results.json probe_results.json \
73
+ --out-dir review_out \
74
+ --project "My Supabase App" \
75
+ --i-own-this-project
76
+ ```
77
+
78
+ This writes three files to `review_out/`:
79
+
80
+ - `report.html` — standalone, offline-ready HTML report (A4 landscape print stylesheet for **Print -> Save as PDF**)
81
+ - `report.md` — Markdown summary suitable for issues or pull requests
82
+ - `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)
83
+
84
+ Add `--lang vi` to generate Vietnamese report text.
85
+
86
+ ### Explaining a rule and optional MCP mode
87
+
88
+ Inspect the rationale, caveats, and remediation example for any rule without touching a target project:
89
+
90
+ ```bash
91
+ supabase-rls-check explain rls_disabled
92
+ supabase-rls-check explain definer_anon_exec
93
+ ```
94
+
95
+ If installed with `supabase-rls-check[mcp]`, start the local stdio MCP server:
96
+
97
+ ```bash
98
+ supabase-rls-check mcp
99
+ ```
100
+
101
+ The MCP server exposes only two local, read-only tools: `analyze_sql_export(path)` and `explain_rule(rule)`. Network probing is intentionally excluded from MCP so AI clients never handle API keys or send HTTP requests through this tool.
102
+
103
+ ## Sample report and offline demo
104
+
105
+ ![Sample HTML report preview](docs/demo-report.png)
106
+
107
+ Try the offline fictional dataset ([`demo/todo_ai.csv`](demo/todo_ai.csv) -> [`demo/report.md`](demo/report.md) and [`demo/fix.sql`](demo/fix.sql)):
108
+
109
+ ```bash
110
+ supabase-rls-check report --from demo/todo_ai.csv --out-dir demo --project "todo-ai (fictional demo)" --i-own-this-project
111
+ 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
112
+ ```
113
+
114
+ ## Eleven checks: SQL catalog rules
115
+
116
+ `check.sql` inspects PostgreSQL 15+ system catalogs and `storage.buckets` in a single read-only CTE query:
117
+
118
+ | Rule ID | Severity | Meaning |
119
+ | --- | --- | --- |
120
+ | `rls_disabled` | High | Table or partitioned table in `public` has Row Level Security disabled (`relrowsecurity = false`). |
121
+ | `policy_true` | High | Policy in `public` has an unconditional `USING (true)` or `WITH CHECK (true)` expression. |
122
+ | `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`). |
123
+ | `definer_anon_exec` | High | Non-trigger `SECURITY DEFINER` function in `public` is executable by `anon` (callable via `/rest/v1/rpc/*`). |
124
+ | `definer_search_path` | High | `SECURITY DEFINER` function in `public` has no fixed `search_path` set on the function definition. |
125
+ | `view_not_invoker` | High | View in `public` does not enable `security_invoker`, so base-table queries run with view-owner privileges. |
126
+ | `public_bucket` | Medium | Supabase Storage bucket in `storage.buckets` is marked `public = true`. |
127
+ | `public_extension` | Low | PostgreSQL extension is installed directly in `public` rather than a dedicated `extensions` schema. |
128
+ | `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. |
129
+ | `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. |
130
+ | `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. |
131
+
132
+ The three new rules add only commented guidance to `fix.sql`; they never generate automatic DDL. 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.
133
+
134
+ ### Additional checks from `probe`
135
+
136
+ When `probe` is run, two runtime checks complement the SQL catalog export:
137
+
138
+ - `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).
139
+ - `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.
140
+
141
+ Tip: pass the anon key through the `SUPABASE_ANON_KEY` environment variable instead of `--anon-key` to keep it out of shell history.
142
+
143
+ ## How it is tested
144
+
145
+ - **66 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, HTML/SQL escaping in reports, identifier quoting in `fix.sql`, English and Vietnamese output, all 11 catalog rules in reports/explanations, comment-only fixes for the new rules, and the MCP tool surface (no `probe` exposed).
146
+ - **Catalog query on a real PostgreSQL 15** (GitHub Actions): `tests/fixtures/seed_pg.sql` plants issues for all 11 rules next to safe controls. CI compares all 19 expected findings exactly, including overlapping view findings, and rejects extra or missing rows. Cases cover both JWT sources, all four authentication helpers, mixed wrapped/unwrapped calls, materialized views, 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.
147
+ - **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.
148
+
149
+ ## Ethical boundaries
150
+
151
+ - **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`.
152
+ - **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.
153
+ - **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.
154
+
155
+ ## Limitations (not a penetration test)
156
+
157
+ This tool is a configuration and anonymous-read review aid, **not a penetration test** and **not a security certification**:
158
+
159
+ - Configuration findings are review signals, not proof of exploitability; public buckets or anonymous `SELECT` policies are sometimes intentional.
160
+ - An empty finding list, HTTP `200 []`, or `401`/`403` on a single request does not prove overall safety.
161
+ - 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.
162
+ - `--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.
163
+ - `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.
164
+
165
+ ## Use it from an AI coding agent
166
+
167
+ - **Agent skill** (Claude Code, Cursor, Codex and other SKILL.md agents): [Supabase RLS Review on Agensi](https://www.agensi.io/skills/supabase-rls-review) walks the agent through the review, policy fixes and a two-user isolation test on staging.
168
+ - **MCP server listing**: [supabase-rls-check on Glama](https://glama.ai/mcp/servers/Tthanh2k6/supabase-rls-check).
169
+
170
+ ## Need a human review?
171
+
172
+ Need a manual review of RLS policies, `SECURITY DEFINER` function bodies, and two-user staging isolation? Book a fixed-scope review here: https://contra.com/s/sFUXWqOZ-supabase-security-check-for-lovable-bolt-and-v0-apps
173
+
174
+ ## License
175
+
176
+ Code is released under the [MIT License](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`](assets/BricolageGrotesque-OFL.txt)).
@@ -0,0 +1,93 @@
1
+ Copyright 2022 The Bricolage Grotesque Project Authors (https://github.com/ateliertriay/bricolage)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://openfontlicense.org
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1 @@
1
+ """Bundled Bricolage Grotesque font assets (SIL OFL 1.1) for standalone HTML reports."""
@@ -0,0 +1,69 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "supabase-rls-check"
7
+ version = "0.2.0"
8
+ description = "Consent-gated, read-only RLS, policy, and anonymous exposure checks for Supabase projects."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { text = "MIT" }
12
+ authors = [
13
+ { name = "Trung Thanh Tran" },
14
+ ]
15
+ keywords = [
16
+ "supabase",
17
+ "postgresql",
18
+ "row-level-security",
19
+ "rls",
20
+ "postgrest",
21
+ "security",
22
+ "audit",
23
+ "mcp",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Environment :: Console",
28
+ "Intended Audience :: Developers",
29
+ "License :: OSI Approved :: MIT License",
30
+ "Operating System :: OS Independent",
31
+ "Programming Language :: Python :: 3",
32
+ "Programming Language :: Python :: 3.11",
33
+ "Programming Language :: Python :: 3.12",
34
+ "Topic :: Database",
35
+ "Topic :: Security",
36
+ ]
37
+ dependencies = [
38
+ "requests>=2.31,<3",
39
+ ]
40
+
41
+ [project.optional-dependencies]
42
+ mcp = [
43
+ "mcp>=1.2",
44
+ ]
45
+ dev = [
46
+ "pytest>=7,<10",
47
+ ]
48
+
49
+ [project.scripts]
50
+ supabase-rls-check = "supabase_rls_check.cli:main"
51
+
52
+ [tool.setuptools]
53
+ packages = [
54
+ "supabase_rls_check",
55
+ "supabase_rls_check.sql",
56
+ "supabase_rls_check.assets",
57
+ ]
58
+
59
+ [tool.setuptools.package-dir]
60
+ "" = "src"
61
+ "supabase_rls_check.assets" = "assets"
62
+
63
+ [tool.setuptools.package-data]
64
+ "supabase_rls_check.sql" = ["*.sql"]
65
+ "supabase_rls_check.assets" = ["*.ttf", "*.txt"]
66
+
67
+ [tool.pytest.ini_options]
68
+ testpaths = ["tests"]
69
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,52 @@
1
+ """Consent-gated, read-only Supabase RLS, policy, and anonymous exposure checks."""
2
+ from __future__ import annotations
3
+
4
+ __version__ = '0.2.0'
5
+
6
+ from .cli import build_parser, main
7
+ from .probe import Scripts, fetch, jwt_role, probe, scan_site, validate_url
8
+ from .report import deduplicate_and_sort_findings, fix_sql, quote_identifier, report
9
+ from .rules import (
10
+ JWT,
11
+ NOTES,
12
+ RULE_GUIDES,
13
+ RULES,
14
+ SEVERITIES,
15
+ SQL_RULES,
16
+ VI_SEVERITIES,
17
+ clean,
18
+ explain_rule,
19
+ finding,
20
+ get_check_sql_path,
21
+ load_result,
22
+ read_check_sql,
23
+ )
24
+
25
+ __all__ = [
26
+ 'JWT',
27
+ 'NOTES',
28
+ 'RULES',
29
+ 'RULE_GUIDES',
30
+ 'SEVERITIES',
31
+ 'SQL_RULES',
32
+ 'Scripts',
33
+ 'VI_SEVERITIES',
34
+ '__version__',
35
+ 'build_parser',
36
+ 'clean',
37
+ 'deduplicate_and_sort_findings',
38
+ 'explain_rule',
39
+ 'fetch',
40
+ 'finding',
41
+ 'fix_sql',
42
+ 'get_check_sql_path',
43
+ 'jwt_role',
44
+ 'load_result',
45
+ 'main',
46
+ 'probe',
47
+ 'quote_identifier',
48
+ 'read_check_sql',
49
+ 'report',
50
+ 'scan_site',
51
+ 'validate_url',
52
+ ]
@@ -0,0 +1,7 @@
1
+ """Allow running `python -m supabase_rls_check`."""
2
+ from __future__ import annotations
3
+
4
+ from .cli import main
5
+
6
+ if __name__ == '__main__':
7
+ raise SystemExit(main())