Documentation
¶
Overview ¶
Package surface covers the Supabase services that sit beside PostgREST: GoTrue auth configuration, storage buckets, and RPC routines.
Two things here are worth calling out.
RPC enumeration reuses the hint oracle. PostgREST volunteers routine names the same way it volunteers relation names, and on the reference target this recovered all three token-gated SECURITY DEFINER admin routines with no prior knowledge. Those routines are precisely the ones an operator assumes are private, because they are not referenced from any client bundle.
Auth configuration matters because `anon` is not the only role an attacker can hold. When signup is open, anyone can obtain an `authenticated` JWT, and RLS policies written `TO authenticated` are frequently far more permissive than the anon ones. Testing only the anon role understates exposure. Actually creating an account is a mutation, so it is gated behind the same ownership confirmation as write probing.
Index ¶
Constants ¶
const ControlBucketName = "unruly_control_bucket_that_cannot_exist"
ControlBucketName is a bucket that cannot exist. If the target claims it does, no answer about any bucket means anything.
Underscore style deliberately: the hyphenated form reads like a finding id, and the coverage audit that walks the tree for id literals picks it up as a check that has never fired. That exact mistake was made with the Edge Function control probe and fixed by renaming; making it again two surfaces later is the argument for the audit catching it rather than for trusting anyone to remember.
const ControlFunctionName = "unruly_control_function_that_cannot_exist"
ControlFunctionName is the Edge Function name the control probe asks for. It cannot be deployed on any real project, and is fixed rather than random so runs stay comparable.
const ControlRoutineName = "unruly_control_routine_that_cannot_exist"
ControlRoutineName is the routine name the direct-hit control probe asks for. Nothing may define it; a host that answers it as though it exists is a host whose answers do not distinguish routines.
Variables ¶
This section is empty.
Functions ¶
func AnonymousSignInFinding ¶
AnonymousSignInFinding reports anonymous sign-ins being enabled.
func RoutineBudgetFinding ¶
RoutineBudgetFinding reports that routine discovery stopped at its probe budget rather than at the end of the candidate list.
-max-rpc-probes has existed since early on and truncated in silence. When -max-relation-probes was added it got a lower-bound note immediately, because adding a cap without one manufactures a false negative on request — and nobody went back to the older cap. An audit did.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Reachable bool
DisableSignup bool `json:"disable_signup"`
MailerAutoconfim bool `json:"mailer_autoconfirm"`
PhoneAutoconfirm bool `json:"phone_autoconfirm"`
SAMLEnabled bool `json:"saml_enabled"`
External map[string]bool `json:"external"`
}
AuthConfig is the subset of GoTrue settings that affects exposure.
func (AuthConfig) SignupOpen ¶
func (a AuthConfig) SignupOpen() bool
SignupOpen reports whether an attacker can mint an authenticated identity.
type Bucket ¶
type Bucket struct {
Name string `json:"name"`
ID string `json:"id"`
Public bool `json:"public"`
// Objects are the first few files the bucket serves, when they could be
// listed. Evidence rather than assertion.
Objects []string `json:"-"`
}
Bucket is a storage bucket visible to the scanning role.
type EdgeFunction ¶
type EdgeFunction struct {
Name string
// Status is the response to an anonymous invocation.
Status int
// RequiresJWT is true when the platform rejected the call before the
// function ran, i.e. verify_jwt is on.
RequiresJWT bool
// Snippet is a short excerpt of the response body.
Snippet string
// contains filtered or unexported fields
}
EdgeFunction is a deployed Deno function and how it treats anonymous callers.
func (EdgeFunction) Invokable ¶
func (f EdgeFunction) Invokable() bool
Invokable reports whether an anonymous caller actually reached the function.
type Options ¶
type Options struct {
// Redact suppresses response bodies captured from the target. An Edge
// Function's response is arbitrary application output -- a user record, a
// token, whatever the function returns -- and this package's own finding
// text notes that functions commonly hold the service_role key. It was
// being emitted verbatim under -redact, the same leak the application
// route probe had.
Redact bool
// BucketSeeds are candidate storage bucket names. Buckets cannot be
// enumerated by the anonymous role, so they are reached by name or not at
// all.
BucketSeeds []string
// RoutineGuesses are candidate routine names probed VERBATIM rather than
// trimmed into stems.
//
// The stem strategy assumes a seed is a real name that must be trimmed to
// become a near miss. A COMPOSED guess is already an approximation, and
// trimming it pushes it past the similarity threshold instead of onto it.
// Measured against a routine named admin_read_audit_log:
//
// admin_audit_log (whole) HINT
// admin_audit_lo (n-1) no hint
// admin_audit (3n/4) no hint
//
// So composing better seeds achieved nothing until they stopped being
// trimmed. Two different jobs that both looked like "candidate names".
RoutineGuesses []string
// RoutineSeeds are candidate names for the RPC hint oracle. Reusing the
// harvested application vocabulary keeps this deterministic and generic.
RoutineSeeds []string
Concurrency int
// MaxCandidates bounds RPC probing. Sorted before truncation, so the cap
// is deterministic.
MaxCandidates int
// FunctionSeeds are candidate Edge Function names.
FunctionSeeds []string
// AllowFunctions permits probing Edge Functions.
//
// The discriminator requires a POST: the platform answers 404 for absent,
// 401 when verify_jwt rejects the caller, and anything else means the
// request reached the function — which is to say the function RAN. A
// deployed function with verify_jwt off is invoked by the act of detecting
// it, and Edge Functions send email, charge cards and write to queues.
//
// Off by default, for the same reason routes are not POSTed to and
// routines are not called. The cost is total for this check: without it no
// Edge Function is detected at all, which the scan states rather than
// leaving as an apparently clean result.
AllowFunctions bool
// AllowWrite permits writes to discovered surfaces: currently an object
// uploaded to a public bucket and deleted again. Small, but a write.
AllowWrite bool
// NoResidue withdraws permission for any probe that could leave something
// behind on the target, which for this package means the bucket upload.
//
// The upload deletes itself afterwards and reports honestly when it
// cannot. That is not what the flag asks for: a bucket granting INSERT
// but not DELETE keeps the file, which is the storage version of exactly
// the table case -no-residue was built for. This field did not exist
// until an audit swept every mutating request in the tree and found that
// NoResidue reached one package out of three that write.
NoResidue bool
// Schema qualifies routine names in findings and in the SQL they carry.
// The templates said public.%s literally, so a routine in another exposed
// schema got remediation naming the WRONG schema explicitly -- which does
// not fail safe: it either errors or revokes on some other function.
Schema string
// AllowInvoke permits CALLING discovered routines to learn whether the
// anonymous role may execute them.
//
// There is no way to ask "may I call this" without calling it. PostgREST
// checks EXECUTE when the statement runs, so the probe invokes the routine
// and reads what comes back — and a routine that is callable RUNS. Verified
// on a fixture: POSTing {} to a zero-argument function executed its body,
// which is exactly what an admin routine named purge, reset or delete does
// for a living, and SECURITY DEFINER ones run with the owner's rights.
//
// Off by default. Without it, disclosure is still reported and callability
// is reported as unknown, which is true.
AllowInvoke bool
}
Options configures surface scanning.
type Result ¶
type Result struct {
Auth AuthConfig
Buckets []Bucket
Routines []string
// Callable records, per disclosed routine, whether the anonymous role may
// actually execute it. PostgREST names routines in its hint regardless of
// EXECUTE privilege, so the two must be measured separately.
//
// Absent from the map means INDETERMINATE, not false: see callableRoutines.
Callable map[string]bool
// RoutineBudgetBound is true when -max-rpc-probes truncated the candidate
// list, so the routines reported are a lower bound.
RoutineBudgetBound bool
// RoutineCandidatesWanted is how many candidates would have been probed
// without the cap.
RoutineCandidatesWanted int
// StorageReachable distinguishes "no public buckets" from "could not ask".
StorageReachable bool
Functions []EdgeFunction
// FunctionsUnresolved counts function names whose probe got no usable
// answer, so the function list is a lower bound.
FunctionsUnresolved int
Findings []finding.Finding
Requests int
// RequestsBy attributes those requests to the sub-stage that made them.
//
// "surface" was one ledger entry covering routine discovery, bucket
// probing, Edge Functions and auth, and it was the largest spender on a
// real target: 4,406 of 12,068 requests, buying four routine disclosures.
// A ledger exists so an operator can see where their traffic went, and the
// biggest line in it said only "surface". Reasoning from an opaque bucket
// has already cost this project one wrong investigation, when a mislabelled
// stage sent it looking at storage for a spend that was elsewhere.
RequestsBy map[string]int
}
Result aggregates the non-PostgREST surfaces.
func Routines ¶
Routines runs ONLY the RPC surface, for a client addressing a schema other than the default.
Auth, storage and Edge Functions are project-wide: they are not per-schema and re-running them once per schema would issue the same requests again and report the same findings several times. Routines are per-schema, and the hint oracle works there -- measured against a routine in a non-default schema:
GET /rest/v1/rpc/admin_rebuild_metric Accept-Profile: reporting -> "Perhaps you meant to call the function reporting.admin_rebuild_metrics"
Without this, a SECURITY DEFINER routine in an exposed reporting schema -- callable by anon, reading a table anon cannot read -- is invisible to the scan, which is the shape of finding this tool exists for.