Documentation
¶
Overview ¶
Package finding defines the Spackle finding: the schema every stage produces and every report renders, with validation, CVSS 4.0 scoring, deduplication and ranking.
Index ¶
- Constants
- func Classes() []string
- func ConfidenceRank(level string) int
- func DefaultVector(class string) (string, bool)
- func LabelRank(label string) int
- func MakeFingerprint(class string, loc Location, lines []string) string
- func MakeID(class string, loc Location) string
- func MakeRuleID(class string, loc Location, rule string) string
- func SafeID(id string) bool
- func Score(vector string) (float64, string, error)
- func SurfaceOf(class string) string
- func UnionOrigins(a, b []string) []string
- type Baseline
- type BaselineEntry
- type BaselineMatcher
- type BlastRadius
- type ClassInfo
- type Confidence
- type Exploitation
- type Finding
- type Flaw
- type FlowStep
- type Location
- type Proof
- type Remediation
- type Severity
Constants ¶
const ( ConfidenceDemonstrated = "demonstrated" // a proof of concept ran and succeeded ConfidenceHigh = "high" // traced end to end, not run ConfidencePlausible = "plausible" // a lead that was not confirmed )
Confidence levels, from strongest to weakest.
const ( ProofDemonstrated = "demonstrated" // PoC ran in the sandbox and triggered the flaw ProofReasoned = "reasoned" // exploit path argued from code or traffic, not run ProofNotRun = "not-run" // no sandbox, or the operator declined live testing ProofFailed = "failed" // PoC ran and did not trigger the flaw )
Proof statuses.
const ( StatusOpen = "open" StatusDismissed = "dismissed" // refuted by the reviewer; reason kept // StatusPatchAvailable means a patch was written and checked against // the proof, but it is not applied: the scanned code still has the flaw. StatusPatchAvailable = "patch-available" // StatusFixed means the stored proof no longer succeeds against the // code itself, which is what "spackle verify" establishes. StatusFixed = "fixed" // StatusAccepted means an entry of the baseline file accepted the // finding: it is still reported, but it does not fail the run. StatusAccepted = "accepted" )
Statuses.
const ( SurfaceCode = "code" SurfaceDAST = "running-target" SurfaceInfra = "infrastructure" SurfaceDebug = "debug" )
Surfaces.
const BaselineVersion = 1
BaselineVersion is the format version a baseline file is written with.
Variables ¶
This section is empty.
Functions ¶
func ConfidenceRank ¶ added in v0.2.0
ConfidenceRank orders confidence levels; higher is stronger. An unknown or empty level ranks as plausible, the weakest.
func DefaultVector ¶
DefaultVector returns the starting CVSS 4.0 vector for a class, and whether the class is known.
func LabelRank ¶
LabelRank orders severity labels; higher is worse. Unknown labels rank below "none".
func MakeFingerprint ¶ added in v0.2.0
MakeFingerprint derives a line-independent fingerprint for a finding: a hash of its class, file, endpoint and parameter, the text of the flagged lines with runs of white space collapsed, and how many times the same text occurs earlier in the file. Lines added or removed elsewhere in the file leave it unchanged; editing the flagged lines changes it. lines is the file's content split into lines (as the caller wants it hashed, after redaction), or nil when the finding has no file or the file could not be read; the fingerprint then rests on the rest alone.
func MakeID ¶
MakeID derives a stable finding id from what the finding is and where it is, so the same flaw gets the same id on every run of the same target.
func MakeRuleID ¶ added in v0.2.0
MakeRuleID is MakeID for a finding that comes straight from a rule hit. The rule is part of the id, so two different rules of one class that fire at the same place stay two findings, while the same rule reported by two seeders still gets one id. An empty rule gives the same id as MakeID.
func SafeID ¶ added in v0.2.0
SafeID reports whether id can be used as one path element: 1 to 64 letters, digits, '.', '_' or '-', starting with a letter or digit. A finding id names its folder in the run directory, and a run folder can come from somewhere else, so every id is checked before it becomes part of a path.
func Score ¶
Score validates a CVSS 4.0 vector and returns its score and the lowercase qualitative rating (critical, high, medium, low, none).
func SurfaceOf ¶ added in v0.2.0
SurfaceOf returns the surface a finding of the class belongs to when nothing more specific is known about it: SurfaceInfra for the deployment and CI classes, SurfaceCode for every other class.
func UnionOrigins ¶ added in v0.2.0
UnionOrigins returns the sorted union of two origin lists.
Types ¶
type Baseline ¶ added in v0.2.0
type Baseline struct {
Version int `json:"version"`
Entries []BaselineEntry `json:"entries"`
}
Baseline is the file of accepted findings: a finding that matches an entry gets the status accepted, stays in every report, and does not fail the run.
func LoadBaseline ¶ added in v0.2.0
LoadBaseline reads and checks a baseline file.
func NewBaseline ¶ added in v0.2.0
NewBaseline makes a baseline that accepts every unresolved finding of fs (open or with a patch available), with reason on each entry.
func ParseBaseline ¶ added in v0.2.0
ParseBaseline decodes a baseline and checks every entry.
type BaselineEntry ¶ added in v0.2.0
type BaselineEntry struct {
ID string `json:"id"`
Fingerprint string `json:"fingerprint,omitempty"`
Class string `json:"class"`
Title string `json:"title"`
Location string `json:"location"`
// Reason says why the finding is accepted.
Reason string `json:"reason,omitempty"`
// Expires is a date (YYYY-MM-DD). From that day on the entry no longer
// accepts anything.
Expires string `json:"expires,omitempty"`
}
BaselineEntry accepts one finding. It matches a finding with the same fingerprint, or, when either side has none, the same id. Title, class and location are there for the person reading the file.
func (BaselineEntry) Matches ¶ added in v0.2.0
func (e BaselineEntry) Matches(f Finding) bool
Matches reports whether the entry accepts f, whether or not it expired.
func (BaselineEntry) String ¶ added in v0.2.0
func (e BaselineEntry) String() string
String names the entry the way notes cite it.
type BaselineMatcher ¶ added in v0.2.0
type BaselineMatcher struct {
// contains filtered or unexported fields
}
BaselineMatcher applies a baseline to the findings of one run and remembers which entries were used.
func NewBaselineMatcher ¶ added in v0.2.0
func NewBaselineMatcher(b Baseline, now time.Time) *BaselineMatcher
NewBaselineMatcher prepares b for a run on day now.
func (*BaselineMatcher) Apply ¶ added in v0.2.0
func (m *BaselineMatcher) Apply(f *Finding) bool
Apply sets f to accepted when an entry that has not expired matches it. Only an open finding or one with a patch available can be accepted. It reports whether f was accepted.
func (*BaselineMatcher) Unused ¶ added in v0.2.0
func (m *BaselineMatcher) Unused() (stale, expired []BaselineEntry)
Unused returns the entries that matched no finding and have not expired (stale: the finding is gone or changed), and those that have expired.
type BlastRadius ¶
type BlastRadius struct {
Gains []string `json:"gains,omitempty"`
Exposed []string `json:"exposed,omitempty"`
KillChain string `json:"kill_chain,omitempty"`
Related []string `json:"related,omitempty"` // ids of findings this combines with
}
BlastRadius says what an attacker gains.
type ClassInfo ¶
type ClassInfo struct {
Name string // human name, e.g. "SQL injection"
OWASP []string // OWASP Top 10 2021 category names, exact
Preconditions []string // 1 to 2 items: what an attacker needs
Steps []string // 2 to 4 items: the typical attack chain, defender-level description
ChainsInto []string // 1 to 2 items: what it commonly leads to
Gains []string // 1 to 3 items: what the attacker gets
Fix string // one or two sentences: the specific, standard remediation
}
ClassInfo is general, class-level knowledge used to describe a lead that no model has investigated. Reports label it as typical for the class, not confirmed for the code.
type Confidence ¶
Confidence is the honest label with its reason.
type Exploitation ¶
type Exploitation struct {
Preconditions []string `json:"preconditions,omitempty"`
Steps []string `json:"steps,omitempty"`
ChainsInto []string `json:"chains_into,omitempty"`
}
Exploitation is the attacker's-eye scenario.
type Finding ¶
type Finding struct {
ID string `json:"id"`
// Fingerprint identifies the flaw by the text of the flagged code, not
// its line number, so a finding that only moved keeps it. See
// MakeFingerprint. Empty in runs stored before it existed.
Fingerprint string `json:"fingerprint,omitempty"`
Title string `json:"title"`
Surface string `json:"surface"`
Class string `json:"class"`
CWE []string `json:"cwe,omitempty"`
OWASP []string `json:"owasp,omitempty"`
Location Location `json:"location"`
Severity Severity `json:"severity"`
Flaw Flaw `json:"flaw"`
Exploitation Exploitation `json:"exploitation"`
Proof Proof `json:"proof"`
BlastRadius BlastRadius `json:"blast_radius"`
Remediation Remediation `json:"remediation"`
Confidence Confidence `json:"confidence"`
Origin []string `json:"origin,omitempty"`
Status string `json:"status"`
// DismissReason is set when Status is dismissed.
DismissReason string `json:"dismiss_reason,omitempty"`
// AcceptReason is the baseline entry's reason when Status is accepted.
AcceptReason string `json:"accept_reason,omitempty"`
}
Finding is one reported flaw. Field order here is the order JSON output uses, and the order a report presents the sections in.
func Dedup ¶
Dedup merges findings that share an id, keeping the stronger one and the union of their origins. Input order decides ties.
type Flaw ¶
type Flaw struct {
Description string `json:"description"`
Flow []FlowStep `json:"flow,omitempty"`
}
Flaw describes what is wrong and how data reaches the sink.
type FlowStep ¶
type FlowStep struct {
Role string `json:"role"` // source|propagation|sanitizer|sink
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Quote string `json:"quote,omitempty"`
Note string `json:"note,omitempty"`
}
FlowStep is one hop from source to sink, quoting the real code or traffic.
type Location ¶
type Location struct {
File string `json:"file,omitempty"` // forward-slash path relative to the target root
StartLine int `json:"start_line,omitempty"`
EndLine int `json:"end_line,omitempty"`
Symbol string `json:"symbol,omitempty"`
Method string `json:"method,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Parameter string `json:"parameter,omitempty"`
}
Location says exactly where the flaw is: a file and line range, or an endpoint and parameter. At least one form must be present.
type Proof ¶
type Proof struct {
Status string `json:"status"`
Kind string `json:"kind,omitempty"` // test|script|http-sequence
Summary string `json:"summary,omitempty"`
Artifacts []string `json:"artifacts,omitempty"` // paths relative to the run directory
Command string `json:"command,omitempty"`
Result string `json:"result,omitempty"` // captured output or response excerpt
Isolation string `json:"isolation,omitempty"`
Reason string `json:"reason,omitempty"` // why it was not run, when it was not
}
Proof records the demonstration, or why there is none.
type Remediation ¶
type Remediation struct {
Summary string `json:"summary"`
Patch string `json:"patch,omitempty"` // unified diff
Why string `json:"why,omitempty"`
DefenseInDepth []string `json:"defense_in_depth,omitempty"`
Verification string `json:"verification,omitempty"` // verified|unverified|rejected
Branch string `json:"branch,omitempty"`
}
Remediation is the fix.
type Severity ¶
type Severity struct {
Vector string `json:"cvss_vector,omitempty"`
Score float64 `json:"cvss_score"`
Label string `json:"label"` // critical|high|medium|low|none
Reasoning string `json:"reasoning,omitempty"`
// Unscored is true when no valid vector was available and Label is an
// estimate carried over from a scanner or rule.
Unscored bool `json:"unscored,omitempty"`
}
Severity holds a CVSS 4.0 assessment. Score and Label are always computed by Spackle from Vector; a model never supplies them.
func SeverityFromVector ¶
SeverityFromVector builds a Severity from a vector, computing the score and label.