sarif

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sarif provides a comprehensive parser and utilities for SARIF (Static Analysis Results Interchange Format) version 2.1.0.

SARIF is an OASIS standard format for the output of static analysis tools. This package implements the full SARIF 2.1.0 specification as defined at: https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html

Basic Usage

Parse a SARIF file:

parser := sarif.NewParser(nil)
log, err := parser.ParseFile("results.sarif")
if err != nil {
	log.Fatal(err)
}

Parse from bytes or reader:

log, err := parser.ParseBytes(data)
log, err := parser.Parse(reader)

Parser Options

Configure parser behavior with Options:

opts := &sarif.Options{
	StrictMode:           true,       // Enable strict validation
	IncludePassedResults: false,      // Exclude passing results
	IncludeSuppressed:    false,      // Exclude suppressed results
	MinLevel:             sarif.LevelWarning, // Filter by minimum level
	MaxResults:           100,        // Limit number of results
}
parser := sarif.NewParser(opts)

Working with Results

Get all results:

results := sarif.GetAllResults(log)

Filter by severity level:

errors := sarif.GetResultsByLevel(log, sarif.LevelError)
warnings := sarif.GetResultsByLevel(log, sarif.LevelWarning)

Filter by rule ID:

results := sarif.GetResultsByRuleID(log, "RULE001")

Count results by level:

counts := sarif.CountByLevel(log)
fmt.Printf("Errors: %d, Warnings: %d\n", counts[sarif.LevelError], counts[sarif.LevelWarning])

Get a summary:

summary := sarif.GetSummary(log)
fmt.Printf("Total: %d results from %d runs\n", summary.TotalResults, summary.RunCount)

Converting to Findings

Extract results to a normalized Finding format:

findings := sarif.ExtractFindings(log)
for _, f := range findings {
	fmt.Printf("[%s] %s: %s at %s:%d\n",
		f.Level, f.RuleID, f.Message, f.FilePath, f.StartLine)
}

Group findings:

byFile := sarif.GroupFindingsByFile(findings)
byRule := sarif.GroupFindingsByRule(findings)
byLevel := sarif.GroupFindingsByLevel(findings)

Filter findings:

goFindings := sarif.FilterFindingsByExtension(findings, ".go")
srcFindings := sarif.FilterFindingsByPath(findings, "src/")

Deduplicate findings:

unique := sarif.DeduplicateFindings(findings)

Merging Multiple SARIF Logs

Combine results from multiple tools:

merged := sarif.MergeLogs(log1, log2, log3)

Severity Levels

SARIF defines four severity levels:

sarif.LevelError   - High severity, should be fixed
sarif.LevelWarning - Medium severity, should be reviewed
sarif.LevelNote    - Low severity, informational
sarif.LevelNone    - No severity specified

Convert between levels and numeric severity:

severity := sarif.LevelToSeverity(sarif.LevelError) // Returns 8.0
level := sarif.SeverityToLevel(5.0)                 // Returns LevelWarning

Result Kinds

SARIF results can have different kinds:

sarif.KindFail          - A defect was found
sarif.KindPass          - The check passed
sarif.KindNotApplicable - The rule was not applicable
sarif.KindOpen          - Review needed
sarif.KindReview        - Manual review needed
sarif.KindInformational - Informational only

Supported Tools

This parser works with SARIF output from various static analysis tools including:

  • CodeQL (GitHub)
  • Semgrep
  • ESLint (with SARIF reporter)
  • Trivy
  • Bandit
  • Checkov
  • KICS
  • Tfsec
  • And many more tools that support SARIF 2.1.0 output

Thread Safety

The Parser is safe for concurrent use. Each Parse* method creates independent result objects. However, the returned Log objects are not thread-safe and should not be modified concurrently.

Performance Considerations

For large SARIF files:

  • Use MaxResults option to limit results if you only need a subset
  • Use MinLevel to filter out low-severity results early
  • Consider streaming parsing for very large files (not yet implemented)

Error Handling

The parser returns specific errors for common issues:

sarif.ErrInvalidSARIF      - The input is not valid JSON or SARIF
sarif.ErrUnsupportedVersion - The SARIF version is not supported
sarif.ErrEmptyRuns         - The SARIF log contains no runs

Package sarif provides types and parser for SARIF (Static Analysis Results Interchange Format) v2.1.0. SARIF is an OASIS standard for representing static analysis results. Specification: https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSARIF       = errors.New("invalid SARIF format")
	ErrUnsupportedVersion = errors.New("unsupported SARIF version")
	ErrEmptyRuns          = errors.New("SARIF log contains no runs")
	ErrEmptyResults       = errors.New("run contains no results")
)

Parser errors.

View Source
var SupportedVersions = []string{"2.1.0"}

SupportedVersions contains the supported SARIF versions.

Functions

func CountByLevel

func CountByLevel(log *Log) map[Level]int

CountByLevel returns a map of result counts by severity level.

func GetAffectedFiles

func GetAffectedFiles(findings []Finding) []string

GetAffectedFiles returns a list of unique file paths from findings.

func GetResultLocation

func GetResultLocation(result *Result) string

GetResultLocation returns a formatted location string for a result. Format: "file.go:10:5" or "file.go:10-15:5" for multi-line results.

func GetUniqueRules

func GetUniqueRules(findings []Finding) []string

GetUniqueRules returns a list of unique rule IDs from findings.

func GroupFindingsByFile

func GroupFindingsByFile(findings []Finding) map[string][]Finding

GroupFindingsByFile groups findings by file path.

func GroupFindingsByLevel

func GroupFindingsByLevel(findings []Finding) map[Level][]Finding

GroupFindingsByLevel groups findings by severity level.

func GroupFindingsByRule

func GroupFindingsByRule(findings []Finding) map[string][]Finding

GroupFindingsByRule groups findings by rule ID.

func LevelToSeverity

func LevelToSeverity(level Level) float64

LevelToSeverity converts SARIF level to a numeric severity (0-10 scale).

Types

type Artifact

type Artifact struct {
	Location            *ArtifactLocation `json:"location,omitempty"`
	ParentIndex         int               `json:"parentIndex,omitempty"`
	Offset              int               `json:"offset,omitempty"`
	Length              int               `json:"length,omitempty"`
	Roles               []ArtifactRole    `json:"roles,omitempty"`
	MimeType            string            `json:"mimeType,omitempty"`
	Contents            *ArtifactContent  `json:"contents,omitempty"`
	Encoding            string            `json:"encoding,omitempty"`
	SourceLanguage      string            `json:"sourceLanguage,omitempty"`
	Hashes              map[string]string `json:"hashes,omitempty"`
	LastModifiedTimeUTC string            `json:"lastModifiedTimeUtc,omitempty"`
	Description         *Message          `json:"description,omitempty"`
	Properties          Properties        `json:"properties,omitempty"`
}

Artifact describes an artifact that was analyzed.

type ArtifactChange

type ArtifactChange struct {
	ArtifactLocation ArtifactLocation `json:"artifactLocation"`
	Replacements     []Replacement    `json:"replacements"`
	Properties       Properties       `json:"properties,omitempty"`
}

ArtifactChange represents changes to a single artifact.

type ArtifactContent

type ArtifactContent struct {
	Text       string                    `json:"text,omitempty"`
	Binary     string                    `json:"binary,omitempty"`
	Rendered   *MultiformatMessageString `json:"rendered,omitempty"`
	Properties Properties                `json:"properties,omitempty"`
}

ArtifactContent represents the content of an artifact.

type ArtifactLocation

type ArtifactLocation struct {
	URI         string     `json:"uri,omitempty"`
	URIBaseID   string     `json:"uriBaseId,omitempty"`
	Index       int        `json:"index,omitempty"`
	Description *Message   `json:"description,omitempty"`
	Properties  Properties `json:"properties,omitempty"`
}

ArtifactLocation represents the location of an artifact.

type ArtifactRole

type ArtifactRole string

ArtifactRole represents the role of an artifact.

const (
	ArtifactRoleAnalysisTarget             ArtifactRole = "analysisTarget"
	ArtifactRoleAttachment                 ArtifactRole = "attachment"
	ArtifactRoleResponseFile               ArtifactRole = "responseFile"
	ArtifactRoleResultFile                 ArtifactRole = "resultFile"
	ArtifactRoleStandardStream             ArtifactRole = "standardStream"
	ArtifactRoleTracedFile                 ArtifactRole = "tracedFile"
	ArtifactRoleUnmodified                 ArtifactRole = "unmodified"
	ArtifactRoleModified                   ArtifactRole = "modified"
	ArtifactRoleAdded                      ArtifactRole = "added"
	ArtifactRoleDeleted                    ArtifactRole = "deleted"
	ArtifactRoleRenamed                    ArtifactRole = "renamed"
	ArtifactRoleUncontrolled               ArtifactRole = "uncontrolled"
	ArtifactRoleDriver                     ArtifactRole = "driver"
	ArtifactRoleExtension                  ArtifactRole = "extension"
	ArtifactRoleTranslation                ArtifactRole = "translation"
	ArtifactRoleTaxonomy                   ArtifactRole = "taxonomy"
	ArtifactRolePolicy                     ArtifactRole = "policy"
	ArtifactRoleReferencedOnCommandLine    ArtifactRole = "referencedOnCommandLine"
	ArtifactRoleMemoryContents             ArtifactRole = "memoryContents"
	ArtifactRoleDirectory                  ArtifactRole = "directory"
	ArtifactRoleUserSpecifiedConfiguration ArtifactRole = "userSpecifiedConfiguration"
	ArtifactRoleToolSpecifiedConfiguration ArtifactRole = "toolSpecifiedConfiguration"
	ArtifactRoleDebugOutputFile            ArtifactRole = "debugOutputFile"
)

type BaselineState

type BaselineState string

BaselineState represents the baseline state of a result.

const (
	BaselineStateNew       BaselineState = "new"
	BaselineStateUnchanged BaselineState = "unchanged"
	BaselineStateUpdated   BaselineState = "updated"
	BaselineStateAbsent    BaselineState = "absent"
)

type CodeFlow

type CodeFlow struct {
	Message     *Message     `json:"message,omitempty"`
	ThreadFlows []ThreadFlow `json:"threadFlows"`
	Properties  Properties   `json:"properties,omitempty"`
}

CodeFlow describes the execution path that leads to a result.

type Exception

type Exception struct {
	Kind            string      `json:"kind,omitempty"`
	Message         string      `json:"message,omitempty"`
	Stack           *Stack      `json:"stack,omitempty"`
	InnerExceptions []Exception `json:"innerExceptions,omitempty"`
	Properties      Properties  `json:"properties,omitempty"`
}

Exception describes a runtime exception encountered during analysis.

type Finding

type Finding struct {
	// ID is a unique identifier for this finding.
	ID string `json:"id,omitempty"`

	// RuleID is the rule that triggered this finding.
	RuleID string `json:"ruleId"`

	// RuleName is the human-readable name of the rule.
	RuleName string `json:"ruleName,omitempty"`

	// Level is the severity level (error, warning, note, none).
	Level Level `json:"level"`

	// Message is the finding message.
	Message string `json:"message"`

	// Description is a longer description from the rule.
	Description string `json:"description,omitempty"`

	// FilePath is the file where the finding was detected.
	FilePath string `json:"filePath,omitempty"`

	// StartLine is the starting line number (1-based).
	StartLine int `json:"startLine,omitempty"`

	// EndLine is the ending line number (1-based).
	EndLine int `json:"endLine,omitempty"`

	// StartColumn is the starting column number (1-based).
	StartColumn int `json:"startColumn,omitempty"`

	// EndColumn is the ending column number (1-based).
	EndColumn int `json:"endColumn,omitempty"`

	// Snippet is the code snippet where the finding was detected.
	Snippet string `json:"snippet,omitempty"`

	// ToolName is the name of the tool that produced this finding.
	ToolName string `json:"toolName"`

	// ToolVersion is the version of the tool.
	ToolVersion string `json:"toolVersion,omitempty"`

	// HelpURI is a URL for more information about the rule.
	HelpURI string `json:"helpUri,omitempty"`

	// Fingerprint is a unique fingerprint for deduplication.
	Fingerprint string `json:"fingerprint,omitempty"`

	// IsSuppressed indicates if this finding is suppressed.
	IsSuppressed bool `json:"isSuppressed,omitempty"`

	// Properties contains additional custom properties.
	Properties Properties `json:"properties,omitempty"`
}

Finding represents a simplified finding extracted from SARIF results. This is useful for converting SARIF data to a normalized format.

func DeduplicateFindings

func DeduplicateFindings(findings []Finding) []Finding

DeduplicateFindings removes duplicate findings based on fingerprint.

func ExtractFindings

func ExtractFindings(log *Log) []Finding

ExtractFindings converts SARIF results to a normalized Finding format.

func FilterFindingsByExtension

func FilterFindingsByExtension(findings []Finding, extensions ...string) []Finding

FilterFindingsByExtension filters findings by file extension.

func FilterFindingsByPath

func FilterFindingsByPath(findings []Finding, pathPrefix string) []Finding

FilterFindingsByPath filters findings by path prefix.

type Fix

type Fix struct {
	Description     *Message         `json:"description,omitempty"`
	ArtifactChanges []ArtifactChange `json:"artifactChanges"`
	Properties      Properties       `json:"properties,omitempty"`
}

Fix represents a proposed fix for a result.

type Importance

type Importance string

Importance represents the importance of a thread flow location.

const (
	ImportanceImportant   Importance = "important"
	ImportanceEssential   Importance = "essential"
	ImportanceUnimportant Importance = "unimportant"
)

type Invocation

type Invocation struct {
	CommandLine                    string             `json:"commandLine,omitempty"`
	Arguments                      []string           `json:"arguments,omitempty"`
	ResponseFiles                  []ArtifactLocation `json:"responseFiles,omitempty"`
	StartTimeUTC                   string             `json:"startTimeUtc,omitempty"`
	EndTimeUTC                     string             `json:"endTimeUtc,omitempty"`
	ExecutionSuccessful            bool               `json:"executionSuccessful"`
	Machine                        string             `json:"machine,omitempty"`
	Account                        string             `json:"account,omitempty"`
	ProcessID                      int                `json:"processId,omitempty"`
	WorkingDirectory               *ArtifactLocation  `json:"workingDirectory,omitempty"`
	EnvironmentVariables           map[string]string  `json:"environmentVariables,omitempty"`
	ToolExecutionNotifications     []Notification     `json:"toolExecutionNotifications,omitempty"`
	ToolConfigurationNotifications []Notification     `json:"toolConfigurationNotifications,omitempty"`
	ExitCode                       int                `json:"exitCode,omitempty"`
	ExitCodeDescription            string             `json:"exitCodeDescription,omitempty"`
	ExitSignalName                 string             `json:"exitSignalName,omitempty"`
	ExitSignalNumber               int                `json:"exitSignalNumber,omitempty"`
	ProcessStartFailureMessage     string             `json:"processStartFailureMessage,omitempty"`
	StdIn                          *ArtifactLocation  `json:"stdin,omitempty"`
	StdOut                         *ArtifactLocation  `json:"stdout,omitempty"`
	StdErr                         *ArtifactLocation  `json:"stderr,omitempty"`
	Properties                     Properties         `json:"properties,omitempty"`
}

Invocation describes a single invocation of an analysis tool.

type Kind

type Kind string

Kind represents the kind of a result.

const (
	KindNotApplicable Kind = "notApplicable"
	KindPass          Kind = "pass"
	KindFail          Kind = "fail"
	KindReview        Kind = "review"
	KindOpen          Kind = "open"
	KindInformational Kind = "informational"
)

func (Kind) IsValid

func (k Kind) IsValid() bool

IsValid checks if the kind is valid.

type Level

type Level string

Level represents the severity level of a result.

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

func SeverityToLevel

func SeverityToLevel(severity float64) Level

SeverityToLevel converts a numeric severity to SARIF level.

func (Level) IsValid

func (l Level) IsValid() bool

IsValid checks if the level is valid.

type Location

type Location struct {
	ID               int               `json:"id,omitempty"`
	PhysicalLocation *PhysicalLocation `json:"physicalLocation,omitempty"`
	LogicalLocations []LogicalLocation `json:"logicalLocations,omitempty"`
	Message          *Message          `json:"message,omitempty"`
	Properties       Properties        `json:"properties,omitempty"`
}

Location represents a location in an artifact.

type Log

type Log struct {
	Version string `json:"version"`
	Schema  string `json:"$schema,omitempty"`
	Runs    []Run  `json:"runs"`
}

Log represents the root SARIF log object.

func MergeLogs

func MergeLogs(logs ...*Log) *Log

MergeLogs merges multiple SARIF logs into a single log.

type LogicalLocation

type LogicalLocation struct {
	Name               string     `json:"name,omitempty"`
	Index              int        `json:"index,omitempty"`
	FullyQualifiedName string     `json:"fullyQualifiedName,omitempty"`
	DecoratedName      string     `json:"decoratedName,omitempty"`
	ParentIndex        int        `json:"parentIndex,omitempty"`
	Kind               string     `json:"kind,omitempty"`
	Properties         Properties `json:"properties,omitempty"`
}

LogicalLocation represents a logical location (e.g., function, class).

type Message

type Message struct {
	Text       string     `json:"text,omitempty"`
	Markdown   string     `json:"markdown,omitempty"`
	ID         string     `json:"id,omitempty"`
	Arguments  []string   `json:"arguments,omitempty"`
	Properties Properties `json:"properties,omitempty"`
}

Message represents a message to the user.

type MultiformatMessageString

type MultiformatMessageString struct {
	Text       string     `json:"text"`
	Markdown   string     `json:"markdown,omitempty"`
	Properties Properties `json:"properties,omitempty"`
}

MultiformatMessageString represents a message in multiple formats.

type Notification

type Notification struct {
	Message        Message                       `json:"message"`
	Level          Level                         `json:"level,omitempty"`
	Locations      []Location                    `json:"locations,omitempty"`
	TimeUTC        string                        `json:"timeUtc,omitempty"`
	Exception      *Exception                    `json:"exception,omitempty"`
	Descriptor     *ReportingDescriptorReference `json:"descriptor,omitempty"`
	AssociatedRule *ReportingDescriptorReference `json:"associatedRule,omitempty"`
	Properties     Properties                    `json:"properties,omitempty"`
}

Notification represents a notification produced during the run.

type Options

type Options struct {
	// StrictMode enables strict validation of SARIF documents.
	StrictMode bool

	// IncludePassedResults includes results with kind "pass" (default: false).
	IncludePassedResults bool

	// MinLevel filters results by minimum severity level.
	// Results with severity below this level are excluded.
	// Valid values: "", "none", "note", "warning", "error"
	MinLevel Level

	// MaxResults limits the number of results returned (0 = unlimited).
	MaxResults int

	// IncludeSuppressed includes suppressed results (default: false).
	IncludeSuppressed bool
}

Options configures the parser behavior.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default parser options.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses SARIF format files.

func NewParser

func NewParser(opts *Options) *Parser

NewParser creates a new SARIF parser with the given options. If opts is nil, default options are used.

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader) (*Log, error)

Parse parses SARIF content from a reader.

func (*Parser) ParseBytes

func (p *Parser) ParseBytes(data []byte) (*Log, error)

ParseBytes parses SARIF content from bytes.

func (*Parser) ParseFile

func (p *Parser) ParseFile(path string) (*Log, error)

ParseFile parses a SARIF file from the given path.

type PhysicalLocation

type PhysicalLocation struct {
	ArtifactLocation *ArtifactLocation `json:"artifactLocation,omitempty"`
	Region           *Region           `json:"region,omitempty"`
	ContextRegion    *Region           `json:"contextRegion,omitempty"`
	Properties       Properties        `json:"properties,omitempty"`
}

PhysicalLocation represents a physical location in an artifact.

type Properties

type Properties map[string]any

Properties is a property bag for custom properties.

type Region

type Region struct {
	StartLine      int              `json:"startLine,omitempty"`
	StartColumn    int              `json:"startColumn,omitempty"`
	EndLine        int              `json:"endLine,omitempty"`
	EndColumn      int              `json:"endColumn,omitempty"`
	CharOffset     int              `json:"charOffset,omitempty"`
	CharLength     int              `json:"charLength,omitempty"`
	ByteOffset     int              `json:"byteOffset,omitempty"`
	ByteLength     int              `json:"byteLength,omitempty"`
	Snippet        *ArtifactContent `json:"snippet,omitempty"`
	Message        *Message         `json:"message,omitempty"`
	SourceLanguage string           `json:"sourceLanguage,omitempty"`
	Properties     Properties       `json:"properties,omitempty"`
}

Region represents a region within an artifact.

type Replacement

type Replacement struct {
	DeletedRegion   Region           `json:"deletedRegion"`
	InsertedContent *ArtifactContent `json:"insertedContent,omitempty"`
	Properties      Properties       `json:"properties,omitempty"`
}

Replacement represents a replacement of content in an artifact.

type ReportingConfiguration

type ReportingConfiguration struct {
	Enabled    bool       `json:"enabled,omitempty"`
	Level      Level      `json:"level,omitempty"`
	Rank       float64    `json:"rank,omitempty"`
	Parameters Properties `json:"parameters,omitempty"`
}

ReportingConfiguration specifies the default configuration for a rule.

type ReportingDescriptor

type ReportingDescriptor struct {
	ID                   string                    `json:"id"`
	Name                 string                    `json:"name,omitempty"`
	ShortDescription     *MultiformatMessageString `json:"shortDescription,omitempty"`
	FullDescription      *MultiformatMessageString `json:"fullDescription,omitempty"`
	Help                 *MultiformatMessageString `json:"help,omitempty"`
	HelpURI              string                    `json:"helpUri,omitempty"`
	DefaultConfiguration *ReportingConfiguration   `json:"defaultConfiguration,omitempty"`
	Properties           Properties                `json:"properties,omitempty"`
}

ReportingDescriptor describes a rule or notification produced by a tool.

func GetRuleDescriptor

func GetRuleDescriptor(run *Run, result *Result) *ReportingDescriptor

GetRuleDescriptor finds the rule descriptor for a result.

type ReportingDescriptorReference

type ReportingDescriptorReference struct {
	ID            string                  `json:"id,omitempty"`
	Index         int                     `json:"index,omitempty"`
	GUID          string                  `json:"guid,omitempty"`
	ToolComponent *ToolComponentReference `json:"toolComponent,omitempty"`
}

ReportingDescriptorReference identifies a rule by ID or index.

type Result

type Result struct {
	RuleID              string                        `json:"ruleId,omitempty"`
	RuleIndex           int                           `json:"ruleIndex,omitempty"`
	Rule                *ReportingDescriptorReference `json:"rule,omitempty"`
	Kind                Kind                          `json:"kind,omitempty"`
	Level               Level                         `json:"level,omitempty"`
	Message             Message                       `json:"message"`
	Locations           []Location                    `json:"locations,omitempty"`
	RelatedLocations    []Location                    `json:"relatedLocations,omitempty"`
	CodeFlows           []CodeFlow                    `json:"codeFlows,omitempty"`
	Fixes               []Fix                         `json:"fixes,omitempty"`
	Fingerprints        map[string]string             `json:"fingerprints,omitempty"`
	PartialFingerprints map[string]string             `json:"partialFingerprints,omitempty"`
	Properties          Properties                    `json:"properties,omitempty"`
	Suppressions        []Suppression                 `json:"suppressions,omitempty"`
	BaselineState       BaselineState                 `json:"baselineState,omitempty"`
	Rank                float64                       `json:"rank,omitempty"`
	HostedViewerURI     string                        `json:"hostedViewerUri,omitempty"`
	GUID                string                        `json:"guid,omitempty"`
	CorrelationGUID     string                        `json:"correlationGuid,omitempty"`
	OccurrenceCount     int                           `json:"occurrenceCount,omitempty"`
}

Result represents a single result from the analysis.

func GetAllResults

func GetAllResults(log *Log) []Result

GetAllResults returns all results from all runs in the log.

func GetResultsByLevel

func GetResultsByLevel(log *Log, level Level) []Result

GetResultsByLevel returns results filtered by severity level.

func GetResultsByRuleID

func GetResultsByRuleID(log *Log, ruleID string) []Result

GetResultsByRuleID returns results filtered by rule ID.

type Run

type Run struct {
	Tool        Tool         `json:"tool"`
	Results     []Result     `json:"results,omitempty"`
	Invocations []Invocation `json:"invocations,omitempty"`
	Artifacts   []Artifact   `json:"artifacts,omitempty"`
	Properties  Properties   `json:"properties,omitempty"`
}

Run represents a single run of an analysis tool.

type Stack

type Stack struct {
	Message    *Message     `json:"message,omitempty"`
	Frames     []StackFrame `json:"frames"`
	Properties Properties   `json:"properties,omitempty"`
}

Stack represents a call stack.

type StackFrame

type StackFrame struct {
	Location   *Location  `json:"location,omitempty"`
	Module     string     `json:"module,omitempty"`
	ThreadID   int        `json:"threadId,omitempty"`
	Parameters []string   `json:"parameters,omitempty"`
	Properties Properties `json:"properties,omitempty"`
}

StackFrame represents a single frame in a call stack.

type Stats

type Stats struct {
	Total           int           `json:"total"`
	ByLevel         map[Level]int `json:"byLevel"`
	UniqueFiles     int           `json:"uniqueFiles"`
	UniqueRules     int           `json:"uniqueRules"`
	SuppressedCount int           `json:"suppressedCount"`
}

Stats contains statistics about findings.

func CalculateStats

func CalculateStats(findings []Finding) Stats

CalculateStats calculates statistics from findings.

type Summary

type Summary struct {
	TotalResults int           `json:"totalResults"`
	ByLevel      map[Level]int `json:"byLevel"`
	ByKind       map[Kind]int  `json:"byKind"`
	Tools        []string      `json:"tools"`
	RunCount     int           `json:"runCount"`
}

Summary contains summarized statistics from a SARIF log.

func GetSummary

func GetSummary(log *Log) Summary

GetSummary returns a summary of the SARIF log.

type Suppression

type Suppression struct {
	Kind          SuppressionKind   `json:"kind"`
	Status        SuppressionStatus `json:"status,omitempty"`
	Location      *Location         `json:"location,omitempty"`
	GUID          string            `json:"guid,omitempty"`
	Justification string            `json:"justification,omitempty"`
	Properties    Properties        `json:"properties,omitempty"`
}

Suppression represents a suppression of a result.

type SuppressionKind

type SuppressionKind string

SuppressionKind represents the kind of suppression.

const (
	SuppressionKindInSource SuppressionKind = "inSource"
	SuppressionKindExternal SuppressionKind = "external"
)

type SuppressionStatus

type SuppressionStatus string

SuppressionStatus represents the status of a suppression.

const (
	SuppressionStatusAccepted    SuppressionStatus = "accepted"
	SuppressionStatusUnderReview SuppressionStatus = "underReview"
	SuppressionStatusRejected    SuppressionStatus = "rejected"
)

type ThreadFlow

type ThreadFlow struct {
	ID         string               `json:"id,omitempty"`
	Message    *Message             `json:"message,omitempty"`
	Locations  []ThreadFlowLocation `json:"locations"`
	Properties Properties           `json:"properties,omitempty"`
}

ThreadFlow represents a sequence of code locations in a single thread.

type ThreadFlowLocation

type ThreadFlowLocation struct {
	Index            int        `json:"index,omitempty"`
	Location         *Location  `json:"location,omitempty"`
	State            Properties `json:"state,omitempty"`
	NestingLevel     int        `json:"nestingLevel,omitempty"`
	ExecutionOrder   int        `json:"executionOrder,omitempty"`
	ExecutionTimeUTC string     `json:"executionTimeUtc,omitempty"`
	Importance       Importance `json:"importance,omitempty"`
	Properties       Properties `json:"properties,omitempty"`
}

ThreadFlowLocation represents a location in a thread flow.

type Tool

type Tool struct {
	Driver     ToolComponent   `json:"driver"`
	Extensions []ToolComponent `json:"extensions,omitempty"`
}

Tool describes the analysis tool that produced the results.

type ToolComponent

type ToolComponent struct {
	Name             string                    `json:"name"`
	Version          string                    `json:"version,omitempty"`
	SemanticVersion  string                    `json:"semanticVersion,omitempty"`
	InformationURI   string                    `json:"informationUri,omitempty"`
	Rules            []ReportingDescriptor     `json:"rules,omitempty"`
	Notifications    []ReportingDescriptor     `json:"notifications,omitempty"`
	Properties       Properties                `json:"properties,omitempty"`
	GUID             string                    `json:"guid,omitempty"`
	Organization     string                    `json:"organization,omitempty"`
	Product          string                    `json:"product,omitempty"`
	FullName         string                    `json:"fullName,omitempty"`
	ShortDescription *MultiformatMessageString `json:"shortDescription,omitempty"`
	FullDescription  *MultiformatMessageString `json:"fullDescription,omitempty"`
}

ToolComponent represents a component of an analysis tool (driver or extension).

type ToolComponentReference

type ToolComponentReference struct {
	Name  string `json:"name,omitempty"`
	Index int    `json:"index,omitempty"`
	GUID  string `json:"guid,omitempty"`
}

ToolComponentReference identifies a tool component.

Jump to

Keyboard shortcuts

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