finding

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 finding defines unruly's result model and its output writers.

The wire format deliberately mirrors ProjectDiscovery tooling (nuclei, httpx, subfinder) so results drop into existing pipelines:

[finding-id] [protocol] [severity] <matched-url> [evidence]

Determinism is a hard requirement. Findings carry a content-addressed ID and are emitted in a total order, so two scans of an unchanged target produce byte-identical output and can be diffed in CI.

Index

Constants

View Source
const AgentSchema = "unruly.agent/v1"

AgentSchema is the compact streaming contract. It is versioned separately from the human JSONL Finding shape so either can evolve without silently changing the other.

View Source
const InterruptedResource = "scan:interrupted"

InterruptedResource marks the finding that reports a scan stopping early.

Variables

View Source
var KnownProtocols = map[string]bool{
	"postgrest":             true,
	"gotrue":                true,
	"storage":               true,
	"realtime":              true,
	"functions":             true,
	"graphql":               true,
	"http":                  true,
	"firestore":             true,
	"rtdb":                  true,
	"firebase-auth":         true,
	"firebase-remoteconfig": true,
	"pocketbase":            true,
	"neon":                  true,
	"unruly":                true,
}

KnownProtocols is the closed set of values the protocol field may take. It is documented in the README and consumers group on it, so a typo -- a trailing space, a capital, a new value nobody wrote down -- is a silent break rather than an error. Validated against every finding the fixture scans produce.

Functions

func AttributeBlindnessToInterruption

func AttributeBlindnessToInterruption(fs []Finding)

AttributeBlindnessToInterruption qualifies every could-not-measure verdict in an interrupted scan.

Cancelling the context makes in-flight requests fail, and those failures are indistinguishable from a target that would not answer. The existing findings then describe them as properties of the TARGET, with remediation to match: after a Ctrl-C, a report says the control probe did not complete and advises "-- Point -u at the PostgREST endpoint itself, or pass -rest-prefix". That is an operator sent to debug a configuration problem they do not have.

Saying the scan was interrupted, once, at the top of the report is not enough -- findings are read individually, sorted away from each other, and filtered by id. The attribution has to travel on each one.

These are NOT deleted. On an interrupted scan the two causes genuinely cannot be told apart: the surface may really be unreachable, and dropping the findings would replace an ambiguous answer with a confidently wrong one.

func CSVHeader

func CSVHeader(out io.Writer) error

CSVHeader writes the column names. Called once, before any row.

func CoverageIncomplete

func CoverageIncomplete(fs []Finding) (bool, []string)

CoverageIncomplete reports whether any part of the scan could not be measured, and names what.

This exists because of the exit code. Measured before it did: a correctly hardened project, a host that is not Supabase at all, an origin returning 500, and a completely unreachable address ALL exited 0 — the same code as a clean scan. In CI that makes `unruly ... && echo secure` print secure for a typo in the URL, which is this project's entire thesis inverted and then handed to a machine.

func FixPlan

func FixPlan(fs []Finding) string

FixPlan returns SQL, or "" when nothing in the report has a relational fix.

func Plain

func Plain(fs []Finding) string

Plain builds the whole report. Empty when nothing reachable was found, so a caller can print a clean-result line instead.

func Sort

func Sort(fs []Finding)

Sort orders findings deterministically: most severe first, then by rule ID, resource and matched URL so ties never reorder between runs.

func Table

func Table(fs []Finding, noColor bool) string

Table returns the rendering, or "" when nothing reachable was found.

func WriteCoverage

func WriteCoverage(fs []Finding) string

WriteCoverage describes what the write probes actually established, derived from the findings themselves.

It replaces a fixed sentence that said "write probing covered INSERT only: UPDATE and DELETE were NOT tested" — printed in the same run that emitted nine UPDATE findings and three DELETE findings. The tool contradicted its own report in a single screen of output, and a reader has no way to know which half to believe.

The fix is structural rather than editorial. The sentence used to be a constant asserting a fact about the code, so it went stale the moment the code gained a capability. Counting the report means the summary cannot disagree with the findings it summarises: if a verb appears, it was tested, and if a verb was declined, the same not-assessed findings the reader can see are what says so.

func WriteHTML

func WriteHTML(out io.Writer, target, generated string, fs []Finding) error

WriteHTML renders the whole report. target and generated are passed in rather than discovered so the output is a pure function of its inputs, which is what lets the determinism eval diff two runs.

Types

type AgentEvidence

type AgentEvidence struct {
	Status  int      `json:"status,omitempty"`
	Rows    int      `json:"rows,omitempty"`
	Classes []string `json:"classes,omitempty"`
	Reason  string   `json:"reason,omitempty"`
}

type AgentRecord

type AgentRecord struct {
	Schema      string        `json:"schema"`
	Type        string        `json:"type"`
	Fingerprint string        `json:"fingerprint"`
	ID          string        `json:"id"`
	Severity    Severity      `json:"severity"`
	Protocol    string        `json:"protocol"`
	Target      string        `json:"target"`
	Resource    string        `json:"resource,omitempty"`
	FixKind     FixKind       `json:"fix_kind,omitempty"`
	Observed    AgentEvidence `json:"observed,omitempty"`
	Replay      *AgentReplay  `json:"replay,omitempty"`
}

type AgentReplay

type AgentReplay struct {
	Command   string `json:"command"`
	Performed bool   `json:"performed"`
}

type Evidence

type Evidence struct {
	// Request is the exact HTTP request an auditor can replay, as a curl line.
	Request string `json:"request,omitempty"`
	// Suggested marks a Request the scan did NOT perform.
	//
	// Most requests here are reproductions: the scan made them, and Status is
	// what came back. A few are offers -- the RPC-discovery finding prints a
	// call the scanner deliberately refuses to make, because calling a routine
	// runs somebody's code and that is gated behind -invoke. Such a command
	// cannot state a status, since nothing observed one, and pretending
	// otherwise would put an answer in the report that its own command does
	// not produce.
	//
	// The distinction was implicit in comments and invisible to any check
	// until a replay eval tried to reproduce every published command and could
	// not tell an offer from a record.
	Suggested bool `json:"suggested,omitempty"`
	// Status is the HTTP status observed.
	Status int `json:"status,omitempty"`
	// Response is the verbatim server response, truncated for readability.
	Response string `json:"response,omitempty"`
	// Rows is the exact row count when the server reported one.
	Rows int `json:"rows,omitempty"`
	// Columns lists the relation's columns as observed.
	Columns []string `json:"columns,omitempty"`
	// Sample holds real rows returned by the target. This is the proof.
	// Redacted when -redact is set.
	Sample []map[string]any `json:"sample,omitempty"`
	// Reason explains the classification in one clause.
	Reason string `json:"reason,omitempty"`
	// Classes names the KINDS of sensitive data this resource holds, as a
	// sorted, deduplicated machine-readable list -- never the values.
	//
	// Separate from Reason because Reason is prose written for a person, and
	// the summary table was reading it with a string parse: it split on commas
	// and took whatever followed the last colon, which recovers "column:tag"
	// pairs and recovers NOTHING from the sentence the value classifier
	// produces. So every kind found by looking at the data rather than at the
	// column names was absent from the table, silently, in a column headed
	// HOLDS. A renderer that has to parse prose will do that again.
	Classes []string `json:"classes,omitempty"`
}

Evidence carries the proof for a finding. unruly never reports a bare boolean: a claim that data is readable must be backed by data actually read, and a claim that a write is possible must quote the database's own response.

type Finding

type Finding struct {
	// ID is the rule identifier, kebab-case, nuclei-template style.
	ID string `json:"id"`
	// Name is a short human-readable title.
	Name string `json:"name"`
	// Severity drives filtering and exit codes.
	Severity Severity `json:"severity"`
	// Protocol is the surface the finding was observed on.
	Protocol string `json:"protocol"`
	// Matched is the URL or resource the finding applies to.
	Matched string `json:"matched"`
	// Resource is the logical target, e.g. a relation or bucket name.
	Resource string `json:"resource,omitempty"`
	// Description explains the issue.
	Description string `json:"description,omitempty"`
	// Remediation is SQL or configuration that fixes it. Emitted with -fix.
	Remediation string `json:"remediation,omitempty"`
	// FixKind says where that remediation is applied -- a database, a rules
	// file, a console, a credential rotation. Empty means unstated, and
	// unstated is never treated as SQL.
	FixKind FixKind `json:"fix_kind,omitempty"`
	// Reference links to documentation.
	Reference []string `json:"reference,omitempty"`
	// Evidence is the proof.
	Evidence Evidence `json:"evidence"`
	// Timestamp is set only when -timestamp is passed, so default output stays
	// byte-identical between runs.
	Timestamp *time.Time `json:"timestamp,omitempty"`
}

Finding is one result. Field order is stable for reproducible JSON.

func Coverage

func Coverage(target string, skipped []SkippedCheck) (Finding, bool)

Coverage builds the finding that records what a scan did NOT examine.

This belongs in the findings stream, not only in the log. The log is what a person watching a terminal sees; the findings stream is what gets stored, diffed in CI, pasted into a ticket and read by someone who was not there. With -silent -json a default scan emitted 13 findings and no trace at all that write exposure, routine callability, Edge Functions and route POST probing had never been checked — a machine-readable report that looks complete.

A tool whose central claim is that absence of findings is not evidence of absence has to say which absences it created on purpose, in the same place it says everything else.

func CredentialRejected

func CredentialRejected(base string, sent int64, role, source string) Finding

CredentialRejected reports that the project refused the key this scan used, so nothing measured is a statement about the project.

Kept separate from TargetRefused because the cause and the fix are different. A refusing host is unreachable; a rejected credential means the host is talking to us and declining to answer as anybody. The remedy is a different key, and the report has to say which key was tried and what role it claimed, because "no relations found" and "the key was wrong" look identical from the outside and only one of them is about the project.

func Dedup

func Dedup(fs []Finding) []Finding

Dedup removes repeated fingerprints, preserving first occurrence.

func Interrupted

func Interrupted(where string, cause error) Finding

Interrupted records that the scan did not finish.

It carries the blindness id the exit code already keys on, so an interrupted scan is treated the same as any other surface that could not be assessed -- no new precedence rule, and CI behaviour that operators already understand.

func NotAssessedApplication

func NotAssessedApplication(site, detail string) Finding

NotAssessedApplication reports that -site was given and could not be read.

It carries the same id as every other "this scan could not see" statement, because that is precisely what it is, and because the exit code already treats that id as blindness: an operator who asked for the application to be harvested and did not get it must not receive exit 0.

The alternative -- staying quiet and falling back to the pinned wordlist -- is what the tool did before. Recall dropped, the report got shorter, and nothing in it said why.

func NotAssessedBackend

func NotAssessedBackend(where string, requests int) Finding

NotAssessedBackend reports that a backend was recognised in the application but never examined, because no credential for it was found.

The distinction this draws is the one the whole report rests on. A scan that found a service_role key in a bundle and stopped there has produced a real finding AND examined no data at all; without this line the reader sees one critical result and a silence they will read as "nothing else".

func NotAssessedSchema

func NotAssessedSchema(restBase, schema, detail string) Finding

NotAssessedSchema reports that an exposed schema could not be judged. It reuses the id the exit code already keys on, so an unmeasured schema drives exit 3 exactly like an unmeasured surface.

func NotAssessedStage

func NotAssessedStage(where, stage, detail string) Finding

NotAssessedStage reports that a whole stage of the scan could not be run.

The pipeline turns every stage error into one of these rather than aborting, so a surface that refused a connection is reported as unexamined instead of silently passing for clean. It reuses the id the exit code keys on, which is what makes an unexamined surface drive exit 3.

func NotAssessedVerb

func NotAssessedVerb(restURL, relation, verb, detail string) Finding

NotAssessedVerb reports that UPDATE or DELETE could not be established.

Kept separate from NotAssessedWrite so the report names the verb. "Write was not assessed" on a relation whose INSERT verdict is confident reads as a contradiction; "DELETE was not assessed" is the actual fact.

DELETE lands here most often, and by design. The only DELETE probe that is both sound and non-destructive is one aimed at a row the scan created itself, so a relation that refuses INSERT can be read, written and updated by an anonymous caller with its DELETE permission still unknown. That is a real hole in the report and is stated as one.

func NotAssessedWrite

func NotAssessedWrite(restURL, relation, detail string) Finding

NotAssessedWrite reports that write access to a relation was requested but could not be established either way.

Before this, an inconclusive write verdict produced NOTHING: probe.Findings emitted a finding for WriteReached only, so a relation the write probe declined vanished from the report and from the exit code. On the reference target, `-write -no-residue` tests four INSERT-reachable relations, silently skips cve_articles -- which is INSERT-reachable but not read-exposed, so there is no sampled row to collide with -- and exits as though the write surface had been assessed in full. That is the tool's own thesis inverted: absence of a finding is only evidence when the scan could see.

It reuses the id the exit code already keys on, so an unassessed write drives exit 3 exactly like an unmeasured schema. That does mean -no-residue exits 3 on any project with an unreadable relation, which is the honest answer rather than the notBlindResources case: the routine cap is a DEFAULT that binds almost everywhere, while -no-residue is a mode the operator chose and whose help text says it "costs write recall". Having opted in, they are owed the list of what it cost. Not passing -write at all stays exit 0, because no write assessment was requested.

func ProbeAccountLeftBehind

func ProbeAccountLeftBehind(base, email string) Finding

ProbeAccountLeftBehind reports a user account this scan created on the target.

Reported for the same reason a probe row is: it is this scanner's own mess, not a property of the project, and hiding it would be the least defensible silence in the tool. The account is reused on later scans rather than recreated, so the litter is one per project and not one per run -- but one is still one, and the operator is the person who has to delete it.

func RestPrefixCorrected

func RestPrefixCorrected(base, from, to string) Finding

RestPrefixCorrected records that PostgREST was not where the scan first asked, and that the scan moved rather than reporting an empty project.

Reported, not silent. A scan that quietly changes where it is looking has changed what its result means, and the reader is entitled to know which address the findings below describe.

func RestPrefixUnresolved

func RestPrefixUnresolved(base, prefix string) Finding

RestPrefixUnresolved reports that PostgREST rejected the mount path the scan was using and no alternative could be confirmed.

The scan stops here rather than sending its whole plan to a path the server has already refused. Measured: continuing costs 18,756 requests, every one answered PGRST125, and produces a report that says 0 relations -- which is indistinguishable from a project with nothing exposed.

func ScanSummary

func ScanSummary(where string, relations, schemas, requests int, origins SeedOrigins) Finding

ScanSummary records the size of the examination, not its result.

It is deliberately info severity and never blind: it is not a claim that anything is wrong, it is the denominator for everything else in the report. A reader diffing two scans of the same project sees the relation count move and knows whether a change in findings means the project changed or the scan reached less of it.

func ScanSummarySurfaces

func ScanSummarySurfaces(where string, routes, origins, providerNames, requests int) Finding

ScanSummarySurfaces records the denominator for an application/provider scan that did not run the relational pipeline. Reporting "0 relations" would invent a database measurement; reporting nothing makes a stored artifact indistinguishable from a scan that never reached the target.

func SkippedStage

func SkippedStage(where, stage, reason string) Finding

SkippedStage reports a stage the OPERATOR turned off.

Distinct from NotAssessedStage, and the distinction is this project's own argument applied one level down. "Could not be assessed" means the scan tried and the surface refused; it drives exit 3, because an unexamined surface must not pass for a clean one. "The operator did not ask for this" means the scan was told not to look -- reporting that as a failure tells somebody to fix a cause that is their own flag, and inflates exit 3 into a number that no longer distinguishes a blind scan from a deliberately narrow one.

Still reported, and still info: a check that did not run is not a check that passed, and the reason names what would enable it.

func SubdomainsFound

func SubdomainsFound(domain string, hosts []string, tried int) Finding

SubdomainsFound reports other hosts under the same domain, and does not pretend to have scanned them.

The value is the forgotten deployment: a staging or preview host that shipped the same backend, was never decommissioned, and nobody has audited since. Production gets the review; the second copy is where an anon key with looser policies is still live.

Info, and no claim about any of them. Discovering that a host exists says nothing about its posture, and rating it as though it did would be the same error as reporting a Firestore 403 as a finding.

func TargetFailed

func TargetFailed(target string, cause error, keyWithheldRef string) Finding

TargetFailed records a target the scan could not get started on.

It carries the blindness id the exit code already keys on, so a failed target behaves like any other unmeasured surface rather than needing a rule of its own.

func TargetRefused

func TargetRefused(base string, sent int64, reason string) Finding

TargetRefused reports that the scan stopped because the target refused every request it had made so far.

This is the loudest possible "could not measure", and it exists because the alternative is worse than a slow scan. A host answering 429 or 5xx to everything produces a report full of "not assessed" lines and no findings, which is shaped exactly like a clean project. The reader has to notice the absence to get the answer right, and readers do not.

Severity is Info because it is a statement about the scan, not the target -- the same rule every scan-diagnostic follows. The exit code is what carries the weight: could-not-measure is 3, and 3 is not clean.

func WeakPasswordAccepted

func WeakPasswordAccepted(base, password string) Finding

WeakPasswordAccepted reports that the project let this scanner register an account with a password no policy worth the name would allow.

It costs nothing to establish. The signup path tries the weak password first because if it is accepted the account exists after one request instead of two -- so the password-policy answer is a by-product of work already done, and throwing it away would be discarding a measured fact.

Low, and deliberately so. A weak-password policy is not exposure: nobody's data moves because of it. It matters as the cheapest route into the authenticated tier for an attacker credential-stuffing a real user, which is a different report from the ones above it.

func (Finding) Fingerprint

func (f Finding) Fingerprint() string

Fingerprint is a deterministic content address for the finding, used for dedup and for stable diffing across runs. It intentionally excludes evidence and timestamps, which vary with database contents.

func (Finding) Where

func (f Finding) Where() string

Where renders the destination for a reader.

Phrased as a place rather than a mechanism, because the question it answers is "where do I go to fix this" and the answer is a console, a file, or a database prompt.

type FixKind

type FixKind string

FixKind says WHERE a remediation is applied.

Every remediation in this report begins with `--`, because the output is piped into psql -- by the remediation eval on every audit, and by operators for real. That convention is correct for a database and misleading everywhere else: Firestore rules live in a file that is edited and deployed, a signup requirement is a toggle in a console, and a leaked key is fixed by rotating it. Rendered identically to SQL, all three invite an operator to paste them into a SQL prompt, where they do nothing.

Empty means unstated, and unstated must never be read as SQL. Most findings predate this field, and a default that guessed "database" would put console instructions into a script somebody executes.

const (
	// FixSQL runs against the project's database.
	FixSQL FixKind = "sql"
	// FixRulesFile is edited in the repository and deployed.
	FixRulesFile FixKind = "rules-file"
	// FixConsole is a setting in the provider's dashboard.
	FixConsole FixKind = "console"
	// FixRotate is a credential that must be replaced, not reconfigured.
	FixRotate FixKind = "rotate-credential"
	// FixNone is for findings that describe the scan rather than the target.
	FixNone FixKind = "none"
)

type SeedOrigins

type SeedOrigins struct {
	// Pinned is the same on every scan and therefore says nothing about this
	// target.
	Pinned int
	// Harvested came from the application and is why a scan with a site beats
	// one without.
	Harvested int
	// Advertised is what the target named about itself.
	Advertised int
	// Supplied came from an operator or an agent. A report that cannot say how
	// many of its findings began as somebody else's suggestion cannot be
	// audited for it.
	Supplied int
}

SeedOrigins counts what each source of candidate names contributed.

It lives here rather than in a backend package because ScanSummary reports it and every backend has the same four kinds of source: a pinned list that ships with the binary, names harvested from the application, names the target advertises about itself, and names supplied from outside the process. A backend package could not own it without the reporting layer importing a backend, which is the wrong direction.

type Severity

type Severity int

Severity follows the nuclei scale so downstream filters (-severity critical) behave the way users already expect.

const (
	Info Severity = iota
	Low
	Medium
	High
	Critical
)

func ParseSeverity

func ParseSeverity(v string) (Severity, bool)

ParseSeverity resolves a -severity filter token.

func (Severity) MarshalJSON

func (s Severity) MarshalJSON() ([]byte, error)

func (Severity) String

func (s Severity) String() string

func (*Severity) UnmarshalJSON

func (s *Severity) UnmarshalJSON(b []byte) error

type SkippedCheck

type SkippedCheck struct {
	Name   string
	Reason string
	Enable string
}

SkippedCheck is a check that did not run, and why.

type Writer

type Writer struct {
	Out     io.Writer
	NoColor bool
	JSON    bool
	// Agent emits the compact, versioned, sample-free streaming contract.
	Agent bool
	// CSV renders one row per finding. Mutually exclusive with JSON; see
	// csv.go for why it never carries sampled rows.
	CSV     bool
	ShowFix bool
	Redact  bool
	MinSev  Severity
	// Proven keeps only findings something was actually retrieved for: rows
	// came back, a write was accepted, or the rows were classified. See
	// proven() -- and note that it filters the OUTPUT only. The verdict, the
	// exit code and the coverage report are computed before this from every
	// finding the scan produced, because "nothing was proven" and "nothing was
	// found" are different results and a flag that merged them would turn a
	// quiet report into a clean one.
	Proven bool
}

Writer renders findings.

func (Writer) Write

func (w Writer) Write(f Finding) error

Write emits one finding in nuclei-compatible form.

[supabase-anon-read-exposed] [postgrest] [critical] https://ref.supabase.co/rest/v1/sessions [17 rows]

type Writers

type Writers []Writer

Writers fans one finding out to several destinations.

-o used to REPLACE stdout rather than add to it, so a run that wrote a file showed the operator log lines and no findings. That made one scan produce one artifact: capturing both a human-readable report and machine-readable JSONL meant scanning twice, and the two scans disagreed, because a write probe adds a row between them. An audit noticed the row counts differing between two files described as the same run.

Writing to both also matches what an operator expects: a scanner told to save its output should not go quiet.

func (Writers) Write

func (ws Writers) Write(f Finding) error

Write sends the finding to every destination, returning the first error. Every writer is attempted regardless, so a full disk on one does not silently cost the other.

Jump to

Keyboard shortcuts

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