Documentation
¶
Overview ¶
Package scanexport renders stored vulnerability and secret scan results as SARIF 2.1.0 (for GitHub code scanning, DefectDojo and other SARIF consumers) and as CSV. Secret exports never carry a secret value, not even a redacted one.
Index ¶
- Constants
- Variables
- func SafeCell(s string) string
- func SecretsCSVRows(items []SecretItem) [][]string
- func VulnCSVRows(items []VulnItem) [][]string
- func WriteCSV(w io.Writer, header []string, rows [][]string) error
- type ArtifactLocation
- type AutomationDetails
- type Driver
- type Help
- type Invocation
- type Location
- type Log
- type LogicalLocation
- type PhysicalLocation
- type Region
- type Result
- type Rule
- type Run
- type SecretItem
- type Text
- type Tool
- type VulnItem
Constants ¶
const ( // MaxResults is the most results GitHub code scanning accepts in one SARIF // file; an export holds back the least severe findings beyond it. MaxResults = 25000 )
Variables ¶
var SecretsCSVHeader = []string{
"repository", "artifact_id", "scan_id", "scan_status", "type", "description", "severity",
}
SecretsCSVHeader is the first row of SecretsCSVRows.
var VulnCSVHeader = []string{
"repository", "artifact_id", "package_name", "package_version", "ecosystem", "scanner",
"scan_id", "scan_status", "vulnerability_id", "severity", "cvss", "fixed_in", "summary",
"published_at", "references",
"kev", "kev_date_added", "kev_due_date", "epss", "epss_percentile", "priority",
}
VulnCSVHeader is the first row of VulnCSV.
Functions ¶
func SafeCell ¶
SafeCell neutralizes spreadsheet formula injection: a cell that starts with "=", "+", "-", "@", a tab or a carriage return would be evaluated by Excel or LibreOffice, so it is prefixed with a single quote (OWASP CSV injection).
func SecretsCSVRows ¶
func SecretsCSVRows(items []SecretItem) [][]string
SecretsCSVRows returns one row per finding (header excluded); no secret value is included.
func VulnCSVRows ¶
VulnCSVRows returns one row per finding (header excluded), most severe scans first as given. A scan without findings yields no row.
Types ¶
type ArtifactLocation ¶
type ArtifactLocation struct {
URI string `json:"uri"`
}
ArtifactLocation is the artifact's relative URI.
type AutomationDetails ¶
type AutomationDetails struct {
ID string `json:"id"`
}
AutomationDetails distinguishes runs of the same tool in one upload.
type Driver ¶
type Driver struct {
Name string `json:"name"`
InformationURI string `json:"informationUri,omitempty"`
Rules []Rule `json:"rules"`
}
Driver is the tool component with its rules.
type Invocation ¶
type Invocation struct {
ExecutionSuccessful bool `json:"executionSuccessful"`
}
Invocation records whether the tool ran to completion.
type Location ¶
type Location struct {
PhysicalLocation PhysicalLocation `json:"physicalLocation"`
LogicalLocations []LogicalLocation `json:"logicalLocations,omitempty"`
}
Location points at the artifact a finding is about.
type Log ¶
type Log struct {
Schema string `json:"$schema"`
Version string `json:"version"`
Runs []Run `json:"runs"`
}
Log is a SARIF log: the top-level object of a .sarif file.
func SecretsSARIF ¶
func SecretsSARIF(items []SecretItem) (*Log, bool)
SecretsSARIF builds a SARIF log of the scans' findings: one run, one rule per secret type, one result per finding, located by the artifact path "<repository>/<artifact id>". A finding's value, redacted or not, and its surrounding text are never exported. truncated is true when more than MaxResults findings existed.
func VulnSARIF ¶
VulnSARIF builds a SARIF log of the scans' findings: one run per scanner, one rule per vulnerability id, one result per package and vulnerability, located by the artifact path "<repository>/<artifact id>" with the package URL as a logical location. Failed and pending scans have no findings and contribute none; a partial scan marks its run unsuccessful. truncated is true when more than MaxResults findings existed and the least severe were dropped.
type LogicalLocation ¶
type LogicalLocation struct {
Name string `json:"name"`
FullyQualifiedName string `json:"fullyQualifiedName,omitempty"`
Kind string `json:"kind,omitempty"`
}
LogicalLocation names the package a finding is about.
type PhysicalLocation ¶
type PhysicalLocation struct {
ArtifactLocation ArtifactLocation `json:"artifactLocation"`
Region Region `json:"region"`
}
PhysicalLocation is a file-like place.
type Region ¶
type Region struct {
StartLine int `json:"startLine"`
}
Region is the (whole-artifact) region of a finding.
type Result ¶
type Result struct {
RuleID string `json:"ruleId"`
RuleIndex int `json:"ruleIndex"`
Level string `json:"level"`
Message Text `json:"message"`
Locations []Location `json:"locations"`
PartialFingerprints map[string]string `json:"partialFingerprints"`
Properties map[string]any `json:"properties,omitempty"`
}
Result is one finding.
type Rule ¶
type Rule struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
ShortDescription *Text `json:"shortDescription,omitempty"`
FullDescription *Text `json:"fullDescription,omitempty"`
Help *Help `json:"help,omitempty"`
HelpURI string `json:"helpUri,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
}
Rule describes one kind of finding (a vulnerability id or a secret type).
type Run ¶
type Run struct {
Tool Tool `json:"tool"`
AutomationDetails *AutomationDetails `json:"automationDetails,omitempty"`
Invocations []Invocation `json:"invocations,omitempty"`
Results []Result `json:"results"`
Properties map[string]any `json:"properties,omitempty"`
}
Run is the output of one tool.
type SecretItem ¶
type SecretItem struct {
Repo string
Scan *models.SecretScanResult
}
SecretItem is a secret scan with the name of its repository.
type Tool ¶
type Tool struct {
Driver Driver `json:"driver"`
}
Tool names the program that produced a run.
type VulnItem ¶
type VulnItem struct {
Repo string
Scan *models.VulnScanResult
// Annotations are the exploitation signals of Scan.Vulnerabilities, index
// for index; empty when the findings were not annotated.
Annotations []exploit.Annotation
}
VulnItem is a vulnerability scan with the name of its repository.