sarif

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sarif provides Draugr's result currency: a pragmatic model of SARIF 2.1.0 findings, plus merge and deduplication. Every scanner normalizes its output to a Report; the engine merges reports and the result can be serialized to standard SARIF JSON for GitHub / Azure DevOps / GitLab.

Index

Constants

View Source
const Version = "2.1.0"

Version is the SARIF specification version Draugr emits.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counts

type Counts struct {
	Error   int
	Warning int
	Note    int
	None    int
}

Counts tallies results by severity.

func (Counts) Total

func (c Counts) Total() int

Total returns the sum of all counts.

type Level

type Level string

Level is the severity of a result, mirroring SARIF's result.level.

const (
	LevelError   Level = "error"
	LevelWarning Level = "warning"
	LevelNote    Level = "note"
	LevelNone    Level = "none"
)

The SARIF result levels.

func (Level) AtLeast

func (l Level) AtLeast(other Level) bool

AtLeast reports whether l is at least as severe as other.

func (Level) Rank added in v0.5.0

func (l Level) Rank() int

Rank orders levels from most to least severe (higher is worse): error=3, warning=2, note=1, none/unknown=0.

type Location

type Location struct {
	URI       string `json:"uri,omitempty"`
	StartLine int    `json:"startLine,omitempty"`
}

Location points at where a finding was observed.

type Report

type Report struct {
	Tool    string   `json:"tool,omitempty"`
	Results []Result `json:"results"`
}

Report is a set of findings, normalized to SARIF semantics. Tool names the primary scanner; when a report carries results from several tools (after Merge), each Result keeps its own Tool.

func FromSARIF

func FromSARIF(data []byte) (Report, error)

FromSARIF parses standard SARIF 2.1.0 JSON into a Report, flattening all runs and setting each result's Tool from its run's driver name.

func Merge

func Merge(reports ...Report) Report

Merge combines reports into one, deduplicating results by fingerprint and preserving first-seen order. Each result's Tool is backfilled from its source report when unset.

func (Report) Counts

func (r Report) Counts() Counts

Counts tallies the report's results by severity.

func (Report) Dedup

func (r Report) Dedup() Report

Dedup returns a copy with exact-duplicate results removed, preserving first-seen order.

func (Report) Highest

func (r Report) Highest() Level

Highest returns the most severe level present, or LevelNone when there are no results.

func (Report) MarshalSARIF

func (r Report) MarshalSARIF() ([]byte, error)

MarshalSARIF serializes the report to standard SARIF 2.1.0 JSON as a single "Draugr" run, with each result's originating scanner recorded in its property bag ("tool").

type Result

type Result struct {
	// Tool is the scanner that produced the finding.
	Tool     string   `json:"tool,omitempty"`
	RuleID   string   `json:"ruleId"`
	Level    Level    `json:"level"`
	Message  string   `json:"message"`
	Location Location `json:"location,omitempty"`
	// Score is the finding's numeric CVSS-style severity (0–10), sourced from the SARIF
	// "security-severity" property. HasScore reports whether a score was present; without
	// one, normalized Severity falls back to Level.
	Score    float64 `json:"score,omitempty"`
	HasScore bool    `json:"-"`
	// Priority is the computed action band (P1–P4) for this finding, stamped by the engine
	// from the component's risk classification. Empty when prioritization is not configured.
	Priority string `json:"priority,omitempty"`
}

Result is a single finding.

func (Result) Fingerprint

func (r Result) Fingerprint() string

Fingerprint is a stable identifier for deduplication: two results with the same fingerprint are considered the same finding.

func (Result) Severity added in v0.5.0

func (r Result) Severity(floor Severity) Severity

Severity resolves a finding's normalized severity, in the order the SARIF/prioritization design prescribes:

  1. the finding's numeric score (CVSS / SARIF security-severity), if present;
  2. otherwise its SARIF level;
  3. then raised to floor if floor is more severe (a control-default floor, e.g. a leaked secret is never "low"). Pass an empty floor for no floor.

type Severity added in v0.5.0

type Severity string

Severity is Draugr's normalized, cross-control severity ladder. Unlike Level (the SARIF wire values error/warning/note), Severity is what prioritization ranks on: it splits a numeric CVSS-style score into four bands so a dependency CVE, a leaked secret, and an IaC misconfiguration can share one ordered list. See docs/concepts.md (prioritization).

const (
	SeverityCritical Severity = "critical"
	SeverityHigh     Severity = "high"
	SeverityMedium   Severity = "medium"
	SeverityLow      Severity = "low"
)

Severity bands, from most to least severe.

func (Severity) AtLeast added in v0.5.0

func (s Severity) AtLeast(other Severity) bool

AtLeast reports whether s is at least as severe as other.

func (Severity) Escalate added in v0.7.0

func (s Severity) Escalate() Severity

Escalate returns the next-higher severity band; critical is already the maximum. Used by exploitability enrichment to bump a finding one band.

func (Severity) Rank added in v0.5.0

func (s Severity) Rank() int

Rank orders severities (higher is worse): critical=4, high=3, medium=2, low=1, empty/unknown=0.

Jump to

Keyboard shortcuts

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