rlsproof 0.0.0-stage → 1.0.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/CALIBRATION.md +63 -0
- package/LICENSE +21 -0
- package/README.md +151 -2
- package/SECURITY.md +23 -0
- package/action.yml +113 -0
- package/bin/rlsproof.js +230 -0
- package/package.json +50 -4
- package/src/core/findings.js +145 -0
- package/src/core/ignore.js +197 -0
- package/src/core/rules.js +155 -0
- package/src/index.js +186 -0
- package/src/reporters/json.js +25 -0
- package/src/reporters/markdown.js +95 -0
- package/src/reporters/sarif.js +101 -0
- package/src/sql/expr-analyzer.js +289 -0
- package/src/sql/parser.js +486 -0
- package/src/sql/sql-rules.js +360 -0
- package/src/sql/state-graph.js +694 -0
- package/src/surface/ai-api-scanner.js +337 -0
- package/src/surface/config-toml.js +137 -0
- package/src/surface/file-walker.js +105 -0
- package/src/surface/secret-scanner.js +247 -0
package/CALIBRATION.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# rlsproof v1.0 — Calibration Set Report (Anonymized)
|
|
2
|
+
|
|
3
|
+
**Evaluated:** 2026-12-05 (`node v26.13.1`, `libpg-query@18.3.0`)
|
|
4
|
+
**Scope Note:** All third-party repository identifiers and commit SHAs are anonymized (`Repo A`–`Repo L`) in public artifacts so unverified static scanner findings are never associated with external maintainers without coordinated disclosure. Named triage notes remain local only inside the gitignored `.cache/` directory.
|
|
5
|
+
|
|
6
|
+
**Measurement Caveat:** The `1/33` (`3.03%`) figure below is the **in-sample false-positive share among flagged findings on the 12-repo calibration set** after tuning 5 general precision refinements on the same cohort. It is **not** a classical negative-ground-truth false-positive rate (FPR), does **not** measure false negatives, and has **not** yet been evaluated on an independent frozen holdout cohort or on Node `20`/`22` locally.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 1. Calibration Set Summary
|
|
11
|
+
|
|
12
|
+
| Metric | Target | Measured (Calibration Set) | Notes |
|
|
13
|
+
|---|---:|---:|---|
|
|
14
|
+
| External Open-Source Repos Evaluated | `>= 10` | **12** | Anonymized `Repo A`–`Repo L` |
|
|
15
|
+
| SQL Migration Files Scanned | — | **243** | — |
|
|
16
|
+
| Aggregate SQL Statements Parsed | `>= 95.0%` | **2,311 / 2,311 (100.00%)** | Measured on `node v26.13.1` |
|
|
17
|
+
| Total Active Findings Emitted | — | **33** | After 5 general refinements |
|
|
18
|
+
| Triaged True Positives (within static scope) | — | **32** | Inspected against local clones |
|
|
19
|
+
| Triaged False Positives / Dynamic-SQL Limit | `<= 5.0%` | **1 / 33 (3.03%)** | Share among flagged findings on calibration set |
|
|
20
|
+
| Unmasked Secrets in Reports/Logs | `0` | **0** | Verified across JSON/MD/SARIF |
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 2. Anonymized Per-Repository Calibration Breakdown
|
|
25
|
+
|
|
26
|
+
| # | Archetype | SQL Files | SQL Parsed | Scan Time | Findings (C/H/M) | Unsupported | Triage Summary |
|
|
27
|
+
|---|---|---:|---:|---:|---|---:|---|
|
|
28
|
+
| `Repo A` | Multi-provider AI chat app | 25 | 242/242 (100%) | ~230 ms | **17** (6C / 10H / 1M) | 0 | 17 triaged findings: 1 unauthenticated AI route using `service_role` lookup, 5 unguarded `SECURITY DEFINER` storage/access RPCs, 11 LLM routes lacking model allowlist and/or rate-limit/`max_tokens` caps |
|
|
29
|
+
| `Repo B` | Multi-tenant SaaS starter | 4 | 104/104 (100%) | ~24 ms | **0** | 0 | Clean pass (inter-procedural auth guard, capability-token lookup, and webhook signing handler verified) |
|
|
30
|
+
| `Repo C` | Vector/embeddings backend | 8 | 15/15 (100%) | ~109 ms | **5** (2C / 3H / 0M) | 0 | 5 triaged findings: 2 tables without RLS (+ `anon` exposure), 1 view without `security_invoker = true` joining `auth.users` |
|
|
31
|
+
| `Repo D` | Next.js + Stripe SaaS starter | 1 | 22/22 (100%) | ~31 ms | **0** | 0 | Clean pass |
|
|
32
|
+
| `Repo E` | Next.js + Supabase template | 4 | 36/36 (100%) | ~58 ms | **0** | 0 | Clean pass |
|
|
33
|
+
| `Repo F` | AI doc-search starter | 1 | 7/7 (100%) | ~13 ms | **0** | 0 | Clean pass |
|
|
34
|
+
| `Repo G` | AI chatbot starter | 1 | 8/8 (100%) | ~31 ms | **0** | 0 | Clean pass |
|
|
35
|
+
| `Repo H` | Large multi-migration community app | 190 | 1762/1762 (100%) | ~1083 ms | **2** (1C / 1H / 0M) | **5** | 1 triaged finding (`SELECT USING (true)` on audit table) + 1 static-scope FP (a `SECURITY DEFINER` function dynamically revoked inside a `DO $$` loop, explicitly reported under `UNSUPPORTED / SKIPPED`) |
|
|
36
|
+
| `Repo I` | Auth/account starter kit | 1 | 15/15 (100%) | ~89 ms | **1** (0C / 1H / 0M) | 0 | 1 triaged finding (`SECURITY DEFINER` function reading `auth.users` without `SET search_path`) |
|
|
37
|
+
| `Repo J` | Workspace SaaS starter | 3 | 75/75 (100%) | ~64 ms | **4** (3C / 1H / 0M) | 0 | 4 triaged findings (unscoped `INSERT` policy on `storage.objects`; permissive `true` policies on tenant/join tables) |
|
|
38
|
+
| `Repo K` | Full-stack web starter | 3 | 23/23 (100%) | ~51 ms | **2** (2C / 0H / 0M) | 0 | 2 triaged findings (2 unguarded `SECURITY DEFINER` storage helper functions) |
|
|
39
|
+
| `Repo L` | Drizzle + Edge starter | 2 | 2/2 (100%) | ~7 ms | **2** (2C / 0H / 0M) | 0 | 2 triaged findings (2 tables including credentials fields created in `public` schema without RLS) |
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 3. General Precision Refinements Applied During Calibration
|
|
44
|
+
|
|
45
|
+
During the first calibration pass (`57` raw findings), manual triage surfaced 5 general false-positive patterns fixed in `src/` with regression tests added to `test/fixtures.test.js`:
|
|
46
|
+
|
|
47
|
+
1. **Inter-procedural SQL auth guards (`src/sql/state-graph.js`):** Functions delegating authorization to another tracked SQL function now inherit `hasAuthGuard` iteratively across the SQL call graph.
|
|
48
|
+
2. **Capability-token RPC lookups (`src/sql/sql-rules.js`):** `SECURITY DEFINER` functions with `SET search_path`, revoked `PUBLIC`/`anon` `EXECUTE`, and an explicit secret-token filter (`WHERE token = ...`) are recognized rather than misflagged.
|
|
49
|
+
3. **Public-read storage policies when `public` column is omitted (`src/sql/state-graph.js`, `src/sql/sql-rules.js`):** Distinguishes omitted `public` column (`null`) from explicit `public = false` on `storage.buckets` so read-only `SELECT` policies on public-asset buckets avoid false alarms while unguarded `INSERT` policies still trigger `CRITICAL`.
|
|
50
|
+
4. **Non-inference SDK methods & custom auth helpers (`src/surface/ai-api-scanner.js`):** Targets paid inference/embedding endpoints rather than management calls (e.g. `openai.beta.assistants.list()`), strips JS/TS comments before rule checks, recognizes common server profile/auth helpers and webhook handler wrappers, and checks nested request settings (`chatSettings.model`).
|
|
51
|
+
5. **Supabase CLI local dev demo JWT in migrations (`src/surface/secret-scanner.js`):** Ignores the well-known public Supabase CLI demo `service_role` token inside `supabase/migrations/*.sql` (while still flagging any non-demo token everywhere and flagging even the demo `service_role` JWT in client/frontend code).
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 4. `UNSUPPORTED / SKIPPED` Transparency
|
|
56
|
+
|
|
57
|
+
In `Repo H`, 5 `DO $$` blocks containing dynamic `CREATE POLICY` or `EXECUTE format('REVOKE EXECUTE ...')` statements were surfaced explicitly in `unsupported[]` (`DYNAMIC_DO_BLOCK`), shifting scan status to `FAIL_WITH_UNSUPPORTED` rather than silently ignoring dynamic SQL.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 5. Synthetic Demo Sanity Check (Separate from External Cohort)
|
|
62
|
+
|
|
63
|
+
- **`supabase-proof-demo`** (local synthetic demo repository): `43/43` SQL statements parsed (**100%**), `3` `CRITICAL` findings detected on the intentionally vulnerable demo client (`VITE_SUPABASE_SERVICE_ROLE_KEY`, hardcoded `service_role` JWT, and report echo), with all secret values redacted in output.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Umit Dopac
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,152 @@
|
|
|
1
|
-
#
|
|
1
|
+
# rlsproof
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Defensive, local-only static security scanner for Supabase PostgreSQL migrations, hardcoded/client-exposed secrets, Edge Function JWT gates, and OWASP API4 AI endpoint cost protection.**
|
|
4
|
+
|
|
5
|
+
`rlsproof` never connects to live databases, never scans remote URLs, and never ships code off your machine. It replays your ordered `supabase/migrations/*.sql` history through the real PostgreSQL parser (`libpg-query@18.3.0` WASM) into a cumulative schema state graph, then combines that final database state with repository secret, `supabase/config.toml`, and LLM API route checks.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Key Capabilities
|
|
10
|
+
|
|
11
|
+
1. **Cumulative Multi-Migration SQL State Graph (M1):**
|
|
12
|
+
- Evaluates the **final state** after replaying `CREATE/ALTER/DROP POLICY`, `AS RESTRICTIVE` narrowing, `ENABLE/DISABLE/FORCE RLS`, `GRANT/REVOKE`, `ALTER DEFAULT PRIVILEGES`, `VIEW` `security_invoker`, `SECURITY DEFINER` RPCs + inter-procedural auth-guard propagation, and `storage.buckets` / `storage.objects`.
|
|
13
|
+
- **Honest `UNSUPPORTED / SKIPPED` Reporting:** Dynamic `DO $$` DDL blocks, `CREATE RULE`, `psql` meta-commands, or unparseable statements are explicitly listed under `UNSUPPORTED / SKIPPED` (`status: INCOMPLETE`, `WARN_WITH_UNSUPPORTED`, or `FAIL_WITH_UNSUPPORTED`) — `rlsproof` never silently marks unknown SQL as safe.
|
|
14
|
+
2. **Low-False-Positive Rules Calibrated Against Real Schemas:**
|
|
15
|
+
- **PostgreSQL `WITH CHECK` inheritance:** `UPDATE` and `ALL` policies omitting `WITH CHECK` inherit `USING` in PostgreSQL; only `INSERT` policies missing `WITH CHECK` are flagged.
|
|
16
|
+
- **Supabase `anon` key accuracy:** Public `anon` / `publishable` client keys are **not** flagged as secrets; findings trigger only when open `anon` writes, RLS-disabled tables, or unguarded `anon`-executable `SECURITY DEFINER` RPCs exist.
|
|
17
|
+
- **Scoped `SECURITY DEFINER` checks:** Trigger functions (`RETURNS trigger`), revoked functions (`REVOKE EXECUTE ... FROM PUBLIC`), and functions with both `SET search_path` and caller/membership authorization checks pass cleanly.
|
|
18
|
+
3. **OWASP API4 AI Wallet-Drain & Edge Function Surface Checks (M2-Lite):**
|
|
19
|
+
- Detects `verify_jwt = false` in `supabase/config.toml` when handlers lack webhook HMAC signatures or manual auth.
|
|
20
|
+
- Detects unauthenticated AI/LLM routes (`AI_ENDPOINT_NO_AUTH`) and authenticated LLM routes missing model allowlists, `max_tokens` caps, or per-user rate-limit/budget checks (`AI_ENDPOINT_UNBOUNDED_COST`).
|
|
21
|
+
- Strips JS/TS comments before rule matching so `// TODO: add requireAuth` comments never suppress findings.
|
|
22
|
+
- Masks all detected secret literals (`sb_secret_*`, `sk-proj-*`, `sk-ant-*`, `AIza*`, `sk_live_*`, `rk_live_*`, `whsec_*`, privileged JWTs, Postgres URIs) across all findings, `UNSUPPORTED` SQL snippets, and parser error messages.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Scan current repository (Markdown report to stdout)
|
|
30
|
+
npx rlsproof scan .
|
|
31
|
+
# Or pass a path directly:
|
|
32
|
+
npx rlsproof .
|
|
33
|
+
|
|
34
|
+
# Output SARIF 2.1.0 and fail CI on HIGH or CRITICAL findings
|
|
35
|
+
npx rlsproof scan . --format sarif --out rlsproof-report.sarif --fail-on high
|
|
36
|
+
|
|
37
|
+
# Single-pass report + compact JSON summary
|
|
38
|
+
npx rlsproof scan . --format sarif --out rlsproof-report.sarif --summary-out summary.json --quiet
|
|
39
|
+
|
|
40
|
+
# JSON output + fail on unsupported dynamic SQL statements too
|
|
41
|
+
npx rlsproof scan . --format json --strict-unsupported
|
|
42
|
+
|
|
43
|
+
# Create and enforce a baseline for existing findings
|
|
44
|
+
npx rlsproof scan . --write-baseline .rlsproof-baseline.json --fail-on none --quiet
|
|
45
|
+
npx rlsproof scan . --baseline .rlsproof-baseline.json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Local development inside this repository:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm test
|
|
52
|
+
npm run gate0
|
|
53
|
+
npm run eval:repos
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## CLI Options
|
|
59
|
+
|
|
60
|
+
| Flag | Default | Description |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `--format <md\|json\|sarif>` | `md` | Report format |
|
|
63
|
+
| `--out <file>` | stdout | Write report to file |
|
|
64
|
+
| `--summary-out <file>` | — | Write compact JSON summary (`status`, `exitCode`, counts, `parseRate`) |
|
|
65
|
+
| `--fail-on <critical\|high\|medium\|low\|none>` | `high` | Exit `1` when active findings meet or exceed severity (lower-severity hits report `status: WARN`) |
|
|
66
|
+
| `--strict-unsupported` | `false` | Also exit `1` if any `UNSUPPORTED` SQL statement is skipped |
|
|
67
|
+
| `--baseline <file>` | — | Suppress findings whose deterministic fingerprints match baseline |
|
|
68
|
+
| `--write-baseline <file>` | — | Save current finding fingerprints to baseline JSON |
|
|
69
|
+
| `--ignore-file <file>` | `.rlsproofignore` | Custom ignore file path |
|
|
70
|
+
| `--no-ignore` | `false` | Ignore `.rlsproofignore` |
|
|
71
|
+
| `--quiet` | `false` | Suppress stdout when `--out` is specified |
|
|
72
|
+
|
|
73
|
+
Exit codes: `0` pass (or findings below `--fail-on` threshold) · `1` blocking findings >= `--fail-on` (or unsupported with `--strict-unsupported`) · `2` CLI/runtime error.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Rules (`rlsproof rules`)
|
|
78
|
+
|
|
79
|
+
1. `RLS_DISABLED` (`CRITICAL`) — Exposed table missing `ENABLE ROW LEVEL SECURITY` with client grants active.
|
|
80
|
+
2. `RLS_PERMISSIVE_TAUTOLOGY` (`CRITICAL`/`HIGH`) — Permissive tautology (`USING (true)`, `1 = 1`, etc.) without covering `AS RESTRICTIVE` policy.
|
|
81
|
+
3. `RLS_INSERT_MISSING_WITH_CHECK` (`HIGH`) — `INSERT` policy omitting `WITH CHECK`.
|
|
82
|
+
4. `RLS_USER_METADATA_TRUST` (`HIGH`) — Policy authorizing via client-mutable `user_metadata` / `raw_user_meta_data`.
|
|
83
|
+
5. `SECURITY_DEFINER_UNSAFE_RPC` (`CRITICAL`/`HIGH`) — Client-callable `SECURITY DEFINER` function missing `SET search_path` or caller/tenant authorization.
|
|
84
|
+
6. `VIEW_MISSING_SECURITY_INVOKER` (`HIGH`) — Exposed view missing `WITH (security_invoker = true)`.
|
|
85
|
+
7. `STORAGE_BUCKET_OVEREXPOSED` (`CRITICAL`) — Bucket-only `storage.objects` policy without owner/folder scoping or sensitive bucket marked `public = true`.
|
|
86
|
+
8. `SECRET_HARDCODED_OR_CLIENT_EXPOSED` (`CRITICAL`) — Hardcoded service/LLM/payment secrets, credentialed remote Postgres URIs, or `VITE_`/`NEXT_PUBLIC_` privileged env variables (all redacted in reports).
|
|
87
|
+
9. `ANON_OPEN_EXPOSURE` (`HIGH`) — Open `anon` write policy, `anon` write access on RLS-disabled table, or explicit `anon EXECUTE` on unsafe `SECURITY DEFINER` RPC.
|
|
88
|
+
10. `EDGE_FUNCTION_VERIFY_JWT_DISABLED` (`HIGH`/`CRITICAL`) — Edge Function with `verify_jwt = false` and no webhook signature or manual auth verification.
|
|
89
|
+
11. `AI_ENDPOINT_NO_AUTH` (`CRITICAL`) — Server-billed LLM endpoint lacking caller authentication (OWASP API4).
|
|
90
|
+
12. `AI_ENDPOINT_UNBOUNDED_COST` (`HIGH`/`MEDIUM`) — Authenticated LLM endpoint missing `req.body.model` allowlist, `max_tokens` cap, or rate-limit/budget guard (OWASP API4).
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## `.rlsproofignore` & Inline Suppressions
|
|
95
|
+
|
|
96
|
+
`.rlsproofignore` supports comments, path globs, and rule-scoped patterns:
|
|
97
|
+
|
|
98
|
+
```gitignore
|
|
99
|
+
# Skip seed/archive files
|
|
100
|
+
supabase/seed.sql
|
|
101
|
+
legacy/**
|
|
102
|
+
|
|
103
|
+
# Suppress a specific rule on a specific table or path
|
|
104
|
+
rule:RLS_DISABLED:public.public_lookup_cache
|
|
105
|
+
rule:AI_ENDPOINT_UNBOUNDED_COST:app/api/internal-embed/*
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Inline suppressions:
|
|
109
|
+
- SQL: `-- rlsproof-ignore RLS_DISABLED`
|
|
110
|
+
- JS/TS: `// rlsproof-ignore AI_ENDPOINT_UNBOUNDED_COST`
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## GitHub Action (`action.yml`)
|
|
115
|
+
|
|
116
|
+
```yaml
|
|
117
|
+
name: rlsproof
|
|
118
|
+
on: [pull_request]
|
|
119
|
+
|
|
120
|
+
jobs:
|
|
121
|
+
security:
|
|
122
|
+
runs-on: ubuntu-latest
|
|
123
|
+
permissions:
|
|
124
|
+
contents: read
|
|
125
|
+
security-events: write
|
|
126
|
+
steps:
|
|
127
|
+
- uses: actions/checkout@v4
|
|
128
|
+
- uses: umut-dpc/rlsproof@v1
|
|
129
|
+
with:
|
|
130
|
+
path: .
|
|
131
|
+
format: sarif
|
|
132
|
+
output: rlsproof-report.sarif
|
|
133
|
+
fail-on: high
|
|
134
|
+
- uses: github/codeql-action/upload-sarif@v3
|
|
135
|
+
if: always()
|
|
136
|
+
with:
|
|
137
|
+
sarif_file: rlsproof-report.sarif
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
> Note: The composite GitHub Action is currently verified on Linux (`ubuntu-latest`) runners.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Calibration & Static Scope Limitations
|
|
145
|
+
|
|
146
|
+
- **Calibration Set:** Evaluated across **12 anonymized open-source Supabase repositories** (**243 SQL migration files**, **2,311 / 2,311 statements parsed = 100.00%** on `node v26.13.1`), yielding **33 flagged findings** with **1/33 (`3.03%`) in-sample false-positive share among flagged findings** (from dynamic `DO $$` `REVOKE`, explicitly surfaced in `UNSUPPORTED / SKIPPED`). This is an in-sample calibration measure rather than an unseen-holdout negative FPR or FN benchmark. Details in [CALIBRATION.md](https://github.com/umut-dpc/rlsproof/blob/main/CALIBRATION.md).
|
|
147
|
+
- **Static Scope Limitations:** M2-Lite JS/TS authentication, model-allowlist, and rate-limit/budget checks operate via comment-stripped single-file pattern analysis rather than full inter-procedural data-flow analysis, so custom helper wrappers or middleware in separate files may require `.rlsproofignore` or inline suppression. Dynamic PL/pgSQL (`DO $$`) and non-PostgreSQL extensions outside `libpg-query` grammar are reported under `UNSUPPORTED / SKIPPED`.
|
|
148
|
+
|
|
149
|
+
## Security & License
|
|
150
|
+
|
|
151
|
+
- See [SECURITY.md](https://github.com/umut-dpc/rlsproof/blob/main/SECURITY.md) for responsible disclosure.
|
|
152
|
+
- Licensed under [MIT](https://github.com/umut-dpc/rlsproof/blob/main/LICENSE).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Scope and Design Guarantee
|
|
4
|
+
|
|
5
|
+
`rlsproof` is a **defensive, local-only** static analysis tool:
|
|
6
|
+
|
|
7
|
+
- It runs entirely on local files (`0` network requests, `0` telemetry, `0` database connections).
|
|
8
|
+
- It never connects to live databases, remote APIs, or production environments.
|
|
9
|
+
- Secret values matched during scanning—including matches inside `UNSUPPORTED` SQL snippets or parser diagnostics—are redacted before reports are emitted in Markdown, JSON, or SARIF.
|
|
10
|
+
|
|
11
|
+
## Supported Versions
|
|
12
|
+
|
|
13
|
+
Only the latest `1.x` release line is supported with security updates.
|
|
14
|
+
|
|
15
|
+
## Reporting a Vulnerability
|
|
16
|
+
|
|
17
|
+
If you discover a secret-redaction bypass, false-negative security defect, or parser/CLI vulnerability in `rlsproof`, please report it privately via **GitHub Security Advisories** on the `umut-dpc/rlsproof` repository rather than opening a public issue.
|
|
18
|
+
|
|
19
|
+
Please include:
|
|
20
|
+
|
|
21
|
+
1. A minimal synthetic reproduction (never real production credentials or private customer data).
|
|
22
|
+
2. Expected vs. observed behavior and output format (`md`, `json`, or `sarif`).
|
|
23
|
+
3. Node.js and `rlsproof` version (`rlsproof --version`).
|
package/action.yml
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
name: "rlsproof Static Security Scan"
|
|
2
|
+
description: "Defensive local static scanner for Supabase PostgreSQL RLS migrations, secrets, Edge Function JWT gates, and OWASP API4 AI endpoints."
|
|
3
|
+
|
|
4
|
+
branding:
|
|
5
|
+
icon: "shield"
|
|
6
|
+
color: "green"
|
|
7
|
+
|
|
8
|
+
inputs:
|
|
9
|
+
path:
|
|
10
|
+
description: "Target repository or SQL path to scan"
|
|
11
|
+
required: false
|
|
12
|
+
default: "."
|
|
13
|
+
format:
|
|
14
|
+
description: "Output report format (md, json, sarif)"
|
|
15
|
+
required: false
|
|
16
|
+
default: "sarif"
|
|
17
|
+
output:
|
|
18
|
+
description: "Output report file path"
|
|
19
|
+
required: false
|
|
20
|
+
default: "rlsproof-report.sarif"
|
|
21
|
+
fail-on:
|
|
22
|
+
description: "Minimum severity to fail the step (critical, high, medium, low, none)"
|
|
23
|
+
required: false
|
|
24
|
+
default: "high"
|
|
25
|
+
baseline:
|
|
26
|
+
description: "Optional baseline JSON path to suppress known findings"
|
|
27
|
+
required: false
|
|
28
|
+
default: ""
|
|
29
|
+
strict-unsupported:
|
|
30
|
+
description: "Fail if unsupported SQL statements are encountered (true/false)"
|
|
31
|
+
required: false
|
|
32
|
+
default: "false"
|
|
33
|
+
node-version:
|
|
34
|
+
description: "Node.js version to configure via actions/setup-node"
|
|
35
|
+
required: false
|
|
36
|
+
default: "22"
|
|
37
|
+
|
|
38
|
+
outputs:
|
|
39
|
+
findings-count:
|
|
40
|
+
description: "Total active findings count"
|
|
41
|
+
value: ${{ steps.run-rlsproof.outputs.findings_count }}
|
|
42
|
+
critical-count:
|
|
43
|
+
description: "Critical findings count"
|
|
44
|
+
value: ${{ steps.run-rlsproof.outputs.critical_count }}
|
|
45
|
+
high-count:
|
|
46
|
+
description: "High findings count"
|
|
47
|
+
value: ${{ steps.run-rlsproof.outputs.high_count }}
|
|
48
|
+
unsupported-count:
|
|
49
|
+
description: "Unsupported SQL statements count"
|
|
50
|
+
value: ${{ steps.run-rlsproof.outputs.unsupported_count }}
|
|
51
|
+
report-path:
|
|
52
|
+
description: "Generated report path"
|
|
53
|
+
value: ${{ steps.run-rlsproof.outputs.report_path }}
|
|
54
|
+
|
|
55
|
+
runs:
|
|
56
|
+
using: "composite"
|
|
57
|
+
steps:
|
|
58
|
+
- name: Setup Node.js
|
|
59
|
+
uses: actions/setup-node@v4
|
|
60
|
+
with:
|
|
61
|
+
node-version: ${{ inputs.node-version }}
|
|
62
|
+
|
|
63
|
+
- name: Install rlsproof dependencies
|
|
64
|
+
shell: bash
|
|
65
|
+
run: |
|
|
66
|
+
cd "${{ github.action_path }}"
|
|
67
|
+
npm ci --omit=dev
|
|
68
|
+
|
|
69
|
+
- name: Run rlsproof scan
|
|
70
|
+
id: run-rlsproof
|
|
71
|
+
shell: bash
|
|
72
|
+
env:
|
|
73
|
+
INPUT_PATH: ${{ inputs.path }}
|
|
74
|
+
INPUT_FORMAT: ${{ inputs.format }}
|
|
75
|
+
INPUT_OUTPUT: ${{ inputs.output }}
|
|
76
|
+
INPUT_FAIL_ON: ${{ inputs.fail-on }}
|
|
77
|
+
INPUT_BASELINE: ${{ inputs.baseline }}
|
|
78
|
+
INPUT_STRICT_UNSUPPORTED: ${{ inputs.strict-unsupported }}
|
|
79
|
+
run: |
|
|
80
|
+
set -euo pipefail
|
|
81
|
+
SUMMARY_TMP="$(mktemp)"
|
|
82
|
+
trap 'rm -f "$SUMMARY_TMP"' EXIT
|
|
83
|
+
|
|
84
|
+
ARGS=(scan "$INPUT_PATH" --format "$INPUT_FORMAT" --out "$INPUT_OUTPUT" --summary-out "$SUMMARY_TMP" --fail-on "$INPUT_FAIL_ON" --quiet)
|
|
85
|
+
if [ -n "$INPUT_BASELINE" ]; then
|
|
86
|
+
ARGS+=(--baseline "$INPUT_BASELINE")
|
|
87
|
+
fi
|
|
88
|
+
if [ "$INPUT_STRICT_UNSUPPORTED" = "true" ]; then
|
|
89
|
+
ARGS+=(--strict-unsupported)
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
set +e
|
|
93
|
+
node "${{ github.action_path }}/bin/rlsproof.js" "${ARGS[@]}"
|
|
94
|
+
SCAN_EXIT=$?
|
|
95
|
+
set -e
|
|
96
|
+
|
|
97
|
+
if [ "$SCAN_EXIT" -eq 2 ] || [ ! -s "$SUMMARY_TMP" ] || [ ! -f "$INPUT_OUTPUT" ]; then
|
|
98
|
+
echo "::error::rlsproof failed to produce a valid report (exit code: $SCAN_EXIT)"
|
|
99
|
+
exit 2
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
node -e '
|
|
103
|
+
const fs = require("fs");
|
|
104
|
+
const data = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
105
|
+
const out = process.env.GITHUB_OUTPUT;
|
|
106
|
+
fs.appendFileSync(out, `findings_count=${data.summary.total}\n`);
|
|
107
|
+
fs.appendFileSync(out, `critical_count=${data.summary.critical}\n`);
|
|
108
|
+
fs.appendFileSync(out, `high_count=${data.summary.high}\n`);
|
|
109
|
+
fs.appendFileSync(out, `unsupported_count=${data.unsupportedCount}\n`);
|
|
110
|
+
fs.appendFileSync(out, `report_path=${process.argv[2]}\n`);
|
|
111
|
+
' "$SUMMARY_TMP" "$INPUT_OUTPUT"
|
|
112
|
+
|
|
113
|
+
exit "$SCAN_EXIT"
|
package/bin/rlsproof.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { RULE_LIST } from "../src/core/rules.js";
|
|
5
|
+
import { scanProject, shouldFailForFindings, TOOL_VERSION } from "../src/index.js";
|
|
6
|
+
import { formatJsonReport } from "../src/reporters/json.js";
|
|
7
|
+
import { formatMarkdownReport } from "../src/reporters/markdown.js";
|
|
8
|
+
import { formatSarifReport } from "../src/reporters/sarif.js";
|
|
9
|
+
|
|
10
|
+
function printHelp() {
|
|
11
|
+
console.log(`rlsproof v${TOOL_VERSION} — Defensive Supabase RLS, Secrets & OWASP API4 Static Scanner
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
rlsproof scan [path] [options]
|
|
15
|
+
rlsproof <path> [options]
|
|
16
|
+
rlsproof rules
|
|
17
|
+
rlsproof --version
|
|
18
|
+
rlsproof --help
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
--format <md|json|sarif> Output format (default: md)
|
|
22
|
+
--out <file> Write report to file (stdout when omitted)
|
|
23
|
+
--summary-out <file> Write compact scan summary JSON (status, counts, exitCode)
|
|
24
|
+
--fail-on <critical|high|medium|low|none>
|
|
25
|
+
Minimum severity that causes exit code 1 (default: high)
|
|
26
|
+
--strict-unsupported Also exit 1 if any UNSUPPORTED SQL statement is encountered
|
|
27
|
+
--baseline <file> Suppress known findings matching baseline fingerprints
|
|
28
|
+
--write-baseline <file> Write current finding fingerprints to baseline JSON file
|
|
29
|
+
--ignore-file <file> Path to custom .rlsproofignore file
|
|
30
|
+
--no-ignore Disable .rlsproofignore loading
|
|
31
|
+
--quiet Suppress stdout report when --out is set
|
|
32
|
+
-v, --version Print version
|
|
33
|
+
-h, --help Show this help
|
|
34
|
+
|
|
35
|
+
Exit codes:
|
|
36
|
+
0 Pass or below --fail-on threshold
|
|
37
|
+
1 Blocking findings detected (or unsupported with --strict-unsupported)
|
|
38
|
+
2 CLI argument or runtime error`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function consumeOptionValue(args, nextIndex, flagName) {
|
|
42
|
+
const val = args[nextIndex];
|
|
43
|
+
if (!val || val.startsWith("-")) {
|
|
44
|
+
throw new Error(`Missing value for ${flagName}.`);
|
|
45
|
+
}
|
|
46
|
+
return val;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseArgs(argv) {
|
|
50
|
+
const args = [...argv];
|
|
51
|
+
if (args.length === 0) {
|
|
52
|
+
return { command: "help" };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const first = args[0];
|
|
56
|
+
if (first === "-h" || first === "--help") return { command: "help" };
|
|
57
|
+
if (first === "-v" || first === "--version") return { command: "version" };
|
|
58
|
+
if (first === "rules") return { command: "rules" };
|
|
59
|
+
|
|
60
|
+
let command = "scan";
|
|
61
|
+
let index = 0;
|
|
62
|
+
if (first === "scan") {
|
|
63
|
+
index = 1;
|
|
64
|
+
} else if (first.startsWith("-") || fs.existsSync(first)) {
|
|
65
|
+
command = "scan";
|
|
66
|
+
index = 0;
|
|
67
|
+
} else {
|
|
68
|
+
throw new Error(`Unknown command "${first}". Use "rlsproof scan [path]" or "--help".`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const opts = {
|
|
72
|
+
target: ".",
|
|
73
|
+
format: "md",
|
|
74
|
+
out: null,
|
|
75
|
+
summaryOut: null,
|
|
76
|
+
failOn: "high",
|
|
77
|
+
strictUnsupported: false,
|
|
78
|
+
baseline: null,
|
|
79
|
+
writeBaseline: null,
|
|
80
|
+
ignoreFile: null,
|
|
81
|
+
noIgnore: false,
|
|
82
|
+
quiet: false,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let targetSet = false;
|
|
86
|
+
|
|
87
|
+
while (index < args.length) {
|
|
88
|
+
const tok = args[index];
|
|
89
|
+
if (tok === "-h" || tok === "--help") {
|
|
90
|
+
return { command: "help" };
|
|
91
|
+
}
|
|
92
|
+
if (tok === "-v" || tok === "--version") {
|
|
93
|
+
return { command: "version" };
|
|
94
|
+
}
|
|
95
|
+
if (tok === "--format") {
|
|
96
|
+
const val = consumeOptionValue(args, ++index, "--format");
|
|
97
|
+
if (!["md", "json", "sarif"].includes(val)) {
|
|
98
|
+
throw new Error(`Invalid --format "${val}". Expected md, json, or sarif.`);
|
|
99
|
+
}
|
|
100
|
+
opts.format = val;
|
|
101
|
+
} else if (tok === "--out") {
|
|
102
|
+
opts.out = consumeOptionValue(args, ++index, "--out");
|
|
103
|
+
} else if (tok === "--summary-out") {
|
|
104
|
+
opts.summaryOut = consumeOptionValue(args, ++index, "--summary-out");
|
|
105
|
+
} else if (tok === "--fail-on") {
|
|
106
|
+
const val = consumeOptionValue(args, ++index, "--fail-on").toLowerCase();
|
|
107
|
+
if (!["critical", "high", "medium", "low", "none"].includes(val)) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Invalid --fail-on "${val}". Expected critical, high, medium, low, or none.`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
opts.failOn = val;
|
|
113
|
+
} else if (tok === "--strict-unsupported") {
|
|
114
|
+
opts.strictUnsupported = true;
|
|
115
|
+
} else if (tok === "--baseline") {
|
|
116
|
+
opts.baseline = consumeOptionValue(args, ++index, "--baseline");
|
|
117
|
+
} else if (tok === "--write-baseline") {
|
|
118
|
+
opts.writeBaseline = consumeOptionValue(args, ++index, "--write-baseline");
|
|
119
|
+
} else if (tok === "--ignore-file") {
|
|
120
|
+
opts.ignoreFile = consumeOptionValue(args, ++index, "--ignore-file");
|
|
121
|
+
} else if (tok === "--no-ignore") {
|
|
122
|
+
opts.noIgnore = true;
|
|
123
|
+
} else if (tok === "--quiet") {
|
|
124
|
+
opts.quiet = true;
|
|
125
|
+
} else if (tok.startsWith("-")) {
|
|
126
|
+
throw new Error(`Unknown option "${tok}".`);
|
|
127
|
+
} else if (!targetSet) {
|
|
128
|
+
opts.target = tok;
|
|
129
|
+
targetSet = true;
|
|
130
|
+
} else {
|
|
131
|
+
throw new Error(`Unexpected extra positional argument "${tok}".`);
|
|
132
|
+
}
|
|
133
|
+
index += 1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return { command, opts };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function main() {
|
|
140
|
+
let parsed;
|
|
141
|
+
try {
|
|
142
|
+
parsed = parseArgs(process.argv.slice(2));
|
|
143
|
+
} catch (err) {
|
|
144
|
+
console.error(`Error: ${err.message}`);
|
|
145
|
+
process.exit(2);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (parsed.command === "help") {
|
|
149
|
+
printHelp();
|
|
150
|
+
process.exit(0);
|
|
151
|
+
}
|
|
152
|
+
if (parsed.command === "version") {
|
|
153
|
+
console.log(TOOL_VERSION);
|
|
154
|
+
process.exit(0);
|
|
155
|
+
}
|
|
156
|
+
if (parsed.command === "rules") {
|
|
157
|
+
for (const r of RULE_LIST) {
|
|
158
|
+
console.log(`${r.id} [${r.severity}] (${r.category}) — ${r.title}`);
|
|
159
|
+
}
|
|
160
|
+
process.exit(0);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const { opts } = parsed;
|
|
164
|
+
let result;
|
|
165
|
+
try {
|
|
166
|
+
result = await scanProject(opts.target, {
|
|
167
|
+
failOn: opts.failOn,
|
|
168
|
+
baseline: opts.baseline,
|
|
169
|
+
writeBaseline: opts.writeBaseline,
|
|
170
|
+
ignoreFile: opts.ignoreFile,
|
|
171
|
+
noIgnore: opts.noIgnore,
|
|
172
|
+
});
|
|
173
|
+
} catch (err) {
|
|
174
|
+
console.error(`Scan error: ${err.message}`);
|
|
175
|
+
process.exit(2);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let outputText = "";
|
|
179
|
+
if (opts.format === "json") {
|
|
180
|
+
outputText = formatJsonReport(result);
|
|
181
|
+
} else if (opts.format === "sarif") {
|
|
182
|
+
outputText = formatSarifReport(result);
|
|
183
|
+
} else {
|
|
184
|
+
outputText = formatMarkdownReport(result);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const failedFindings = shouldFailForFindings(result.findings, opts.failOn);
|
|
188
|
+
const failedUnsupported = opts.strictUnsupported && result.unsupported.length > 0;
|
|
189
|
+
const exitCode = failedFindings || failedUnsupported ? 1 : 0;
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
if (opts.out) {
|
|
193
|
+
const outAbs = path.resolve(opts.out);
|
|
194
|
+
fs.mkdirSync(path.dirname(outAbs), { recursive: true });
|
|
195
|
+
fs.writeFileSync(outAbs, outputText, "utf8");
|
|
196
|
+
if (!opts.quiet) {
|
|
197
|
+
process.stdout.write(outputText);
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
process.stdout.write(outputText);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (opts.summaryOut) {
|
|
204
|
+
const sumAbs = path.resolve(opts.summaryOut);
|
|
205
|
+
fs.mkdirSync(path.dirname(sumAbs), { recursive: true });
|
|
206
|
+
fs.writeFileSync(
|
|
207
|
+
sumAbs,
|
|
208
|
+
`${JSON.stringify(
|
|
209
|
+
{
|
|
210
|
+
status: result.status,
|
|
211
|
+
exitCode,
|
|
212
|
+
summary: result.summary,
|
|
213
|
+
unsupportedCount: result.unsupported.length,
|
|
214
|
+
parseRate: result.parseStats.parseRate,
|
|
215
|
+
},
|
|
216
|
+
null,
|
|
217
|
+
2
|
|
218
|
+
)}\n`,
|
|
219
|
+
"utf8"
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
} catch (ioErr) {
|
|
223
|
+
console.error(`Output error: ${ioErr.message}`);
|
|
224
|
+
process.exit(2);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
process.exit(exitCode);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rlsproof",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Defensive local-only static analyzer for Supabase PostgreSQL RLS state graphs, secrets, Edge Function JWT gates, and OWASP API4 AI endpoint cost protection.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20.0.0"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"rlsproof": "bin/rlsproof.js"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node --test test/*.test.js",
|
|
18
|
+
"gate0": "node scripts/gate0-libpg-query.mjs",
|
|
19
|
+
"eval:repos": "node scripts/eval-repos.mjs",
|
|
20
|
+
"prepublishOnly": "npm test"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"supabase",
|
|
24
|
+
"postgresql",
|
|
25
|
+
"rls",
|
|
26
|
+
"security",
|
|
27
|
+
"owasp-api4",
|
|
28
|
+
"static-analysis",
|
|
29
|
+
"sarif"
|
|
30
|
+
],
|
|
31
|
+
"author": "Umit Dopac",
|
|
32
|
+
"homepage": "https://github.com/umut-dpc/rlsproof#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/umut-dpc/rlsproof/issues"
|
|
35
|
+
},
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/umut-dpc/rlsproof.git"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"bin/",
|
|
42
|
+
"src/",
|
|
43
|
+
"action.yml",
|
|
44
|
+
"README.md",
|
|
45
|
+
"CALIBRATION.md",
|
|
46
|
+
"SECURITY.md",
|
|
47
|
+
"LICENSE"
|
|
48
|
+
],
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"libpg-query": "18.3.0"
|
|
51
|
+
}
|
|
52
|
+
}
|