Documentation
¶
Overview ¶
Package eval defines ground-truth targets and scores a scan against them.
Evals come before the scanner on purpose. Every tool surveyed during the research that motivated unruly fails in the same direction: it reports "no findings" against a database that is in fact world-writable, and nothing in its own test suite catches that. Recall against a known answer is the only thing that does.
A Target is a declaration of what is true about a Supabase project. The runner scans it and scores the result, so every change to the scanner is measured rather than eyeballed.
Index ¶
- Constants
- func Reachable(ctx context.Context, c *client.Client, relation string) error
- type Expectation
- type Observation
- type Relation
- type Result
- type Score
- type Target
- func (t *Target) AnonKey() (string, error)
- func (t Target) BackendOrDefault() string
- func (t *Target) ClaimsClasses() bool
- func (t *Target) EscalationGains() []string
- func (t *Target) ExpectedClasses() []string
- func (t *Target) InsertReachable() []string
- func (t *Target) Protected() []string
- func (t *Target) ReadExposed() []string
- func (t *Target) RelationNames() []string
- func (t *Target) Routines() []string
- func (t *Target) Validate() error
Constants ¶
const ReachabilityProbe = "unruly_fixture_reachability_probe"
ReachabilityProbe is the relation name used to test that a fixture answers. Nothing may define it, so a 404 is the expected success case.
Variables ¶
This section is empty.
Functions ¶
func Reachable ¶
Reachable reports whether a fixture is actually serving, distinguishing a target that answered from one that could not be dialled.
The evals grade recall and precision against fixtures in Docker. When the daemon dies mid-run -- which on this machine it has done eleven times -- every request fails at the transport, every relation classifies as unknown, and the graders report what looks like a substantive regression:
probed 9 relations in 3ms (18 requests) relation-discovery FAIL recall 0.0% read-exposure-classifier is UNSOUND
Each of those took real time to diagnose, and each said nothing about the scanner. It is the exact confusion this project exists to prevent -- a measurement that could not be taken presenting as a measurement that came back bad -- reproduced inside the harness that is supposed to enforce it.
The distinction is the transport, not the status. A 404 or a 401 proves the fixture is up and talking; a dial error proves nothing about anything. The relation therefore need not exist -- only the dial matters.
Types ¶
type Expectation ¶
type Expectation struct {
// Relations the scanner must discover. This is the recall denominator.
Relations []Relation `yaml:"relations"`
// DiscoverableRef asserts the project ref is recoverable blackbox from
// Site alone, and names the channel it leaks through.
DiscoverableRef string `yaml:"discoverable_ref,omitempty"`
// KeyInBundles asserts whether a credential is currently retrievable from
// the site's shipped JavaScript.
KeyInBundles bool `yaml:"key_in_bundles"`
// OpenRoutes are application endpoints that answer without authentication
// but should not.
OpenRoutes []string `yaml:"open_routes,omitempty"`
// Routines the scanner must discover via the function hint oracle.
Routines []string `yaml:"routines,omitempty"`
// EscalationGains are relations readable by an elevated role but not anon.
EscalationGains []string `yaml:"escalation_gains,omitempty"`
}
Expectation is the known-correct answer for a target.
type Observation ¶
type Observation struct {
Relations []string
ReadExposed []string
InsertReachable []string
Rows map[string]int
Routines []string
EscalationGains []string
// Classes are the relation:class pairs the scan reported.
//
// Nil means the observation makes no statement -- a probe-only run, or a
// backend whose findings carry no classes -- and the dimension is skipped.
Classes []string
}
Observation is what a scan actually found, in the shape the scorer needs. The scanner produces this; the scorer never imports the scanner, so evals stay usable for grading third-party tools too.
NIL AND EMPTY MEAN DIFFERENT THINGS on the optional dimensions. A nil slice says "this stage did not run"; an empty non-nil slice says "it ran and found nothing". Conflating them is the same mistake this tool exists to correct, and it had leaked into the tool's own eval output: a probe-only test scored routine-discovery at 0% recall and printed "target lab-fixture: FAIL" while passing, because the target declares routines and the observation left them nil. Reports that print FAIL next to a passing result teach people to stop reading FAIL.
type Relation ¶
type Relation struct {
Name string `yaml:"name"`
// Rows is the exact anon-visible row count. Zero means RLS filters all
// rows (the relation exists but leaks nothing).
Rows int `yaml:"rows"`
// ReadExposed is true when anonymous SELECT returns real rows.
ReadExposed bool `yaml:"read_exposed"`
// InsertReachable is true when an anonymous INSERT passes RLS and is
// rejected by the schema rather than the security layer.
InsertReachable bool `yaml:"insert_reachable"`
// SensitiveColumns are columns that must trip the secret/PII classifier.
SensitiveColumns []string `yaml:"sensitive_columns,omitempty"`
// Classes are the KINDS of sensitive data the report must name for this
// relation -- credential, financial, government-id, health, pii, contact,
// location.
//
// Distinct from SensitiveColumns, which names the columns that carry them.
// A relation can have classes and NO sensitive columns: that is the whole
// point of the German-named table in corpus project 16, where no column
// name matches an English rule and only the sampled VALUES carry the
// answer.
//
// NIL AND EMPTY MEAN DIFFERENT THINGS, as everywhere else here. Nil says
// the key makes no claim and the target is not scored on classification.
// Empty says the correct answer is that NO class is reported -- the
// lookalike tables, whose columns end in address and token and name and
// hold none of those things.
Classes []string `yaml:"classes,omitempty"`
}
Relation is the expected state of one database relation.
type Result ¶
type Result struct {
Target string
Scores []Score
// RowCountErrors records relations where the scanner reported the wrong
// number of rows. Getting the count wrong means the evidence is wrong,
// even when the boolean verdict is right.
RowCountErrors []string
}
Result aggregates every dimension for one target.
func Grade ¶
func Grade(t *Target, o Observation) Result
Grade scores an observation against a target.
type Score ¶
type Score struct {
Dimension string
TruePos []string
FalsePos []string
FalseNeg []string
// Sampled marks a dimension whose answer key lists a SAMPLE of the target
// rather than all of it. Recall still means something -- everything named
// must be found -- and precision does not, because a name the key omits
// may be a correct find rather than an invention. Reported so a reader
// never sees a precision figure that could not have been computed.
Sampled bool
// Unstable carries the key's own reason when WHICH items answer changes
// between identical runs. A number computed over a fixed list there is a
// measurement of the target's rate limiter, and quoting it would be worse
// than reporting nothing.
Unstable string
}
Score is precision/recall for one dimension of a scan.
Both halves matter and they fail in opposite directions. Recall catches the bug that breaks every surveyed tool: silently reporting a vulnerable database as clean. Precision catches the opposite temptation — flagging every relation so recall looks perfect — which produces a scanner nobody trusts. A dimension only passes when both hold.
type Target ¶
type Target struct {
// Backend names the product, defaulting to supabase.
//
// It exists because the anon-key rule in Validate is not universal.
// Supabase's anon key is a JWT, and committing one would publish a
// credential -- so a target must name the environment variable holding it
// and never carry it inline. Firebase has no anon key at all: its web API
// key is documented by Google as public, and the Firestore REST surface is
// reached unauthenticated.
//
// Applying the Supabase rule to every target dropped the corpus's only
// Firebase project from every scoreboard, and RESULTS.md printed the
// validation error as though it were a decision.
Backend string `yaml:"backend,omitempty"`
// Name identifies the target in eval output.
Name string `yaml:"name"`
// ProjectRef is the Supabase project reference.
ProjectRef string `yaml:"project_ref"`
// Site is the public application URL, used for blackbox discovery evals.
Site string `yaml:"site,omitempty"`
// BaseURL overrides the derived cloud origin, for self-hosted or local
// fixture targets.
BaseURL string `yaml:"base_url,omitempty"`
// RestPrefix overrides the PostgREST mount path.
RestPrefix string `yaml:"rest_prefix,omitempty"`
// AnonKeyEnv names the environment variable holding the anon key, so no
// credential is ever committed to the repository.
AnonKeyEnv string `yaml:"anon_key_env"`
// AuthenticatedKeyEnv names the variable holding a token for the
// authenticated role, so the escalation dimension can be graded. The
// corpus keys have carried this since they were written and Target did
// not read it, so every corpus project would have been scored with the
// escalation pass silently switched off.
AuthenticatedKeyEnv string `yaml:"authenticated_key_env,omitempty"`
// Fixture marks a target we provisioned ourselves and may safely mutate.
// Write evals only run against fixtures.
Fixture bool `yaml:"fixture"`
// Notes records provenance and any caveats.
Notes string `yaml:"notes,omitempty"`
Expect Expectation `yaml:"expect"`
}
Target is a ground-truth specification for one project in the corpus.
func LoadTarget ¶
LoadTarget reads a ground-truth spec from disk.
func (*Target) AnonKey ¶
AnonKey resolves the target's credential from the environment.
A backend with no anonymous credential returns the empty string and no error. Firebase is that case: there is nothing to resolve, so demanding a variable produced "env is empty" -- naming no variable, because there was none to name -- and excluded the target one layer below Validate.
func (Target) BackendOrDefault ¶
BackendOrDefault is the declared backend, or supabase when none is given. Every key predates the field and every one of those is Supabase.
func (*Target) ClaimsClasses ¶
ClaimsClasses reports whether this target makes any classification claim.
Fifteen of the sixteen corpus projects make none, and their scans do report sensitive columns. Scoring those against an empty expectation would turn every correct classification into a false positive on a dimension they never claimed to measure.
func (*Target) EscalationGains ¶
EscalationGains returns expected escalation results, sorted.
func (*Target) ExpectedClasses ¶
ExpectedClasses returns the relation:class pairs the report must carry.
Paired rather than flat, so a class found on the WRONG relation counts as a false positive and a false negative instead of cancelling out.
func (*Target) InsertReachable ¶
InsertReachable returns relations that must be reported as anon-writable.
func (*Target) Protected ¶
Protected returns relations that must NOT be reported as exposed. Scoring these guards against the opposite failure: a scanner that cries wolf on every table would score perfect recall and be useless.
func (*Target) ReadExposed ¶
ReadExposed returns relations that must be reported as anonymously readable.
func (*Target) RelationNames ¶
RelationNames returns every expected relation, sorted.