rattlecheck 0.0.0-stage → 0.1.0
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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +173 -2
- package/bin/rattlecheck.js +12 -0
- package/docs/rules/RC001.md +40 -0
- package/docs/rules/RC002.md +35 -0
- package/docs/rules/RC003.md +25 -0
- package/docs/rules/RC004.md +23 -0
- package/docs/rules/RC005.md +32 -0
- package/docs/rules/RC101.md +31 -0
- package/integrations/AGENTS.md +11 -0
- package/integrations/claude-code/rattlecheck/SKILL.md +42 -0
- package/integrations/cursor/rattlecheck.mdc +13 -0
- package/package.json +45 -4
- package/src/cli.js +158 -0
- package/src/config.js +62 -0
- package/src/live/catalog.js +43 -0
- package/src/live/env.js +102 -0
- package/src/live/ownership.js +72 -0
- package/src/live/probe.js +80 -0
- package/src/live/rc101-anon-readable.js +38 -0
- package/src/mcp/server.js +163 -0
- package/src/model.js +723 -0
- package/src/report/badge-svg.js +26 -0
- package/src/report/card-svg.js +50 -0
- package/src/report/grade.js +26 -0
- package/src/report/sarif.js +44 -0
- package/src/report/terminal.js +105 -0
- package/src/rules/index.js +14 -0
- package/src/rules/supabase/rc001-table-without-rls.js +54 -0
- package/src/rules/supabase/rc002-definer-callable-by-anon.js +37 -0
- package/src/rules/supabase/rc003-definer-search-path.js +33 -0
- package/src/rules/supabase/rc004-invoker-trigger-locked-table.js +49 -0
- package/src/rules/supabase/rc005-permissive-true-policy.js +81 -0
- package/src/scan.js +167 -0
- package/src/sql/ident.js +25 -0
- package/src/sql/signature.js +143 -0
- package/src/sql/statements.js +267 -0
- package/src/version.js +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,174 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rattlecheck
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Rattle every door you own.**
|
|
4
|
+
|
|
5
|
+
At closing time, a good manager walks the building and rattles every door to make sure it's locked. rattlecheck does that for your app. It checks every table, function, and rule in your Supabase project the way someone on the outside would, tells you in plain English which doors are open, and gives you the exact fix.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx rattlecheck
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
rattlecheck 0.1.0 rattle every door you own
|
|
13
|
+
|
|
14
|
+
┌──────────────────────────────────────────────┐
|
|
15
|
+
│ GRADE F Wide open │
|
|
16
|
+
│ 3 doors checked, 3 open │
|
|
17
|
+
└──────────────────────────────────────────────┘
|
|
18
|
+
|
|
19
|
+
CRITICAL Anyone on the internet, using only the key that ships in your website's code,
|
|
20
|
+
can read and change every row in the "_snapshot_orders" table. It was created
|
|
21
|
+
as a copy of another table (CREATE TABLE AS), and copies inherit none of the
|
|
22
|
+
original's security.
|
|
23
|
+
What to do: Lock the copy, or drop it if you no longer need it.
|
|
24
|
+
|
|
25
|
+
CRITICAL Anyone on the internet can run the "get_orders" function. It runs with full
|
|
26
|
+
database powers and skips your security rules, so whatever it can read or
|
|
27
|
+
change, anyone can.
|
|
28
|
+
What to do: Stop the public from calling it. If signed-in users need it,
|
|
29
|
+
allow only them.
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Add `--technical` for file and line, the standards each finding maps to, and the SQL fix.
|
|
33
|
+
|
|
34
|
+
## Why this exists
|
|
35
|
+
|
|
36
|
+
Supabase serves your database straight to the browser. That's what makes it fast to build on, and it's why one missed line of SQL can put every customer's data on the open internet. The key that unlocks it ships inside your website's code, so anyone can find it. Apps built in a weekend, by people or by coding agents, ship these holes all the time, and nothing in the normal build process notices.
|
|
37
|
+
|
|
38
|
+
Every rule in rattlecheck comes from a real incident in a production app:
|
|
39
|
+
|
|
40
|
+
- **A snapshot table, readable by anyone.** Someone made a quick backup copy of a customer table before a risky change (`create table ... as select`). Copies inherit none of the original's security. For a day, every guest name and message in it was readable with nothing but the public key, while the real table was locked tight. (RC001)
|
|
41
|
+
- **A helper function that skipped every lock.** A `SECURITY DEFINER` function was written to fetch one customer's data. Postgres lets everyone run new functions by default, and nobody revoked that, so anyone could call it with someone else's id. (RC002)
|
|
42
|
+
- **A week of silent failures.** A trigger wrote audit rows to a table locked to the server. Every save by a real user failed and rolled back. Server jobs bypass the lock, so every dashboard stayed green for seven days. (RC004)
|
|
43
|
+
|
|
44
|
+
## What it checks
|
|
45
|
+
|
|
46
|
+
| Rule | What it catches | Severity |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| [RC001](docs/rules/RC001.md) | A table reachable through the API with row-level security off, including `CREATE TABLE AS` copies | critical |
|
|
49
|
+
| [RC002](docs/rules/RC002.md) | A `SECURITY DEFINER` function anyone can call | critical |
|
|
50
|
+
| [RC003](docs/rules/RC003.md) | A `SECURITY DEFINER` function without a pinned `search_path` | high |
|
|
51
|
+
| [RC004](docs/rules/RC004.md) | A trigger that runs with the user's rights and writes to a server-only table, so user saves fail | high |
|
|
52
|
+
| [RC005](docs/rules/RC005.md) | A policy whose condition is just `true`, letting anyone change every row | high |
|
|
53
|
+
| [RC101](docs/rules/RC101.md) | **Live:** a table on your running project that hands rows to the public key | critical |
|
|
54
|
+
|
|
55
|
+
rattlecheck doesn't grep your files. It replays every migration in order, statement by statement, the way Postgres would, so it knows the current state: a revoke from March doesn't count if the function was dropped and re-created in June, and a policy that was later dropped protects nothing.
|
|
56
|
+
|
|
57
|
+
Grades: **A** nothing open, **B** only things worth a look, **C** one high finding, **D** two or more, **F** anything critical.
|
|
58
|
+
|
|
59
|
+
## For coding agents
|
|
60
|
+
|
|
61
|
+
rattlecheck has an MCP server built in. Connect it and your agent can check its own work before it ships, then write the fixes as a new migration.
|
|
62
|
+
|
|
63
|
+
**Claude Code**
|
|
64
|
+
```bash
|
|
65
|
+
claude mcp add rattlecheck -- npx -y rattlecheck mcp
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Cursor, Windsurf, and other MCP clients** (`.cursor/mcp.json` or your client's equivalent):
|
|
69
|
+
```json
|
|
70
|
+
{ "mcpServers": { "rattlecheck": { "command": "npx", "args": ["-y", "rattlecheck", "mcp"] } } }
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Tools: `scan` (grade, plain-English findings, fix SQL), `explain_rule`, `list_rules`. The server tells the agent to put fixes in a new migration, never to run SQL against production, and never to silence a finding without asking you.
|
|
74
|
+
|
|
75
|
+
Prefer instructions over a server? Drop in one of these:
|
|
76
|
+
- Claude Code skill: [`integrations/claude-code/rattlecheck/SKILL.md`](integrations/claude-code/rattlecheck/SKILL.md) (copy the folder into `.claude/skills/`)
|
|
77
|
+
- `AGENTS.md` / `CLAUDE.md` section: [`integrations/AGENTS.md`](integrations/AGENTS.md)
|
|
78
|
+
- Cursor rule: [`integrations/cursor/rattlecheck.mdc`](integrations/cursor/rattlecheck.mdc) (copy into `.cursor/rules/`)
|
|
79
|
+
|
|
80
|
+
## Share your grade
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npx rattlecheck --card # 1200x630 share image: rattlecheck-card.svg
|
|
84
|
+
npx rattlecheck --badge # README badge: rattlecheck-badge.svg
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The card shows the grade and counts only. It never names a table, a function, or your project, so a failing card doesn't tell anyone where the hole is.
|
|
88
|
+
|
|
89
|
+
## Live check
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npx rattlecheck --live
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Static checks read your migration files. The live check asks your running project, with only the public key, how many rows each table will hand over. It catches what migrations can't: a policy someone added in the dashboard, or a table that was changed by hand.
|
|
96
|
+
|
|
97
|
+
- **Your project only.** Before anything else, rattlecheck proves you control the project: either a `SUPABASE_ACCESS_TOKEN` (from `supabase login`) that can see it, or the project's service key in your local `.env`. Without proof, it refuses. There is no flag to skip this.
|
|
98
|
+
- **Read-only.** Every table request is a `HEAD` asking for a row count; the one `GET` asks for the list of table names. No rows are downloaded, nothing is written, nothing is stored. Counting is exact, so very large tables can take a moment.
|
|
99
|
+
- **Keys go nowhere else.** Your keys are only ever sent to `https://<project-ref>.supabase.co` or a local Supabase on `localhost`, never through a redirect. The URL and keys must come from the same place (all from your environment, or all from your `.env` files), so a repo's `.env` can't point your shell's keys somewhere else.
|
|
100
|
+
- **Every table, not just the ones in your migrations.** Tables made in the dashboard or by hand (a quick backup copy, say) never show up in migrations, and they're the likeliest to be left open. With `SUPABASE_ACCESS_TOKEN`, rattlecheck reads the full list of table and view names through Supabase's read-only query endpoint (names only, no rows). Without it, the report says exactly which part it couldn't cover instead of calling it an all-clear.
|
|
101
|
+
- **Honest zeros.** A table that returns zero rows is reported as "locked or empty", because from outside those look the same.
|
|
102
|
+
|
|
103
|
+
The project URL and public key are read from the environment, or from `.env`, `.env.local`, `.env.development` (`SUPABASE_URL`, `NEXT_PUBLIC_SUPABASE_URL`, `VITE_SUPABASE_URL`, and the matching `..._ANON_KEY` or `..._PUBLISHABLE_KEY`). Keys are never printed or included in any report.
|
|
104
|
+
|
|
105
|
+
## In CI
|
|
106
|
+
|
|
107
|
+
```yaml
|
|
108
|
+
# .github/workflows/rattlecheck.yml
|
|
109
|
+
name: rattlecheck
|
|
110
|
+
on: [pull_request]
|
|
111
|
+
permissions: { contents: read, security-events: write }
|
|
112
|
+
jobs:
|
|
113
|
+
rattlecheck:
|
|
114
|
+
runs-on: ubuntu-latest
|
|
115
|
+
steps:
|
|
116
|
+
- uses: actions/checkout@v4
|
|
117
|
+
- uses: actions/setup-node@v4
|
|
118
|
+
with: { node-version: 22 }
|
|
119
|
+
- run: npx -y rattlecheck --sarif --out rattlecheck.sarif
|
|
120
|
+
- if: always()
|
|
121
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
122
|
+
with: { sarif_file: rattlecheck.sarif }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Exit codes: `0` nothing open, `1` open door found, `2` usage or config error, `3` migrations could not be parsed (don't trust the result), `4` live check refused.
|
|
126
|
+
|
|
127
|
+
`--json` prints a stable, versioned report (`rattlecheck.report/v1`). `--sarif` prints SARIF 2.1.0 for GitHub code scanning and other security tools. `--fix-sql` writes every suggested fix to one file for review.
|
|
128
|
+
|
|
129
|
+
## Config
|
|
130
|
+
|
|
131
|
+
`rattlecheck.config.json` in your project folder:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"defaults": "supabase-stock",
|
|
136
|
+
"allow": [
|
|
137
|
+
{ "rule": "RC005", "object": "public.menu_items", "reason": "The menu is public on the website." }
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
- **`allow`**: some doors are meant to be open, like a public menu. Every entry needs a written reason. Entries that no longer match anything are reported, so an old exception can't quietly cover something new.
|
|
143
|
+
- **`defaults`**: rattlecheck assumes Supabase's stock privileges, where new tables and functions in `public` are open to `anon` and `authenticated` until you revoke them. If your baseline migration revokes those defaults through dynamic SQL that a static reader can't see, set `"clean"`, or `{ "functions": "clean", "tables": "supabase-stock" }`.
|
|
144
|
+
- **`exposedSchemas`**: read from `supabase/config.toml` (`[api] schemas`) by default.
|
|
145
|
+
- **`migrationRoles`**: the roles your migrations run as (default `["postgres"]`). `ALTER DEFAULT PRIVILEGES FOR ROLE` only counts when it names one of them.
|
|
146
|
+
|
|
147
|
+
## Standards
|
|
148
|
+
|
|
149
|
+
Every finding is labeled with the controls auditors and agencies already use, so a rattlecheck report can go straight into a security review.
|
|
150
|
+
|
|
151
|
+
| Rule | CWE | NIST SP 800-53 | CIS Controls v8 |
|
|
152
|
+
|---|---|---|---|
|
|
153
|
+
| RC001 | CWE-284, CWE-862 | AC-3, AC-6 | 3.3 |
|
|
154
|
+
| RC002 | CWE-269, CWE-862 | AC-3, AC-6 | 3.3, 6.8 |
|
|
155
|
+
| RC003 | CWE-426 | CM-6, AC-6 | 4.1 |
|
|
156
|
+
| RC004 | CWE-279 | AC-6, AU-9 | 8.2 |
|
|
157
|
+
| RC005 | CWE-732 | AC-3, AC-6 | 3.3 |
|
|
158
|
+
| RC101 | CWE-200, CWE-284 | AC-3, AC-6 | 3.3 |
|
|
159
|
+
|
|
160
|
+
## Built to be trusted
|
|
161
|
+
|
|
162
|
+
- **Zero runtime dependencies.** Including the MCP server. Every line that runs is in this repository.
|
|
163
|
+
- **No telemetry.** rattlecheck never phones home. Static checks work fully offline.
|
|
164
|
+
- **Never changes your database.** Fixes are printed for you to review and commit.
|
|
165
|
+
- **Checks only what you own.** Live checks require proof of ownership, every time.
|
|
166
|
+
- **Shows its coverage.** Every run says how many files, statements, tables, and functions it parsed, and fails loudly if it found migrations but couldn't read them. A clean report from a checker that saw nothing is worse than no report.
|
|
167
|
+
|
|
168
|
+
## What it doesn't check yet
|
|
169
|
+
|
|
170
|
+
rattlecheck 0.1 reads Supabase migrations and, with `--live`, your running project's tables. It does not yet look at views, storage buckets, edge functions, auth settings, or secrets leaked into your website's code. It can't see inside dynamic SQL (`EXECUTE format(...)`), which is one more reason to run `--live`.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { main } from '../src/cli.js';
|
|
3
|
+
|
|
4
|
+
main(process.argv.slice(2)).then(
|
|
5
|
+
(code) => {
|
|
6
|
+
if (code !== null) process.exitCode = code;
|
|
7
|
+
},
|
|
8
|
+
(err) => {
|
|
9
|
+
process.stderr.write(`rattlecheck: unexpected error: ${err?.stack ?? err}\n`);
|
|
10
|
+
process.exitCode = 2;
|
|
11
|
+
},
|
|
12
|
+
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# RC001: Table reachable through the API without row-level security
|
|
2
|
+
|
|
3
|
+
**Severity:** critical
|
|
4
|
+
**Standards:** CWE-284, CWE-862 · NIST SP 800-53 AC-3, AC-6 · CIS Controls v8 3.3
|
|
5
|
+
|
|
6
|
+
## What it catches
|
|
7
|
+
|
|
8
|
+
A table in an exposed schema (usually `public`) that `anon` or `authenticated` can reach, with row-level security (RLS) turned off. That includes tables created as a copy with `CREATE TABLE ... AS SELECT`.
|
|
9
|
+
|
|
10
|
+
## Why it matters
|
|
11
|
+
|
|
12
|
+
Supabase serves every table in an exposed schema over HTTP. The key that lets your website talk to it ships inside your website's code, so anyone can copy it. With RLS off, that key can read and change every row.
|
|
13
|
+
|
|
14
|
+
Copies are the sneaky case. `create table backup as select * from customers` copies the rows and none of the security: no RLS, no policies, and Supabase's default grants to `anon` and `authenticated`. A backup made before a risky change can quietly become the one table on your project anyone can read.
|
|
15
|
+
|
|
16
|
+
## How to fix
|
|
17
|
+
|
|
18
|
+
```sql
|
|
19
|
+
alter table public.your_table enable row level security;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
With RLS on and no policies, only your server (the service role) can use the table. Then add a policy for each thing users should be allowed to do:
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
create policy "read own rows" on public.your_table
|
|
26
|
+
for select to authenticated
|
|
27
|
+
using ((select auth.uid()) = user_id);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For a copy you only needed briefly, lock it and drop it when you're done:
|
|
31
|
+
|
|
32
|
+
```sql
|
|
33
|
+
alter table public.your_copy enable row level security;
|
|
34
|
+
revoke all on public.your_copy from anon, authenticated;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Not a finding
|
|
38
|
+
|
|
39
|
+
- Tables where you revoked every privilege from `anon` and `authenticated`.
|
|
40
|
+
- Tables in schemas the API doesn't expose.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# RC002: SECURITY DEFINER function callable by anyone
|
|
2
|
+
|
|
3
|
+
**Severity:** critical
|
|
4
|
+
**Standards:** CWE-269, CWE-862 · NIST SP 800-53 AC-3, AC-6 · CIS Controls v8 3.3, 6.8
|
|
5
|
+
|
|
6
|
+
## What it catches
|
|
7
|
+
|
|
8
|
+
A `SECURITY DEFINER` function in an exposed schema that `PUBLIC` or `anon` can execute.
|
|
9
|
+
|
|
10
|
+
## Why it matters
|
|
11
|
+
|
|
12
|
+
A `SECURITY DEFINER` function runs with its owner's powers, which usually means it skips row-level security entirely. That's often the point: a helper that fetches one customer's data on their behalf.
|
|
13
|
+
|
|
14
|
+
But Postgres grants `EXECUTE` on every new function to `PUBLIC` by default, and Supabase's stock setup also grants it to `anon` and `authenticated`. Unless you revoke that, anyone with your public key can call the function through `/rest/v1/rpc/...` and pass in any argument they like, such as another customer's id.
|
|
15
|
+
|
|
16
|
+
rattlecheck tracks grants in order. Dropping and re-creating a function resets its grants, so a revoke written before the re-create no longer counts. `CREATE OR REPLACE` keeps them. Overloads are tracked separately: revoking `f(uuid)` does not protect `f(uuid, text)`.
|
|
17
|
+
|
|
18
|
+
## How to fix
|
|
19
|
+
|
|
20
|
+
```sql
|
|
21
|
+
revoke execute on function public.your_function(uuid) from public, anon;
|
|
22
|
+
-- Only if signed-in users should be able to call it:
|
|
23
|
+
grant execute on function public.your_function(uuid) to authenticated;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To make every new function start closed:
|
|
27
|
+
|
|
28
|
+
```sql
|
|
29
|
+
alter default privileges revoke execute on functions from public;
|
|
30
|
+
alter default privileges in schema public revoke execute on functions from anon, authenticated;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Allowing it
|
|
34
|
+
|
|
35
|
+
Some functions really are meant for the public, like a store locator. Add them to `rattlecheck.config.json` with a reason, and make sure the function only returns data that's safe for anyone to see.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# RC003: SECURITY DEFINER function without a pinned search_path
|
|
2
|
+
|
|
3
|
+
**Severity:** high
|
|
4
|
+
**Standards:** CWE-426 · NIST SP 800-53 CM-6, AC-6 · CIS Controls v8 4.1
|
|
5
|
+
|
|
6
|
+
## What it catches
|
|
7
|
+
|
|
8
|
+
A `SECURITY DEFINER` function (callable or trigger) without `SET search_path`.
|
|
9
|
+
|
|
10
|
+
## Why it matters
|
|
11
|
+
|
|
12
|
+
When a function says `orders`, Postgres looks that name up using the caller's `search_path`. That includes the caller's own temporary schema, which every session can write to. A caller can create a temporary table or function with the same name as something the definer uses, and the definer will use theirs instead, with the owner's powers.
|
|
13
|
+
|
|
14
|
+
## How to fix
|
|
15
|
+
|
|
16
|
+
```sql
|
|
17
|
+
alter function public.your_function(uuid) set search_path = '';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
With an empty `search_path`, refer to every table inside the function with its schema: `public.orders`, not `orders`. You can also set it when creating the function:
|
|
21
|
+
|
|
22
|
+
```sql
|
|
23
|
+
create function public.your_function(uid uuid) returns ...
|
|
24
|
+
language plpgsql security definer set search_path = '' as $$ ... $$;
|
|
25
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# RC004: Invoker-rights trigger writes to a table locked to the server
|
|
2
|
+
|
|
3
|
+
**Severity:** high
|
|
4
|
+
**Standards:** CWE-279 · NIST SP 800-53 AC-6, AU-9 · CIS Controls v8 8.2
|
|
5
|
+
|
|
6
|
+
## What it catches
|
|
7
|
+
|
|
8
|
+
A trigger function that runs with the caller's rights (`SECURITY INVOKER`, the default) and writes to a table that has row-level security on and no policies.
|
|
9
|
+
|
|
10
|
+
## Why it matters
|
|
11
|
+
|
|
12
|
+
RLS on with no policies is a legitimate way to lock a table to your server: perfect for an audit log. But a trigger that writes to it on a user's behalf runs as that user. The insert is denied with `42501`, and Postgres rolls back the user's whole change.
|
|
13
|
+
|
|
14
|
+
This one hides well. Server jobs and cron tasks use the service role, which bypasses RLS, so every pipeline keeps working and every health check stays green. Only real users fail, and only on the actions that fire the trigger. In the incident behind this rule, saves failed for every user for seven days before anyone noticed.
|
|
15
|
+
|
|
16
|
+
## How to fix
|
|
17
|
+
|
|
18
|
+
```sql
|
|
19
|
+
alter function public.your_trigger_fn() security definer;
|
|
20
|
+
alter function public.your_trigger_fn() set search_path = '';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Trigger functions can't be called directly, so making them `SECURITY DEFINER` doesn't open a new door. It's also the right design for audit tables: an audit trail shouldn't depend on the permissions of the person it's auditing, and a policy that lets users insert into it would let them forge entries.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# RC005: Policy lets anyone change every row
|
|
2
|
+
|
|
3
|
+
**Severity:** high (change), warning (add, read)
|
|
4
|
+
**Standards:** CWE-732 · NIST SP 800-53 AC-3, AC-6 · CIS Controls v8 3.3
|
|
5
|
+
|
|
6
|
+
## What it catches
|
|
7
|
+
|
|
8
|
+
A permissive policy whose condition is simply `true`, for a role that can reach the table:
|
|
9
|
+
|
|
10
|
+
- **high:** `UPDATE`, `DELETE`, or `ALL` for `anon`, `authenticated`, or `public` (a policy without `TO` applies to everyone). Anyone can change other people's rows.
|
|
11
|
+
- **warning:** `INSERT` with `with check (true)`. Anyone can add rows. That's normal for a signup or contact form, but check that nobody can add a row that claims to belong to someone else.
|
|
12
|
+
- **warning:** `SELECT` for `anon` or `public`.
|
|
13
|
+
|
|
14
|
+
## Why it matters
|
|
15
|
+
|
|
16
|
+
Row-level security only protects a table as well as its policies do. `using (true)` admits every row, so for that action RLS might as well be off. "Enable RLS, then add `using (true)` to make the error go away" is one of the most common ways apps end up open.
|
|
17
|
+
|
|
18
|
+
Some of this is intended: a menu or store hours anyone can read, a waitlist anyone can join. That's why adding and reading are warnings, not failures.
|
|
19
|
+
|
|
20
|
+
## How to fix
|
|
21
|
+
|
|
22
|
+
Replace the policy with one scoped to the row's owner:
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
drop policy "your policy" on public.your_table;
|
|
26
|
+
create policy "your policy" on public.your_table
|
|
27
|
+
for update to authenticated
|
|
28
|
+
using ((select auth.uid()) = user_id)
|
|
29
|
+
with check ((select auth.uid()) = user_id);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
If a table is meant to be readable by everyone, allow it in `rattlecheck.config.json` with a reason.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# RC101: Live table hands rows to the public key
|
|
2
|
+
|
|
3
|
+
**Severity:** critical
|
|
4
|
+
**Runs with:** `--live`
|
|
5
|
+
**Standards:** CWE-200, CWE-284 · NIST SP 800-53 AC-3, AC-6 · CIS Controls v8 3.3
|
|
6
|
+
|
|
7
|
+
## What it catches
|
|
8
|
+
|
|
9
|
+
A table on your running project that returns one or more rows to a request carrying only the public (anon or publishable) key.
|
|
10
|
+
|
|
11
|
+
## Why it matters
|
|
12
|
+
|
|
13
|
+
Migrations describe what your database should be. The live check asks what it actually is. It catches a policy someone added in the dashboard, a table changed by hand, or anything inside dynamic SQL a static reader can't see. When your migrations say a table is locked and the live project hands out rows anyway, rattlecheck says so.
|
|
14
|
+
|
|
15
|
+
## How it checks, and what it won't do
|
|
16
|
+
|
|
17
|
+
- It only runs after proving you own the project (a Supabase access token that can see it, or the project's service key).
|
|
18
|
+
- It asks about every table and view the project has, not only the ones in your migrations. With `SUPABASE_ACCESS_TOKEN`, the list comes from the project catalog through Supabase's read-only query endpoint (names only). If no full list is available, the report marks the live check as partial and says what was left out.
|
|
19
|
+
- Each table gets one `HEAD` request with `Prefer: count=exact`. The server answers with a count. No rows are downloaded, nothing is written, nothing is stored.
|
|
20
|
+
- Keys are only sent to `https://<project-ref>.supabase.co` or a local Supabase, and no request follows a redirect.
|
|
21
|
+
- A count of zero is reported as "locked or empty". From outside, those look the same.
|
|
22
|
+
|
|
23
|
+
## How to fix
|
|
24
|
+
|
|
25
|
+
Turn on row-level security for the table and review its policies:
|
|
26
|
+
|
|
27
|
+
```sql
|
|
28
|
+
alter table public.your_table enable row level security;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If the data is meant to be public, allow it in `rattlecheck.config.json` with a reason.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!-- Paste this section into your project's AGENTS.md (or CLAUDE.md) so coding agents check security before they ship. -->
|
|
2
|
+
|
|
3
|
+
## Security check before deploy (rattlecheck)
|
|
4
|
+
|
|
5
|
+
This project uses Supabase. Before deploying, and after any migration that touches tables, policies, functions, triggers, or grants:
|
|
6
|
+
|
|
7
|
+
1. Run `npx rattlecheck --json` from the project root (or call the `scan` tool from the rattlecheck MCP server).
|
|
8
|
+
2. Put each finding's `fix` SQL into a **new** migration file. Never edit migrations that already ran. Never run SQL against production yourself.
|
|
9
|
+
3. Run it again until the grade is A.
|
|
10
|
+
4. If a finding is intentional, ask before adding an allow entry with a written reason to `rattlecheck.config.json`. Never allow a finding just to silence it.
|
|
11
|
+
5. Explain what you found and fixed using each finding's `plain` text.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rattlecheck
|
|
3
|
+
description: Check a Supabase project for open doors (tables anyone can read, functions anyone can call with full database powers, policies that let anyone change every row) before deploying, and fix them with a new migration. Use before any deploy of a Supabase app, after writing or changing migrations, or when the user asks whether their app or data is secure.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# rattlecheck: rattle every door before you ship
|
|
7
|
+
|
|
8
|
+
rattlecheck replays `supabase/migrations` and grades the project A to F. It never changes the database.
|
|
9
|
+
|
|
10
|
+
## When to run it
|
|
11
|
+
|
|
12
|
+
- Before deploying a Supabase app.
|
|
13
|
+
- After you write or change a migration that touches tables, policies, functions, triggers, or grants.
|
|
14
|
+
- When the user asks "is my app secure?", "is my data safe?", or similar.
|
|
15
|
+
|
|
16
|
+
## How
|
|
17
|
+
|
|
18
|
+
1. From the project root, run:
|
|
19
|
+
```bash
|
|
20
|
+
npx rattlecheck --json
|
|
21
|
+
```
|
|
22
|
+
Or call the `scan` tool if the rattlecheck MCP server is connected.
|
|
23
|
+
2. For each finding, read `plain` (what's wrong, in plain words), `todo`, and `fix` (SQL).
|
|
24
|
+
3. Put the fixes in a **new** migration file, for example `supabase/migrations/<timestamp>_rattlecheck_fixes.sql`.
|
|
25
|
+
- Never edit a migration that has already run.
|
|
26
|
+
- Never run SQL against a production database yourself.
|
|
27
|
+
- Read each fix before using it. Fixes that turn on row-level security may need a policy so the app keeps working; write one scoped to the row's owner.
|
|
28
|
+
4. Run rattlecheck again. Repeat until the grade is **A**.
|
|
29
|
+
5. If a finding is intentional (a public menu, store hours), **ask the user** before adding an allow entry to `rattlecheck.config.json`:
|
|
30
|
+
```json
|
|
31
|
+
{ "allow": [{ "rule": "RC005", "object": "public.menu_items", "reason": "The menu is public on the website." }] }
|
|
32
|
+
```
|
|
33
|
+
Never add an allow entry just to make a finding go away.
|
|
34
|
+
6. Tell the user what you found and fixed, in plain words, using each finding's `plain` text.
|
|
35
|
+
|
|
36
|
+
## Live check
|
|
37
|
+
|
|
38
|
+
`npx rattlecheck --live` also asks the running project, read-only, how many rows each table hands to the public key. It only runs after proving the user owns the project (a `SUPABASE_ACCESS_TOKEN` or the service key in the local `.env`). Ask the user before running it.
|
|
39
|
+
|
|
40
|
+
## Exit codes
|
|
41
|
+
|
|
42
|
+
`0` nothing open, `1` open door found, `2` usage or config error, `3` migrations could not be parsed (don't trust the result), `4` live check refused.
|