sarif

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 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) Severity

func (l Level) Severity() int

Severity ranks 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. Results are grouped into one run per 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"`
}

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.

Jump to

Keyboard shortcuts

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