probe

package
v0.1.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package probe classifies read and write exposure for a relation and builds proof-carrying findings.

Write probing is the part everyone gets wrong, in both directions.

Unsound: a zero-match DELETE or PATCH (?id=eq.-1). RLS does not raise on writes; it silently filters candidate rows to zero. A protected relation and a wide-open one both answer 204, so the probe cannot discriminate and flags every relation as writable. Measured against the reference target this produced 16 false positives out of 21.

Sound: an INSERT. RLS evaluates WITH CHECK before the schema sees the row, so the two outcomes are distinguishable:

42501                     -> the security layer rejected it (protected)
23502/23505/23503/22P02   -> it passed RLS and the SCHEMA rejected it

Reaching the schema is the proof: RLS would have stopped it earlier. PGRST204 is deliberately NOT in that list: PostgREST raises it from its own schema cache before any SQL runs, so it is returned identically for protected and open relations and proves nothing.

Safety: an empty INSERT normally cannot land a row, because any NOT NULL column rejects it. On a relation where every column is nullable or defaulted it CAN succeed, so the probe requests the inserted representation and deletes what it created, reporting honestly when cleanup fails. Write probing is opt-in regardless.

Index

Constants

View Source
const ControlRelationName = "unruly_control_relation_that_cannot_exist"

Run probes every relation. Results are returned in sorted name order. ControlRelationName is the name probed to decide whether this target's answers carry information. It cannot exist, and it is the same name the enumerator uses -- a second name would be a second thing to keep absent.

View Source
const DefaultMaxColumnProbes = 2000

DefaultMaxColumnProbes bounds sensitive-column probing per scan.

2,000 is roughly 60 exposed relations at 33 candidates each, which covers every project seen in a 100-site sample -- the largest had 80 exposed relations, and the bound then truncates rather than silently issuing 2,640 requests to one target.

Variables

This section is empty.

Functions

func ColumnBudgetFinding

func ColumnBudgetFinding(restBase string, used, limit, unprobed int) finding.Finding

ColumnBudgetFinding reports that sensitive-column probing was truncated.

Severity in a measurement scan depends on knowing column names, so a relation the budget could not reach is reported at the severity of a table whose contents are unknown -- which is lower than it may deserve. Every other budget here says so when it binds; this one does too.

func ContentColumns

func ContentColumns(cols []string) []string

ContentColumns returns the columns that name presentation rather than people.

func SchemaNames

func SchemaNames(ctx context.Context, c *client.Client) []string

SchemaNames returns the relation names a PostgREST OpenAPI document advertises, or nothing when the document is not served.

This tool does not RELY on the OpenAPI root, for a measured reason: on the managed product it is service_role-only and answers 401, which is why every scanner built around it reports a database with 21 relations as having none. That is an argument against depending on it, and it was quietly taken as an argument against ever asking.

It is one request, and it is already being made: looksLikePostgREST fetches exactly this document to decide whether a candidate mount is PostgREST, and then discards the paths. Measured on the corpus project that models an API gateway in front of Supabase -- error codes rewritten, hints destroyed, the mount moved to /api/db/v2/ -- the document passes through untouched because it is a 200, and it names the three readable relations the scan otherwise finds none of.

The names are SEEDS, not findings. Every one is probed like any other candidate, so a document that lies costs a request and changes no verdict. That is the same contract the vocabulary handoff works under.

func SensitiveColumns

func SensitiveColumns(cols []string) []string

sensitivePatterns are deterministic name-based rules. Name matching is used rather than value inspection so the classifier behaves identically whether or not a given row happens to contain data. SensitiveColumns is retained as the name this package's callers know, and forwards to internal/classify.

The patterns moved because two providers were answering the same question differently. Supabase rated a relation critical for a column called password; Firebase rated every readable Firestore collection high whatever it was called, because the classifier lived in this Supabase-shaped package and the provider could not reach it without importing probing machinery it has no use for. "What kind of data is this" belongs to the shared core, next to the value classifier that answers the same question from the other side.

func Trigger

func Trigger(ctx context.Context, c *client.Client, name string) bool

Trigger causes exactly one row-level change on a relation, for the Realtime delivery probe, and reports whether the write actually landed.

It reuses the INSERT probe rather than issuing a bespoke write, which keeps one promise in one place: the probe cleans up any row it creates, and the two-phase logic that stops a RETURNING artifact from being read as an RLS denial applies here too. Callers must gate this on -write; nothing in this function checks consent, because consent is not a property of a relation.

Types

type Options

type Options struct {
	// Write enables the INSERT discriminator. Off by default: it issues a
	// mutating request, and must be gated on target ownership.
	Write bool
	// SampleRows is how many real rows to quote as evidence.
	SampleRows int
	// Concurrency bounds in-flight probes.
	Concurrency int
	// Redact suppresses sampled values in evidence. The rows are still
	// RETRIEVED; only the report is stripped. For consent reasons that is a
	// different thing from Measure.
	Redact bool
	// Measure establishes exposure without transferring any data.
	//
	// The read probe asks for limit=0 with an exact count, so PostgREST answers
	//
	//	206  Content-Range: */465   body: []
	//
	// "465 rows are readable by anyone", in two bytes, with not one row leaving
	// the database. Redact cannot do this: it fetches the rows and then hides
	// them, so the data has already crossed the network and sits in the
	// scanner's memory.
	//
	// The cost is honest and worth stating: with no rows there are no column
	// names, so the sensitivity heuristics that raise a finding to critical
	// when a column is called access_token or password cannot run. Measure
	// answers "is it readable, and how much", not "how bad is it".
	//
	// This exists for studying populations of third-party projects, where
	// retrieving strangers' personal data to prove a point is not defensible
	// however good the point is.
	Measure bool
	// MaxColumnProbes bounds the total sensitive-column probes a measurement
	// scan issues, across all relations. Zero means the default.
	//
	// Every other budget in this scanner is bounded and says so when it binds;
	// this one was added without either, and 33 candidates per exposed
	// relation is 16,500 requests against a project with 500 of them. A
	// bounded scan that discloses the bound is the pattern here, not an
	// unbounded one that is polite in practice.
	MaxColumnProbes int
	// Schema addresses a PostgREST schema other than the default, so findings
	// and their remediation name the relation the way SQL must refer to it.
	Schema string
	// NoResidue restricts write probing to INSERTs that should be rejected
	// before a row is created.
	//
	// It forbids phase B's bare INSERT, which on a relation that accepts
	// anonymous INSERT, refuses anonymous SELECT and has no NOT NULL column
	// succeeds with 201, no Location header and an empty body — leaving a row
	// whose key is unreadable and which no anon-key holder can delete.
	//
	// It also constrains phase A, which it did NOT do until an audit ran the
	// flag against the exploit lab and watched it leave exactly the rows it
	// promises not to: gating only phase B is no protection when phase A has
	// already committed one. Phase A now sends a row the read stage sampled, so
	// the primary key collides and nothing is created, and declines to probe at
	// all when no such row exists.
	//
	// The cost is write recall on relations this scan cannot read, which are
	// reported as inconclusive rather than as clean.
	NoResidue bool
}

Options configures probing.

type PrefixVerdict

type PrefixVerdict int

PrefixVerdict is what the two probes established.

const (
	// PrefixOK: PostgREST did not object to the configured prefix, so the scan
	// proceeds unchanged. This is every managed project -- the root there
	// answers 401, not PGRST125.
	PrefixOK PrefixVerdict = iota
	// PrefixMoved: PostgREST is somewhere else and the scan found it.
	PrefixMoved
	// PrefixWrongAndUnresolved: PostgREST said the prefix is wrong and no
	// candidate corroborated. Continuing means sending the whole plan to a
	// path the server has already rejected -- measured at 18,756 requests, all
	// of them answered PGRST125, producing a report that says 0 relations.
	//
	// This case is not hypothetical: it is what a wrong prefix looks like when
	// the credential is ALSO not accepted, because then the candidate root
	// answers 401 and cannot corroborate. Both faults are real and the operator
	// needs to hear about the one that is decidable.
	PrefixWrongAndUnresolved
)

func ResolveRestPrefix

func ResolveRestPrefix(ctx context.Context, c *client.Client) (*client.Client, string, PrefixVerdict)

ResolveRestPrefix returns a client addressing PostgREST where it actually is, the prefix it settled on, and what it established. The input client is returned unchanged unless the target says, in PostgREST's own words, that the prefix is wrong.

type Relation

type Relation struct {
	Name string
	// ColumnsUnprobed marks a relation the column budget could not reach, so
	// its severity is a lower bound rather than a verdict.
	ColumnsUnprobed bool

	// Schema is the PostgREST schema this relation lives in. Empty means the
	// default one, and nothing is qualified.
	//
	// It exists because remediation SQL was being emitted UNQUALIFIED for
	// relations outside the default schema:
	//
	//	ALTER TABLE daily_revenue ENABLE ROW LEVEL SECURITY;
	//
	// pasted into a SQL editor that resolves against public via search_path.
	// That either errors or -- worse -- alters a different table of the same
	// name while the real exposure stays open and the operator believes it is
	// fixed. A fix that silently targets the wrong object is worse than no fix.
	Schema string
	Read   postgrest.ReadState
	// ReadStatus is the HTTP status the read actually returned.
	//
	// The classified ReadState is what the scanner reasons with; the status is
	// what the operator's own replay of the published command will show. A
	// finding that prints a command and not the answer it got cannot be checked
	// against anything -- replaying proves the command runs, and running is not
	// reproducing. measured: 51 findings published a command and one
	// stated a status, so a deliberately mangled URL replayed to 404 and the
	// replay check passed it.
	ReadStatus int
	// WriteStatus is what the insert probe was answered with.
	WriteStatus int
	// UpdateStatus is what the PATCH probe was answered with.
	UpdateStatus int
	Rows         int
	Columns      []string
	Sample       []map[string]any
	Write        postgrest.WriteState
	// Update and Delete are the other two write verbs, kept separate from Write
	// because they are separate permissions. A relation that accepts INSERT
	// frequently also accepts UPDATE and DELETE, but "frequently" is a guess and
	// this scanner reports what it measured.
	Update    postgrest.WriteState
	UpdateWhy string
	Delete    postgrest.WriteState
	DeleteWhy string
	WriteWhy  string
	Sensitive []string
	// SensitiveValues names the KINDS of data found in the sampled rows, as
	// opposed to in the column names.
	//
	// The two are different instruments pointed at the same question. Column
	// names are English, so a schema written in any other language -- or one
	// using notes, payload, data -- yields nothing from them however plainly
	// the rows contain card numbers. Values carry no language.
	//
	// Empty under -measure by construction: that mode retrieves no rows, so
	// there is nothing to look at, and the finding says so rather than
	// implying the rows were clean.
	SensitiveValues []string
	CleanupErr      string
	// contains filtered or unexported fields
}

Relation is the fully classified state of one relation.

func (Relation) Qualified

func (r Relation) Qualified() string

type Result

type Result struct {
	// Discriminating is false when the target answered a relation that cannot
	// exist exactly as it answered the ones that can. Nothing below it was
	// measured in that case, and reporting the empty list as a clean project
	// is the failure this guards.
	Discriminating bool
	// ControlDetail says why, in the words a report can print.
	ControlDetail string

	// ColumnsUnprobedCount is how many exposed relations the column budget
	// could not reach. The count, not just the fact: a budget that stopped one
	// relation short and one that stopped forty short are different reports.
	ColumnsUnprobedCount int
	// ColumnBudgetBound is true when at least one exposed relation went
	// unprobed for sensitive columns, so severity is understated.
	ColumnBudgetBound bool
	// ColumnProbesUsed counts the sensitive-column probes actually issued.
	ColumnProbesUsed int
	Relations        []Relation
	Requests         int
}

Result aggregates probing.

func Run

func Run(ctx context.Context, c *client.Client, names []string, o Options) Result

func (Result) Findings

func (r Result) Findings(baseURL string, redact bool) []finding.Finding

Findings converts probe results into deterministic, proof-carrying findings.

It takes a base URL rather than a Client so finding generation is a pure function of observed state, independent of the network layer.

func (Result) InsertReachable

func (r Result) InsertReachable() []string

InsertReachable returns relations that accept anonymous writes.

func (Result) ReadExposed

func (r Result) ReadExposed() []string

ReadExposed returns relations that leak rows anonymously.

func (Result) Rows

func (r Result) Rows() map[string]int

Rows maps relation name to anon-visible row count.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL