{"modulePath":"github.com/TMHSDigital/spackle","version":"v0.2.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package finding\n\nPackage finding defines the Spackle finding: the schema every stage produces and every report renders, with validation, CVSS 4.0 scoring, deduplication and ranking.\n\n## Constants\n\n```go\nconst (\n\tConfidenceDemonstrated = \"demonstrated\" // a proof of concept ran and succeeded\n\tConfidenceHigh         = \"high\"         // traced end to end, not run\n\tConfidencePlausible    = \"plausible\"    // a lead that was not confirmed\n)\n```\nConfidence levels, from strongest to weakest.\n\n```go\nconst (\n\tProofDemonstrated = \"demonstrated\" // PoC ran in the sandbox and triggered the flaw\n\tProofReasoned     = \"reasoned\"     // exploit path argued from code or traffic, not run\n\tProofNotRun       = \"not-run\"      // no sandbox, or the operator declined live testing\n\tProofFailed       = \"failed\"       // PoC ran and did not trigger the flaw\n)\n```\nProof statuses.\n\n```go\nconst (\n\tStatusOpen      = \"open\"\n\tStatusDismissed = \"dismissed\" // refuted by the reviewer; reason kept\n\t// StatusPatchAvailable means a patch was written and checked against\n\t// the proof, but it is not applied: the scanned code still has the flaw.\n\tStatusPatchAvailable = \"patch-available\"\n\t// StatusFixed means the stored proof no longer succeeds against the\n\t// code itself, which is what \"spackle verify\" establishes.\n\tStatusFixed = \"fixed\"\n\t// StatusAccepted means an entry of the baseline file accepted the\n\t// finding: it is still reported, but it does not fail the run.\n\tStatusAccepted = \"accepted\"\n)\n```\nStatuses.\n\n```go\nconst (\n\tSurfaceCode  = \"code\"\n\tSurfaceDAST  = \"running-target\"\n\tSurfaceInfra = \"infrastructure\"\n\tSurfaceDebug = \"debug\"\n)\n```\nSurfaces.\n\n```go\nconst BaselineVersion = 1\n```\nBaselineVersion is the format version a baseline file is written with.\n\n## Functions\n\n```go\nfunc Classes() []string\n```\nClasses returns every class that has a default vector.\n\n```go\nfunc ConfidenceRank(level string) int\n```\nConfidenceRank orders confidence levels; higher is stronger. An unknown or empty level ranks as plausible, the weakest.\n\n```go\nfunc DefaultVector(class string) (string, bool)\n```\nDefaultVector returns the starting CVSS 4.0 vector for a class, and whether the class is known.\n\n```go\nfunc LabelRank(label string) int\n```\nLabelRank orders severity labels; higher is worse. Unknown labels rank below \"none\".\n\n```go\nfunc MakeFingerprint(class string, loc Location, lines []string) string\n```\nMakeFingerprint 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.\n\n```go\nfunc MakeID(class string, loc Location) string\n```\nMakeID 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.\n\n```go\nfunc MakeRuleID(class string, loc Location, rule string) string\n```\nMakeRuleID 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.\n\n```go\nfunc SafeID(id string) bool\n```\nSafeID 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.\n\n```go\nfunc Score(vector string) (float64, string, error)\n```\nScore validates a CVSS 4.0 vector and returns its score and the lowercase qualitative rating (critical, high, medium, low, none).\n\n```go\nfunc SurfaceOf(class string) string\n```\nSurfaceOf 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.\n\n```go\nfunc UnionOrigins(a, b []string) []string\n```\nUnionOrigins returns the sorted union of two origin lists.\n\n## Types\n\n```go\ntype Baseline struct {\n\tVersion int             `json:\"version\"`\n\tEntries []BaselineEntry `json:\"entries\"`\n}\n```\nBaseline 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.\n\n```go\nfunc LoadBaseline(path string) (Baseline, error)\n```\nLoadBaseline reads and checks a baseline file.\n\n```go\nfunc NewBaseline(fs []Finding, reason string) Baseline\n```\nNewBaseline makes a baseline that accepts every unresolved finding of fs (open or with a patch available), with reason on each entry.\n\n```go\nfunc ParseBaseline(raw []byte) (Baseline, error)\n```\nParseBaseline decodes a baseline and checks every entry.\n\n```go\ntype BaselineEntry struct {\n\tID          string `json:\"id\"`\n\tFingerprint string `json:\"fingerprint,omitempty\"`\n\tClass       string `json:\"class\"`\n\tTitle       string `json:\"title\"`\n\tLocation    string `json:\"location\"`\n\t// Reason says why the finding is accepted.\n\tReason string `json:\"reason,omitempty\"`\n\t// Expires is a date (YYYY-MM-DD). From that day on the entry no longer\n\t// accepts anything.\n\tExpires string `json:\"expires,omitempty\"`\n}\n```\nBaselineEntry 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.\n\n```go\nfunc (e BaselineEntry) Matches(f Finding) bool\n```\nMatches reports whether the entry accepts f, whether or not it expired.\n\n```go\nfunc (e BaselineEntry) String() string\n```\nString names the entry the way notes cite it.\n\n```go\ntype BaselineMatcher struct {\n\t// contains filtered or unexported fields\n}\n```\nBaselineMatcher applies a baseline to the findings of one run and remembers which entries were used.\n\n```go\nfunc NewBaselineMatcher(b Baseline, now time.Time) *BaselineMatcher\n```\nNewBaselineMatcher prepares b for a run on day now.\n\n```go\nfunc (m *BaselineMatcher) Apply(f *Finding) bool\n```\nApply 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.\n\n```go\nfunc (m *BaselineMatcher) Unused() (stale, expired []BaselineEntry)\n```\nUnused returns the entries that matched no finding and have not expired (stale: the finding is gone or changed), and those that have expired.\n\n```go\ntype BlastRadius struct {\n\tGains     []string `json:\"gains,omitempty\"`\n\tExposed   []string `json:\"exposed,omitempty\"`\n\tKillChain string   `json:\"kill_chain,omitempty\"`\n\tRelated   []string `json:\"related,omitempty\"` // ids of findings this combines with\n}\n```\nBlastRadius says what an attacker gains.\n\n```go\ntype ClassInfo struct {\n\tName          string   // human name, e.g. \"SQL injection\"\n\tOWASP         []string // OWASP Top 10 2021 category names, exact\n\tPreconditions []string // 1 to 2 items: what an attacker needs\n\tSteps         []string // 2 to 4 items: the typical attack chain, defender-level description\n\tChainsInto    []string // 1 to 2 items: what it commonly leads to\n\tGains         []string // 1 to 3 items: what the attacker gets\n\tFix           string   // one or two sentences: the specific, standard remediation\n}\n```\nClassInfo 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.\n\n```go\nfunc Info(class string) ClassInfo\n```\nInfo returns the class-level knowledge for a class. An unknown class yields a zero-value ClassInfo whose Name is the class itself. The returned slices are shared and must not be modified.\n\n```go\ntype Confidence struct {\n\tLevel  string `json:\"level\"`\n\tReason string `json:\"reason\"`\n}\n```\nConfidence is the honest label with its reason.\n\n```go\ntype Exploitation struct {\n\tPreconditions []string `json:\"preconditions,omitempty\"`\n\tSteps         []string `json:\"steps,omitempty\"`\n\tChainsInto    []string `json:\"chains_into,omitempty\"`\n}\n```\nExploitation is the attacker's-eye scenario.\n\n```go\ntype Finding struct {\n\tID string `json:\"id\"`\n\t// Fingerprint identifies the flaw by the text of the flagged code, not\n\t// its line number, so a finding that only moved keeps it. See\n\t// MakeFingerprint. Empty in runs stored before it existed.\n\tFingerprint string   `json:\"fingerprint,omitempty\"`\n\tTitle       string   `json:\"title\"`\n\tSurface     string   `json:\"surface\"`\n\tClass       string   `json:\"class\"`\n\tCWE         []string `json:\"cwe,omitempty\"`\n\tOWASP       []string `json:\"owasp,omitempty\"`\n\n\tLocation Location `json:\"location\"`\n\tSeverity Severity `json:\"severity\"`\n\n\tFlaw         Flaw         `json:\"flaw\"`\n\tExploitation Exploitation `json:\"exploitation\"`\n\tProof        Proof        `json:\"proof\"`\n\tBlastRadius  BlastRadius  `json:\"blast_radius\"`\n\tRemediation  Remediation  `json:\"remediation\"`\n\tConfidence   Confidence   `json:\"confidence\"`\n\n\tOrigin []string `json:\"origin,omitempty\"`\n\tStatus string   `json:\"status\"`\n\t// DismissReason is set when Status is dismissed.\n\tDismissReason string `json:\"dismiss_reason,omitempty\"`\n\t// AcceptReason is the baseline entry's reason when Status is accepted.\n\tAcceptReason string `json:\"accept_reason,omitempty\"`\n}\n```\nFinding is one reported flaw. Field order here is the order JSON output uses, and the order a report presents the sections in.\n\n```go\nfunc Dedup(fs []Finding) []Finding\n```\nDedup merges findings that share an id, keeping the stronger one and the union of their origins. Input order decides ties.\n\n```go\nfunc Rank(fs []Finding) []Finding\n```\nRank returns the findings ordered for a report: open before fixed before dismissed, then by severity label, score, confidence, and finally id so the order is total and stable.\n\n```go\nfunc (f *Finding) Validate() error\n```\nValidate checks that a finding is complete enough to report. It returns every problem at once so a rejected draft can be explained in one message.\n\n```go\ntype Flaw struct {\n\tDescription string     `json:\"description\"`\n\tFlow        []FlowStep `json:\"flow,omitempty\"`\n}\n```\nFlaw describes what is wrong and how data reaches the sink.\n\n```go\ntype FlowStep struct {\n\tRole  string `json:\"role\"` // source|propagation|sanitizer|sink\n\tFile  string `json:\"file,omitempty\"`\n\tLine  int    `json:\"line,omitempty\"`\n\tQuote string `json:\"quote,omitempty\"`\n\tNote  string `json:\"note,omitempty\"`\n}\n```\nFlowStep is one hop from source to sink, quoting the real code or traffic.\n\n```go\ntype Location struct {\n\tFile      string `json:\"file,omitempty\"` // forward-slash path relative to the target root\n\tStartLine int    `json:\"start_line,omitempty\"`\n\tEndLine   int    `json:\"end_line,omitempty\"`\n\tSymbol    string `json:\"symbol,omitempty\"`\n\n\tMethod    string `json:\"method,omitempty\"`\n\tEndpoint  string `json:\"endpoint,omitempty\"`\n\tParameter string `json:\"parameter,omitempty\"`\n}\n```\nLocation says exactly where the flaw is: a file and line range, or an endpoint and parameter. At least one form must be present.\n\n```go\nfunc (l Location) String() string\n```\nString renders the location the way a report cites it.\n\n```go\ntype Proof struct {\n\tStatus    string   `json:\"status\"`\n\tKind      string   `json:\"kind,omitempty\"` // test|script|http-sequence\n\tSummary   string   `json:\"summary,omitempty\"`\n\tArtifacts []string `json:\"artifacts,omitempty\"` // paths relative to the run directory\n\tCommand   string   `json:\"command,omitempty\"`\n\tResult    string   `json:\"result,omitempty\"` // captured output or response excerpt\n\tIsolation string   `json:\"isolation,omitempty\"`\n\tReason    string   `json:\"reason,omitempty\"` // why it was not run, when it was not\n}\n```\nProof records the demonstration, or why there is none.\n\n```go\ntype Remediation struct {\n\tSummary        string   `json:\"summary\"`\n\tPatch          string   `json:\"patch,omitempty\"` // unified diff\n\tWhy            string   `json:\"why,omitempty\"`\n\tDefenseInDepth []string `json:\"defense_in_depth,omitempty\"`\n\tVerification   string   `json:\"verification,omitempty\"` // verified|unverified|rejected\n\tBranch         string   `json:\"branch,omitempty\"`\n}\n```\nRemediation is the fix.\n\n```go\ntype Severity struct {\n\tVector    string  `json:\"cvss_vector,omitempty\"`\n\tScore     float64 `json:\"cvss_score\"`\n\tLabel     string  `json:\"label\"` // critical|high|medium|low|none\n\tReasoning string  `json:\"reasoning,omitempty\"`\n\t// Unscored is true when no valid vector was available and Label is an\n\t// estimate carried over from a scanner or rule.\n\tUnscored bool `json:\"unscored,omitempty\"`\n}\n```\nSeverity holds a CVSS 4.0 assessment. Score and Label are always computed by Spackle from Vector; a model never supplies them.\n\n```go\nfunc SeverityFromVector(vector, reasoning string) (Severity, error)\n```\nSeverityFromVector builds a Severity from a vector, computing the score and label.\n\n","path":"github.com/TMHSDigital/spackle/internal/finding","name":"finding","synopsis":"Package finding defines the Spackle finding: the schema every stage produces and every report renders, with validation, CVSS 4.0 scoring, deduplication and ranking.","isRedistributable":true}
