scanexport

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 14 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 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

View Source
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

View Source
var SecretsCSVHeader = []string{
	"repository", "artifact_id", "scan_id", "scan_status", "type", "description", "severity",
}

SecretsCSVHeader is the first row of SecretsCSVRows.

View Source
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

func SafeCell(s string) string

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

func VulnCSVRows(items []VulnItem) [][]string

VulnCSVRows returns one row per finding (header excluded), most severe scans first as given. A scan without findings yields no row.

func WriteCSV

func WriteCSV(w io.Writer, header []string, rows [][]string) error

WriteCSV writes header and rows as RFC 4180 CSV with every cell guarded against formula injection.

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 Help

type Help struct {
	Text     string `json:"text"`
	Markdown string `json:"markdown,omitempty"`
}

Help is the rule's help text.

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

func VulnSARIF(items []VulnItem) (*Log, bool)

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 Text

type Text struct {
	Text string `json:"text"`
}

Text is a SARIF message string.

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.

Jump to

Keyboard shortcuts

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