Repository navigation
feat(rules): security/supabase-rls counts rows the anon key can see with a HEAD request (repo#1959) - #1883
Conversation
|
Review requirement before merge: the probe should prove exposure without downloading anyone's data. Today |
|
Decision: only the HEAD +
|
71304b8 to
41a3482
Compare
cb4b228 to
dbfaf9e
Compare
|
Review requirement (2026-11-15, from #1920): a probe answered with 429, a 401/403 bot challenge, an HTML challenge page (cf-mitigated, Cloudflare or WAF challenge markers), 5xx or a timeout must make the target UNVERIFIED. The rule then reports not checked or incomplete, never passed. Only a genuine 404, or a non-challenge answer, counts as not exposed. Please add a stub test for a 429 and for a 403 HTML challenge. |
86f648c to
69c4b6c
Compare
…answered #1883 planned now uses every deduped table the code names, so a ninth table never probed keeps the run not checked instead of a pass. tablesCapped includes the per-project cap drops, and the cap reason names the 8-tables-per-project cap. Signed-off-by: Nik Cubrilovic <[email protected]>
…answered #1883 planned now uses every deduped table the code names, so a ninth table never probed keeps the run not checked instead of a pass. tablesCapped includes the per-project cap drops, and the cap reason names the 8-tables-per-project cap. Signed-off-by: Nik Cubrilovic <[email protected]>
a14215c to
db33672
Compare
…e.externalLinks #1883 The rule reads site.externalLinks === undefined as "this audit may not request other hosts". The rule context has no other signal for that, so it joins LINK_VERDICT_RULE_IDS and runs in the late pass, after the link check binds the field (repo#2144). Adds an engine test that fails when the rule runs in the first pass, and a rule test that external link checking on with zero links still probes. Signed-off-by: Nik Cubrilovic <[email protected]>
… can count with a HEAD request (repo#1959) Sends one HEAD /rest/v1/<table> with Prefer: count=exact per table the site's own code names, with the site's anon key, and judges exposure only from the status and the Content-Range total. Never a GET, never a query string, never a response body read, no guessed table names. Aggressive probing only, external requests on, at most ten requests per audit. Signed-off-by: Nik Cubrilovic <[email protected]>
… guard passes (repo#1959) Signed-off-by: Nik Cubrilovic <[email protected]>
… its query string or fragment (repo#1959) Signed-off-by: Nik Cubrilovic <[email protected]>
…definite answer (repo#1959) A 429, a bot challenge or a 403 with WAF markers stops the run and is never read as protected. Pushback, a network error, an answer without a usable total, or a table or project left out by the caps makes the run probe-incomplete (not checked) instead of a pass that clears the rule. The key's source URL drops userinfo as well as query and fragment. The rule page documents waiving a public table with [[ignore]], and the canonical golden gains its one per-rule line. Signed-off-by: Nik Cubrilovic <[email protected]>
…answered #1883 planned now uses every deduped table the code names, so a ninth table never probed keeps the run not checked instead of a pass. tablesCapped includes the per-project cap drops, and the cap reason names the 8-tables-per-project cap. Signed-off-by: Nik Cubrilovic <[email protected]>
…d, names the budget cap (repo#1959) Signed-off-by: Nik Cubrilovic <[email protected]>
…e.externalLinks #1883 The rule reads site.externalLinks === undefined as "this audit may not request other hosts". The rule context has no other signal for that, so it joins LINK_VERDICT_RULE_IDS and runs in the late pass, after the link check binds the field (repo#2144). Adds an engine test that fails when the rule runs in the first pass, and a rule test that external link checking on with zero links still probes. Signed-off-by: Nik Cubrilovic <[email protected]>
db33672 to
6f5df51
Compare
…answered #1883 planned now uses every deduped table the code names, so a ninth table never probed keeps the run not checked instead of a pass. tablesCapped includes the per-project cap drops, and the cap reason names the 8-tables-per-project cap. Signed-off-by: Nik Cubrilovic <[email protected]>
Adds
security/supabase-rlsfor squirrelscan/repo#1959 (part of repo#1952, policy per repo#1931). HOLD-LIST (security): planning reviews this at Opus depth before merge.Revised per the planning decision: no row is ever read.
What it does
The rule reads the scripts and inline scripts the crawl already fetched, looking for a Supabase project URL (
<ref>.supabase.co), an anon key, and the table names the site's own code queries (.from("x").select(...)chains,/rest/v1/xURLs). For each such table it sends one request:No query string, no
select=, never aGET. The response body is never read, even if a server sends one to the HEAD.Exposure is judged only from the status and the
Content-Rangetotal:2xxwith total > 0: exposed (fail). The finding names the table and the row count, nothing else.429, a bot challenge (cf-mitigated: challenge) or a403with WAF/challenge markers (isThrottledOrChallengedfromprobe-http): pushback. Never protected; the run stops, no further request.401/ a plain403(PostgREST answers42501with these): protected.2xxwith total0(*/0): not flagged. RLS hiding every row and an empty table look the same; the docs say so.404: missing table.2xxwithout a numeric total, or a network error: not checked.A pass clears only what got a definite answer. The rule passes only when every table the code names, in every project found, answered 401, a plain 403, a zero total or 404. Pushback, an error, an unusable answer, a budget stop, or a table or project left out by the caps makes the run skipped
probe-incompletewithvalue: "not-checked"(or the narrowerprobe-budget/probe-errors/probe-inconclusivewhen only that applies), never a pass.keySourcedrops userinfo as well as query and fragment.Intentionally public tables:
[[ignore]](pub#1262) waives one by item id, e.g.items = ["glob:*/rest/v1/posts"]; the rule page documents it. A bare table name (items = ["posts"]) does not match, because the item id is<host>/rest/v1/<table>and the label carries the row count.No table names are guessed (
users,profiles,ordersare gone). A project whose code names no table is skippedno-tables-in-codeand nothing is sent. No column names are reported at all.Safety (unchanged):
--probe aggressive. Cloud audits of unverified websites stay passive and never send.site.externalLinksis undefined (--offline, or external checks off).<ref>.supabase.co|in(strict 20-char ref), through the egress guard (no private, link-local or metadata addresses, pinned to the vetted IP). No cookies, no custom audit headers,redirect: manual, 10 s per-request timeout, shared probe budget.iss: supabase,role: anonand a validref, sent only to that project; asb_publishable_key only when its script names exactly one project. Service-role andsb_secret_keys are never used.graphql-probe.tsis no longer touched (no body reader needed).Acceptance criteria
/rest/v1tables and flags tables the anon key can see rows in. Tests:a table reporting rows is flagged from its count; no body is read and no value leaks,the probe is a HEAD with a row count on the project host, with the anon key.tables behind RLS (401, 403, a zero total) or missing are not flagged,response classification uses only the status and the Content-Range total,answers without a usable total are not checked, never a pass.HEADwith no query string, the stub body is never pulled (a countingReadableStream), and none of the values (or their field names) appear in the serialized rule result (checks, items, details) or any console line.table probes are capped across the run, and a capped run is not a pass,a 401 then 429s: the run stops at the first 429 and is not a pass,a bot challenge 403 (cf-mitigated) is not protected and not a pass,a network error on one table makes the run not checked, not a pass,a planted sb_secret_ key sends nothing and never appears in the result,passive, active or no probe budget: skipped, nothing sent,offline or external requests off: skipped, nothing sent,no guessed tables: a project whose code names no table sends nothing,a project host that resolves to a private address is refused, nothing sent,a zero probe budget sends nothing and is not a pass.Docs and counts
Rebased onto main after pub#2056; counts recomputed from
loadAllRules(): 341 rules, 32 in Security. Updateddocs/rules/security/supabase-rls.mdx(HEAD-only probe, verdict table incl. pushback, results incl.probe-incomplete, waiving a public table with[[ignore]]), the "Rules that probe" table indocs/configuration/security.mdx,docs.json, the regenerated security hub, Security counts inREADME.md,docs/index.mdx,docs/rules/index.mdx, and CHANGELOG[Unreleased]/ Added. Golden: one line"security/supabase-rls": 1incanonical-rule-totals.json; the finding-messages snapshot gains this rule's one skipped entry.Gates
packages/rules:supabase-rls,rule-check-declarations,rule-verdict-scope,docs-index-rule-counts,docs-rule-pages(--timeout 30000): 452 pass, 0 fail.supabase-rlsalone: 24 pass; 5 of the new/rewritten tests fail on the pre-fix rule (86f648c).packages/audit-engine:streaming-rules-canonical-golden: 1 pass;golden-finding-messages-229: 3 pass.packages/rules(src + tests) andpackages/audit-engine: pass.make validateindocs/: all checks passed, links good, 62 pass.Agent skill
The squirrelscan agent skill does not need a change: it lists rule categories, not individual probing rules.
Round 5 (a14215c): HTML error pages are not a definite answer
packages/rules/src/security/supabase-rls.ts:279-284,isHtmlat :294): after the pushback check, a 401, 403 or 404 whoseContent-Typemedia type istext/html(any case, any parameters) isother: not protected, not missing. A JSON content type, or none at all, keeps today's meaning. An all-HTML run lands in the existing all-unanswered branch (probe-inconclusive, skipped); a mix with definite answers isprobe-incomplete. Neither is a pass.packages/rules/tests/supabase-rls.test.ts):an HTML 401, 403 or 404 is not a definite answer; JSON or no content type keeps its meaning(:326; coversclassifyTableResponse(403, null, text/html)not protected, JSON 403 still protected, JSON 404 still missing, no content type unchanged),a run where every table answers an HTML 403 / 404 / 401 block page is not a pass(:657),an HTML 403 among JSON answers leaves the run probe-incomplete(:677),JSON 403 (PostgREST 42501) and JSON 404 answers still pass, and the zero-budget test now asserts the cap reason and0 of 1(:764). On 353940c: 25 pass, 6 fail (the 6 new/extended assertions); after: 31 pass, 0 fail.supabase-rls.ts:572-580, 612, 629): names the cap and how far it got, e.g.No Supabase table was probed: the shared probe time budget of 60 s for all probing rules ran out first (0 of 3 table probe(s) sent)and... ran out after 2 of 5 table probe(s) ...; the probe-incomplete reason list uses the same wording.probe-incompletelist (docs/rules/security/supabase-rls.mdx:51,57-60,74). The CHANGELOG bullet's "judges only the status and the row total" now includes the content type and lists an HTML 401, 403 or 404 page among the not-checked answers (CHANGELOG.md:36).supabase-rls,rule-verdict-scope,streaming-rules-canonical-golden,golden-finding-messages-229(--timeout 30000): 406 pass, 0 fail. Typecheckpackages/rules(src + tests): pass.make validateindocs/: pass, 62 pass.Round 6: rule order vs the link check (head db33672)
Rebased onto main (ecd2703, no conflicts).
What
site.externalLinksis in each casesite.externalLinks--offlineundefinedapps/cli/src/controllers/audit.ts:3389-3390setsexternal_links.enabled = false; the engine maps that toundefinedatpackages/audit-engine/src/adapter.ts:2069(v1),:3017(streaming first pass),:3701(late pass)--no-external-links,[external_links] enabled = false, targeted run)undefinedcontrollers/audit.ts:3389[]adapter.ts:2742-2787(readExternalLinkVerdictsalways returns an array), bound at:3698-3701adapter.ts:2742-2787,:3698-3701outOfTime)late-link-verdicts.ts:17-18,adapter.ts:2770[]before any verdict), read before the check is boundadapter.ts:2833,:3679-3691So
undefinedmeans "link checking off" in every engine path. In practice the a14215c first-pass read gets[], notundefined. Today the "skipped as external-requests-off" symptom can't happen in the engine, but the rule reads a field the link check fills before that field is bound. That breaks the repo#2144 contract and is whylink-verdict-rules-2144.test.tsis red.Fix
RuleContexthas no offline or external-requests flag (packages/rules/src/types.ts:760-840;ctx.probecarries only level and budget).reliability/broken-formsreads the same field the same way and is listed. Sosecurity/supabase-rlsjoinsLINK_VERDICT_RULE_IDS(packages/rules/src/link-verdict-rules.ts) and runs in the late pass, after the link check binds the field. A comment at the read (supabase-rls.ts:443-448) records why. With checking on and zero links the field is[], which reads as on.Tests
packages/audit-engine/tests/late-link-verdicts-2144.test.ts"security/supabase-rls runs after the link check binds site.externalLinks, not before it": an online late-binding run. It fails with the list change reverted (rule in the first pass:Expected: > 1, Received: 0) and passes after.packages/rules/tests/supabase-rls.test.ts"external link checking on with zero external links is not off: the table is probed" (new). "offline or external requests off: skipped, nothing sent" still passes.packages/rules/tests/link-verdict-rules-2144.test.ts: green.Gates
bun run scripts/test-suites.ts --run rules:11296 pass, 25 todo, 0 fail(378 files)golden-baseline,golden-finding-messages-229,late-link-verdicts-2144: 17 pass, 0 failpackages/rulestypecheck (src + tests) andpackages/audit-enginetypecheck: clean--offline, external link checking on", so they are unchanged. No docs change, so nomake validate.Residual risk
The rule now starts after the link verdict deadline. That deadline holds back
LINK_RULES_RESERVE_MS(30 s) before a run deadline, but the rule can probe for up to 10 requests × 10 s, inside a probe budget whose clock other probes may already have started. On a deadline-bound aggressive run the rule may hit the budget cap more often (reported as not checked, never as a pass) or run past the reserve. Hosted runs are locked passive unless ownership is verified, which limits this to verified hosted aggressive runs and local runs (which have no run deadline). A dedicated "external requests allowed"SiteDataflag would remove the dependency; I left it as a follow-up.The squirrelscan agent skill needs no change.