Documentation
¶
Overview ¶
Package supabase holds the Supabase scan expressed as pipeline stages.
It is the destination of the port. Today the whole Supabase scan lives in scanTarget() in cmd/unruly/main.go -- one 1,390-line function whose twelve author-marked sections are the stages below. Each section moves here one at a time, with its own test, and the old call site is retired only once parity is proven: the existing code encodes PostgREST behaviour learned the hard way (206 is a counted read, 204 means a write succeeded, a zero-match DELETE returns 204 whether or not it was allowed) that must survive the move.
Index ¶
- Variables
- func MergeSeeds(s SeedSources) []string
- func Stages(cfg Config) []scan.Stage
- type Config
- type CoverageStage
- type Credential
- type EnumerateOutcome
- type EnumerateStage
- type Escalation
- type EscalationStage
- type GraphQLStage
- type HistoryStage
- type PreviewStage
- type ProbeStage
- type RealtimeOutcome
- type RealtimeStage
- type SchemaEscalation
- type SchemaRealtime
- type SchemaScan
- type Schemas
- type SchemasStage
- type SeedOrigins
- type SeedSources
- type SelfCheckStage
- type SubdomainStage
- type SurfaceStage
- type Vocabulary
- type VocabularyStage
Constants ¶
This section is empty.
Variables ¶
var ( ArtVocabulary = scan.ArtifactOf[Vocabulary]() ArtRelations = scan.ArtifactOf[EnumerateOutcome]() ArtSelfCheck = scan.ArtifactOf[selfcheck.Result]() ArtProbe = scan.ArtifactOf[probe.Result]() ArtSchemas = scan.ArtifactOf[Schemas]() ArtSurface = scan.ArtifactOf[surface.Result]() ArtGraphQL = scan.ArtifactOf[graphql.Result]() ArtRealtime = scan.ArtifactOf[RealtimeOutcome]() ArtHistory = scan.ArtifactOf[history.Result]() ArtPreview = scan.ArtifactOf[preview.Result]() ArtSubdomain = scan.ArtifactOf[subdomain.Result]() ArtEscalation = scan.ArtifactOf[Escalation]() ArtCredential = scan.ArtifactOf[Credential]() ArtCoverage = scan.ArtifactOf[scan.Coverage]() ArtAccess = scan.ArtifactOf[scan.Access]() )
What each stage requires and produces, declared.
The list in Stages() was already ordered by these dependencies and tested against nine of them by hand. Declaring them moves that from a test that knows the answers to a property the plan can be checked against -- including by a plan nobody wrote a test for, which is the case that matters when somebody adds a stage.
The artifact names are the Go types' names, so the two cannot drift far without being obvious.
Functions ¶
func MergeSeeds ¶
func MergeSeeds(s SeedSources) []string
MergeSeeds combines every source into the candidate list.
Delegates to wordlist.Merge in the same order main used -- harvested and supplied together, then advertised, then pinned -- so the result is identical to the expression this replaced. Merge folds, trims, deduplicates and sorts, which is what keeps probe order and therefore report order stable between runs.
func Stages ¶
Stages is the complete, ordered Supabase scan.
ORDER IS A DEPENDENCY GRAPH, not a preference. Stages hand each other typed artifacts, so probing before enumeration finds no relations to probe, and the escalation compare before probing has nothing to compare against. It is also what fixes finding order, and two scans of an unchanged project have to produce identical bytes.
A stage the operator turned off is WRAPPED, never omitted. The rule this project applies to its own checks: a row marked "not run" is not a pass. A scan that silently drops a surface reads exactly like a scan that found it clean, and two flags here once did precisely that.
Types ¶
type Config ¶
type Config struct {
Client *client.Client
// Limiter and Timeout are the operator's traffic controls, shared so every
// stage honours one budget rather than each keeping its own.
Limiter *client.Limiter
Timeout time.Duration
AnonKey string
ElevatedKey string
Site string
UserAgent string
ArchiveBase string
// PreviewHosts are extra deployment hosts to check, already split.
PreviewHosts []string
// Domain is the registrable domain for subdomain enumeration, resolved by
// the caller because it is derived from the site URL.
Domain string
// Seed sources. Harvested and Supplied describe THIS target; Advertised
// comes from the OpenAPI document; Pinned is the same everywhere.
Sources SeedSources
// HarvestSources is how many documents the harvest actually read. Zero
// with a site set is the difference between "the application told us
// nothing" and "we never asked".
HarvestSources int
Concurrency int
SampleRows int
MaxRelation int
MaxRPC int
MaxColumnProbes int
Write bool
NoResidue bool
Measure bool
Invoke bool
Redact bool
SkipRoutes bool
SkipRealtime bool
SkipSubdomains bool
CheckHistory bool
// ExtraRoutines and RPCRoutines are shared allowances. The schemas pass
// and the surface pass draw on the same RPC budget, so it travels as a
// budget rather than an int -- see SurfaceStage.RPCRoutines.
ExtraRoutines *scan.Budget
RPCRoutines *scan.Budget
}
Config is everything a Supabase scan needs that is NOT another stage's result: the operator's flags, the shared clients, and the budgets.
The distinction is the whole point. Every field here is known before the scan starts, which is what lets Stages() produce the complete ordered list up front instead of the caller building each stage as the values for it happen to become available. That was the shape scanTarget had, and it is why adding, removing or handing off a Supabase stage meant editing the command.
type CoverageStage ¶
type CoverageStage struct{}
CoverageStage translates this provider's artifacts into the neutral shape the command reports on.
It is the provider's side of the boundary: the command needs a handful of scan-level numbers for the stored summary and for the coverage finding, and it used to obtain them by reading four Supabase types. Only this package knows what those types mean, so the translation belongs here and the command reads scan.Coverage alone.
Deliberately LAST and deliberately cheap. It issues no requests and makes no decisions; it reads what the earlier stages published and states it once.
func (CoverageStage) Describe ¶
func (CoverageStage) Describe() scan.StageDescriptor
func (CoverageStage) Name ¶
func (CoverageStage) Name() string
func (CoverageStage) Run ¶
Run publishes the neutral summary.
Every input is optional. A scan cut short by a cancelled context, or one whose enumeration failed, still has a coverage figure -- a smaller one -- and refusing to publish would leave the command unable to tell "covered nothing" from "said nothing", which is the distinction it needs most when a scan ends early.
type Credential ¶
type Credential struct {
Token string
// Role is what the token claims to be, for the finding's wording.
Role string
}
Credential is an elevated token the scan ACQUIRED, as opposed to one the operator supplied.
It exists because the two arrive at different times. A supplied token is known before the stage list is built; a minted one is not -- unruly creates an account mid-scan when writes were authorised and no token was given, and that is how the middle tier of the threat model gets measured at all.
Baking the token into the stage at construction time therefore silently disabled the escalation pass on exactly the path that needs it most: the stage was wrapped as "not run: no -user-jwt was supplied" and then said so while the scan held a working credential.
type EnumerateOutcome ¶
type EnumerateOutcome struct {
Result enumerate.Result
// Retried is false when there was no second pass, which is NOT the same as
// a second pass that found nothing.
Retried bool
// Why is the operator-facing cause, decided here because only this stage
// knows which condition fired.
Why string
Candidates int
}
EnumerateOutcome is what was found, plus what the command needs to say.
type EnumerateStage ¶
EnumerateStage recovers relation names, and retries once with near-miss candidates when the first pass came back empty.
Ported from the "// ---- vocabulary + enumeration ----" section of scanTarget. This is the Enumerate phase of the provider contract: it decides what EXISTS, not whether it is exposed.
TWO LEDGER LABELS, DELIBERATELY. The first pass attributes under "relations" and the retry under "relations-retry", exactly as the inline code did. Folding them into one would erase what the retry cost -- and the retry only runs when the first pass found nothing, so an operator reading a large "relations" figure needs to know whether that was one sweep or two. runStage folds State.Spending() rather than Name() precisely so a stage can attribute under several labels.
THE STAGE DOES NOT LOG. No ported stage does: operator-facing messages stay in the command, where -silent governs them and their order is one person's decision. The retry's message needs facts only this stage has, so they come back in the outcome rather than a logger coming in.
func (EnumerateStage) Describe ¶
func (EnumerateStage) Describe() scan.StageDescriptor
func (EnumerateStage) Name ¶
func (EnumerateStage) Name() string
type Escalation ¶
type Escalation struct {
Result escalate.Result
PerSchema []SchemaEscalation
}
Escalation is what the escalation stage publishes.
Both passes, in one artifact. The default schema's comparison and the per-schema ones answer the same question -- what does signing up gain -- and a consumer holding only the first under-reports every project with an extra exposed schema, which is exactly the shape the schemas pass exists to catch.
type EscalationStage ¶
type EscalationStage struct {
Client *client.Client
ElevatedKey string
Concurrency int
SampleRows int
Redact bool
Measure bool
}
EscalationStage measures what an authenticated role reads that anonymous cannot -- for the default schema and for every other exposed schema.
Ported from the "// ---- privilege escalation ----" section of scanTarget.
WHY THIS ONE MATTERS BEYOND TIDINESS. Inline, this was the only work in the scan that spent requests with no ledger attribution at all: the other ported stages attribute through runStage/State.Spending, and the remaining inline work carries explicit spend.add labels (discovery, prefix, providers, relations, relations-retry). Escalation had neither. Since the printed breakdown is spend.summary(4) -- the top four, LARGEST FIRST -- a pass that re-probes every relation and every exposed schema with an elevated key could be the single biggest spender in the scan and still never appear in the list an operator reads to decide what to cap. Being a stage fixes that as a side effect of the move.
WHAT IS DELIBERATELY NOT HERE: escalate.Acquire. Acquisition signs up and hands back a credential, and inline it assigns o.userJWT -- a stage that mutates its caller's options is not a stage. It stays where it is and its result arrives here as ElevatedKey, so the ordering constraint is visible in this struct rather than implied by where the code happens to sit.
func (EscalationStage) Describe ¶
func (EscalationStage) Describe() scan.StageDescriptor
func (EscalationStage) Name ¶
func (EscalationStage) Name() string
type GraphQLStage ¶
type GraphQLStage struct {
Client *client.Client
SampleRows int
Concurrency int
Redact bool
// Measure DECLINES this check rather than weakening it. See Run.
Measure bool
}
GraphQLStage checks pg_graphql, a second read path over the same tables.
Ported from the "// ---- auth / storage / rpc ----" section of scanTarget. It is the one interface no surveyed scanner looks at, and it needs no consent flag: every query it issues is a read the REST pass already made.
func (GraphQLStage) Describe ¶
func (GraphQLStage) Describe() scan.StageDescriptor
func (GraphQLStage) Name ¶
func (GraphQLStage) Name() string
func (GraphQLStage) Run ¶
Run queries pg_graphql unless -measure forbids it.
GraphQL cannot participate in a measurement run. It distinguishes a readable relation from an RLS-filtered one by asking for node ids, and a node id decodes to a real row's primary key -- data. There is no count-only form of that question, so the check is skipped and SAID to be skipped rather than quietly weakened into something that looks like a clean result.
type HistoryStage ¶
type HistoryStage struct {
// Opts carries the site, the current key to compare against, the archive
// to query, and the operator's redaction choice.
Opts history.Options
}
HistoryStage looks for credentials the application shipped in the past.
Ported from the "// ---- historical exposure ----" section of scanTarget. A clean bundle today says nothing about what shipped last quarter, and removing a key from a build does not revoke it.
func (HistoryStage) Describe ¶
func (h HistoryStage) Describe() scan.StageDescriptor
func (HistoryStage) Name ¶
func (HistoryStage) Name() string
Name is stable: it appears in the spend breakdown and in the not-assessed finding the pipeline emits if this stage fails.
func (HistoryStage) Run ¶
Run queries the archive and records what it recovered.
The empty-site guard is carried over deliberately. Without it a scan pointed at a bare project ref, with no application to look up, would query a public archive for the empty string -- traffic sent to a third party to answer a question nobody asked.
type PreviewStage ¶
PreviewStage sweeps preview and branch deployments of the same application.
Ported from the "// ---- preview deployments ----" section of scanTarget. A clean production bundle today says nothing about a branch build nobody watches: removing a key from main does not revoke it, and a key rotated in production can keep being served by a preview deployment.
func (PreviewStage) Describe ¶
func (PreviewStage) Describe() scan.StageDescriptor
func (PreviewStage) Name ¶
func (PreviewStage) Name() string
type ProbeStage ¶
type ProbeStage struct {
// Client speaks to the target's PostgREST. It is held by the stage rather
// than by scan.State on purpose: a client is the most backend-specific
// thing there is, and putting it in the shared state would make every
// future backend accept a field only Supabase and Neon can populate.
Client *client.Client
// Opts carries the probe budget and behaviour the operator chose.
Opts probe.Options
// Redact removes sampled values while keeping the finding usable.
Redact bool
}
ProbeStage establishes what an anonymous caller can actually do to each discovered relation.
Ported from the "// ---- probing ----" section of scanTarget. The stage owns the probing and the accounting; the operator warnings that used to sit alongside it stay with the command, because telling a human what is about to happen is a property of the interface rather than of the scan.
func (ProbeStage) Describe ¶
func (ProbeStage) Describe() scan.StageDescriptor
func (ProbeStage) Name ¶
func (p ProbeStage) Name() string
Name is stable: it appears in the spend breakdown and in the not-assessed finding the pipeline emits if this stage fails.
type RealtimeOutcome ¶
type RealtimeOutcome struct {
Default realtime.Result
// PerSchema is a slice, not a map: two scans of an unchanged project must
// produce identical bytes, and map iteration is not ordered.
PerSchema []SchemaRealtime
}
RealtimeOutcome is what the stage established, for the command to report.
type RealtimeStage ¶
type RealtimeStage struct {
Client *client.Client
AnonKey string
// Write and NoResidue gate the delivery probe. See wouldTrigger.
Write bool
NoResidue bool
// Timeout is the operator's -timeout. realtime.Options declares it and
// internal/realtime reads it, but no caller ever set one, so every
// subscription used the package's own 20s default no matter what was
// asked for -- a control present in the API and absent from the
// behaviour.
Timeout time.Duration
}
RealtimeStage establishes whether anonymous listeners receive future changes.
Ported from the "// ---- realtime ----" section of scanTarget. REST answers "can anon read this now"; Realtime answers "does anon receive every future change". A relation can look quiet to one and stream to the other.
func (RealtimeStage) Describe ¶
func (r RealtimeStage) Describe() scan.StageDescriptor
func (RealtimeStage) Name ¶
func (RealtimeStage) Name() string
type SchemaEscalation ¶
SchemaEscalation pairs a schema with what the elevated role read in it.
type SchemaRealtime ¶
SchemaRealtime pairs a schema with what Realtime did there.
type SchemaScan ¶
type SchemaScan struct {
// Name is the schema, used to qualify findings so a fix names the right
// relation: without it a remediation says CREATE POLICY ... ON invoices
// for a table in another schema, which resolves against search_path and
// either errors or targets something else entirely.
Name string
// Relations are the names enumerated in that schema.
Relations []string
// Result is what probing established there. Realtime steers on which
// relations are writable and readable; escalation needs the whole thing.
Result probe.Result
}
SchemaScan is what one non-default exposed schema's pass produced.
PostgREST exposes more than the default schema when configured to, and a subscriber or reader asks for one by name. Each extra schema therefore gets its own enumeration and its own probe, and several later stages -- realtime delivery, the escalation compare, the scan summary -- consume the result.
This type used to be declared INSIDE scanTarget. That is not incidental to the size of that function: a type scoped to a function scopes every consumer of it to the same function, so realtime and escalation could not leave main while the thing they iterate over could not be named from outside. Moving it here is a prerequisite for porting them, and it is counted as part of that work rather than as separate tidying.
type Schemas ¶
type Schemas struct {
Scans []SchemaScan
Discovered schemas.Result
}
Schemas is what the schemas stage publishes.
The two halves travel together because they are one fact: which schemas PostgREST exposes beyond the default, and what was found in each. As separate out-params a caller could hold the scan list without the discovery that explains it, and the log line that names the extra schemas would then disagree with the scans that follow it.
type SchemasStage ¶
type SchemasStage struct {
Client *client.Client
Concurrency int
Write bool
NoResidue bool
Measure bool
Invoke bool
Redact bool
SampleRows int
MaxColumnProbes int
// ExtraRoutines caps how much routine discovery the non-default schemas
// may do; RPCRoutines is the whole scan's routine allowance, which a LATER
// stage also draws on. Spending charges both, which is why they are
// budgets rather than ints: the auth/storage/rpc pass that runs after this
// one must see what was already spent.
//
// Nil means uncapped, so a caller that has not adopted budgets is not
// silently reduced to zero work.
ExtraRoutines *scan.Budget
RPCRoutines *scan.Budget
}
SchemasStage examines every schema PostgREST exposes beyond the default one.
Ported from the "// ---- other exposed schemas ----" section of scanTarget. Every scan before that section existed probed the default schema and stopped, which is the same false-negative shape as trusting the OpenAPI root: relations in another exposed schema are never asked about, and silence reads as safety. PostgREST names them when asked for a schema that cannot exist, so this costs one request on projects that expose nothing extra.
func (SchemasStage) Describe ¶
func (s SchemasStage) Describe() scan.StageDescriptor
func (SchemasStage) Name ¶
func (SchemasStage) Name() string
type SeedOrigins ¶
type SeedOrigins = finding.SeedOrigins
SeedOrigins is finding.SeedOrigins, aliased so this package can name it without the reporting layer having to import a backend.
type SeedSources ¶
type SeedSources struct {
// Pinned ships with the binary and is the same on every scan, so it says
// nothing about this target.
Pinned []string
// Harvested comes from the application's own pages and bundles, and is the
// reason a scan with a site beats one without.
Harvested []string
// Advertised is what the OpenAPI document names. Not trusted and not
// relied on -- on the managed product it is service_role-only and answers
// 401 -- but where a self-hosted deployment serves it, it names the schema
// outright.
Advertised []string
// Supplied came from outside this process: an operator who knows the
// schema, or an agent that read a document this scanner cannot parse.
Supplied []string
}
SeedSources are the candidate names, kept apart by where they came from.
They are merged, never chosen between. Measured on a second project: the pinned list alone reached 2 of 7 relations while the hint oracle would have answered for all 7, so preferring one source loses recall another already had.
type SelfCheckStage ¶
SelfCheckStage verifies the scan's own oracles before anything trusts what they did NOT find.
Ported from the "// ---- self-check ----" section of scanTarget. A scan that cannot see must say so: "no findings" from a blind scan is the exact lie every surveyed tool tells, and this is the check that makes it impossible here. It runs after enumeration so it can judge on what the scan actually observed rather than on a synthetic guess.
func (SelfCheckStage) Describe ¶
func (SelfCheckStage) Describe() scan.StageDescriptor
func (SelfCheckStage) Name ¶
func (SelfCheckStage) Name() string
type SubdomainStage ¶
SubdomainStage names other hosts under the same registrable domain.
Ported from the "// ---- other deployments of the same application ----" section. It REPORTS rather than scans, and that is deliberate: a subdomain of a domain the operator nominated is not automatically theirs -- status pages and documentation portals commonly point at somebody else's infrastructure -- and this tool scans what it was pointed at. Opts is taken whole, as PreviewStage, HistoryStage and RoutesStage take theirs. This stage used to restate the three fields it cared about -- Domain, Labels, Concurrency -- and the port dropped Timeout on the way through, so -timeout stopped binding subdomain enumeration and every lookup silently used the package's own 5s default instead. A stage that restates its options can forget one; a stage that forwards them cannot.
func (SubdomainStage) Describe ¶
func (SubdomainStage) Describe() scan.StageDescriptor
func (SubdomainStage) Name ¶
func (SubdomainStage) Name() string
type SurfaceStage ¶
type SurfaceStage struct {
Client *client.Client
Opts surface.Options
// RoutineCap is the allowance the routine sweep was given, carried
// separately because the truncation finding reports what the cap WAS
// rather than what remained.
RoutineCap int
// RPCRoutines is the LIVE routine allowance, shared with the schemas
// stage. Carried as the budget rather than as an int because the schemas
// pass spends from it first: an int captured at construction time would be
// the allowance as it stood before that pass ran, so this stage would
// either over-spend the operator's -max-rpc or under-use it, depending on
// when the caller happened to read it.
//
// This is also what let the stage list stop depending on scan order.
RPCRoutines *scan.Budget
}
SurfaceStage examines auth, storage, routines and Edge Functions.
Ported from the "// ---- auth / storage / rpc ----" section of scanTarget. These are project-wide rather than per-schema, which is why they run once and are deliberately not repeated for every exposed schema: doing so would re-issue the same requests and report the same findings several times.
func (SurfaceStage) Describe ¶
func (s SurfaceStage) Describe() scan.StageDescriptor
func (SurfaceStage) Name ¶
func (SurfaceStage) Name() string
type Vocabulary ¶
type Vocabulary struct {
// Seeds is the merged candidate list, in MergeSeeds' order. The order is
// load-bearing: it fixes probe order and therefore report order, and two
// scans of an unchanged target have to produce identical bytes.
Seeds []string
// Origins is what each source contributed AFTER the merge, so the four
// parts sum to exactly len(Seeds). The stage that merges is the only
// thing that can know this.
Origins SeedOrigins
// RoutineSeeds are the candidates for routine discovery: harvested
// vocabulary merged with the pinned routine list.
RoutineSeeds []string
// Composed are compound routine candidates built from harvested
// vocabulary. A routine named admin_read_audit_log is invisible to a seed
// list of single tokens, because PostgREST's hint matches on similarity
// and a compound is not similar enough to either of its parts.
//
// Both live here rather than being computed at a call site because they
// are derived from the SAME harvested vocabulary this stage already owns.
// Computing them in the command meant the schemas and surface stages could
// only be constructed by a caller holding the harvest -- which is the one
// thing that stopped the stage list being a pure function of the flags.
Composed []string
}
Vocabulary is what the vocabulary stage publishes: the candidate names every later stage probes, and where they came from.
A typed artifact rather than two out-params. `Out: &seeds, Origins: &seedOrigins` put two variables in scanTarget's scope for a fact entirely internal to the Supabase scan, which is what made this stage impossible to reorder or replace without editing the command.
type VocabularyStage ¶
type VocabularyStage struct {
Sources SeedSources
// MaxRPC bounds compound routine candidates, honouring the same budget the
// rest of routine discovery does.
MaxRPC int
// Site and HarvestSources describe where the vocabulary came from, so this
// stage can report a SHORTFALL: falling back to the pinned list is a
// CHOICE when no site was supplied and a LOSS when one was and could not
// be read. Those two need different words and only one of them is a
// warning, and the command used to decide which -- from counts it was
// holding purely to make that call.
Site string
HarvestSources int
}
VocabularyStage produces the candidate names every later stage probes.
This is the Enumerate phase of the provider contract: it does not assess anything, it decides what will be asked about. Its output is exactly what scan.Inputs.Seeds carries to the other backends.
func (VocabularyStage) Describe ¶
func (VocabularyStage) Describe() scan.StageDescriptor
func (VocabularyStage) Name ¶
func (VocabularyStage) Name() string