severity

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Overview

Package severity provides unified severity level definitions and mappings for security findings across SDK and Backend.

IMPORTANT: This package is shared between sdk and api. Any changes must be backward compatible or coordinated across both projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Level) int

Compare returns:

-1 if a < b (a is lower severity)
 0 if a == b
+1 if a > b (a is higher severity)

Types

type CountBySeverity

type CountBySeverity struct {
	Critical int `json:"critical"`
	High     int `json:"high"`
	Medium   int `json:"medium"`
	Low      int `json:"low"`
	Info     int `json:"info"`
	Unknown  int `json:"unknown"`
	Total    int `json:"total"`
}

CountBySeverity counts findings by severity level.

func (*CountBySeverity) HighestSeverity

func (c *CountBySeverity) HighestSeverity() Level

HighestSeverity returns the highest severity level that has a non-zero count.

func (*CountBySeverity) Increment

func (c *CountBySeverity) Increment(level Level)

Increment increases the count for the given severity.

type Level

type Level string

Level represents a severity level for security findings.

const (
	// Critical - Immediate action required. Actively exploited or trivially exploitable.
	Critical Level = "critical"

	// High - Serious vulnerability that should be addressed urgently.
	High Level = "high"

	// Medium - Moderate risk, should be addressed in normal development cycle.
	Medium Level = "medium"

	// Low - Minor issue, address when convenient.
	Low Level = "low"

	// Info - Informational finding, no security impact.
	Info Level = "info"

	// Unknown - Severity could not be determined.
	Unknown Level = "unknown"
)

func AllLevels

func AllLevels() []Level

AllLevels returns all severity levels in order of priority (highest first).

func FromCVSS

func FromCVSS(score float64) Level

FromCVSS converts a CVSS score (0.0-10.0) to a severity level. Based on CVSS v3.0 severity ratings:

  • 9.0-10.0: Critical
  • 7.0-8.9: High
  • 4.0-6.9: Medium
  • 0.1-3.9: Low
  • 0.0: Info

func FromString

func FromString(s string) Level

FromString normalizes various severity string formats to a standard Level. Handles common formats from different scanners:

  • Semgrep: ERROR, WARNING, INFO
  • Trivy: CRITICAL, HIGH, MEDIUM, LOW, UNKNOWN
  • Gitleaks: (uses rule-based)
  • SARIF: error, warning, note

func Max

func Max(a, b Level) Level

Max returns the higher severity of two levels.

func Min

func Min(a, b Level) Level

Min returns the lower severity of two levels.

func (Level) IsAtLeast

func (l Level) IsAtLeast(other Level) bool

IsAtLeast returns true if this severity is at least as high as the other.

func (Level) IsHigherThan

func (l Level) IsHigherThan(other Level) bool

IsHigherThan returns true if this severity is higher than the other.

func (Level) Priority

func (l Level) Priority() int

Priority returns the numeric priority of the severity level. Higher numbers = higher priority.

func (Level) String

func (l Level) String() string

String returns the string representation of the severity level.

func (Level) ToCVSSRange

func (l Level) ToCVSSRange() (float64, float64)

ToCVSSRange returns the CVSS score range for a severity level. Returns (min, max) where min is inclusive and max is exclusive.

Jump to

Keyboard shortcuts

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