cvss

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cvss implements v2.0, v3.0, v3.1, and v4.0 CVSS vectors and scoring.

The primary purpose of this package is to parse CVSS vectors then use the parsed representation to calculate the numerical score and produce the canonicalized representation of the vector.

CVSS v2.0

Metrics and scoring is implemented as laid out in the v2.0 specification.

CVSS v3.0

Metrics and scoring is implemented as laid out in the v3.0 specification.

CVSS v3.1

Metrics and scoring is implemented as laid out in the v3.1 specification.

CVSS v4.0

Metrics and scoring is implemented as laid out in the v4.0 specification. The ordering emitted is as specified in revision 1.1, not 1.0.

The v4 scoring system is very complicated and under-specified. This package's implementation is built to mirror the Javascript implementation where ever the specification is unclear.

There are outstanding issues in the specification as of 2024-01-02; see the "Bugs" section of this documentation for details.

Index

Constants

View Source
const ValueInvalid = Value(255)

ValueInvalid is reported when the packed representation in a Vector is invalid.

View Source
const ValueUnset = Value(0)

ValueUnset is reported when the packed representation in a Vector is not set.

Methods returning values may translate this into a specification-defined Unset/Not Defined/Undefined Value.

Variables

View Source
var ErrMalformedVector = errors.New("malformed vector")

ErrMalformedVector is reported when a vector is invalid in some way.

Functions

func UnparseV2Value

func UnparseV2Value(m V2Metric, v Value) string

UnparseV2Value unpacks the Value v into the specification's abbreviation.

Invalid values are returned as-is.

func Version

func Version(vec string) (v int)

Version guesses at the version of a vector string.

Types

type Metric

type Metric interface {
	~int
	fmt.Stringer
	// contains filtered or unexported methods
}

Metric is a CVSS metric.

The set of types this describes is namespaced per-version.

type Qualitative

type Qualitative int

Qualitative is the "Qualitative Severity" of a Vector.

const (
	None Qualitative
	Low
	Medium
	High
	Critical
)

The specified qualitative severities.

func QualitativeScore

func QualitativeScore[M Metric, V Vector[M]](v V) (q Qualitative)

QualitativeScore returns the qualitative severity of the provided Vector "v".

There is no defined mapping for v2. The mapping defined for the other versions is used.

func (Qualitative) String

func (i Qualitative) String() string

type V2

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

V2 is a CVSS version 2 score.

func ParseV2

func ParseV2(s string) (v V2, err error)

ParseV2 parses the provided string as a v2 vector.

func (*V2) Environmental

func (v *V2) Environmental() (ok bool)

Environmental reports if the vector has "Environmental" metrics.

func (*V2) Get

func (v *V2) Get(m V2Metric) Value

Get implements Vector.

func (*V2) MarshalText

func (v *V2) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (*V2) Score

func (v *V2) Score() float64

Score implements Vector.

The reported score is always an "Environmental" score.

func (*V2) String

func (v *V2) String() string

String implements fmt.Stringer.

Calling this method on an invalid instance results in an invalid vector string.

func (*V2) Temporal

func (v *V2) Temporal() (ok bool)

Temporal reports if the vector has "Temporal" metrics.

func (*V2) UnmarshalText

func (v *V2) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type V2Metric

type V2Metric int

V2Metric is a metric in a v2 vector.

const (
	V2AccessVector               V2Metric = iota // AV
	V2AccessComplexity                           // AC
	V2Authentication                             // Au
	V2Confidentiality                            // C
	V2Integrity                                  // I
	V2Availability                               // A
	V2Exploitability                             // E
	V2RemediationLevel                           // RL
	V2ReportConfidence                           // RC
	V2CollateralDamagePotential                  // CDP
	V2TargetDistribution                         // TD
	V2ConfidentialityRequirement                 // CR
	V2IntegrityRequirement                       // IR
	V2AvailabilityRequirement                    // AR

)

These are the metrics defined in the specification.

func (V2Metric) String

func (i V2Metric) String() string

type V3

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

V3 is a CVSS version 3 score.

func ParseV3

func ParseV3(s string) (v V3, err error)

ParseV3 parses the provided string as a v3 vector.

func (*V3) Environmental

func (v *V3) Environmental() (ok bool)

Environmental reports if the vector has "Environmental" metrics.

func (*V3) Get

func (v *V3) Get(m V3Metric) Value

Get implements Vector.

func (*V3) MarshalText

func (v *V3) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (*V3) Score

func (v *V3) Score() float64

Score implements Vector.

The reported score is always a "Temporal" score, and uses the "Environmental" equations when Environmental metrics are present.

func (*V3) String

func (v *V3) String() string

String implements fmt.Stringer.

Calling this method on an invalid instance results in an invalid vector string.

func (*V3) Temporal

func (v *V3) Temporal() bool

Temporal reports if the vector has "Temporal" metrics.

func (*V3) UnmarshalText

func (v *V3) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type V3Metric

type V3Metric int

V3Metric is a metric in a v3 vector.

const (
	V3AttackVector               V3Metric = iota // AV
	V3AttackComplexity                           // AC
	V3PrivilegesRequired                         // PR
	V3UserInteraction                            // UI
	V3Scope                                      // S
	V3Confidentiality                            // C
	V3Integrity                                  // I
	V3Availability                               // A
	V3ExploitMaturity                            // E
	V3RemediationLevel                           // RL
	V3ReportConfidence                           // RC
	V3ConfidentialityRequirement                 // CR
	V3IntegrityRequirement                       // IR
	V3AvailabilityRequirement                    // AR
	V3ModifiedAttackVector                       // MAV
	V3ModifiedAttackComplexity                   // MAC
	V3ModifiedPrivilegesRequired                 // MPR
	V3ModifiedUserInteraction                    // MUI
	V3ModifiedScope                              // MS
	V3ModifiedConfidentiality                    // MC
	V3ModifiedIntegrity                          // MI
	V3ModifiedAvailability                       // MA

)

These are the metrics defined in the specification.

func (V3Metric) String

func (i V3Metric) String() string

type V4

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

V4 is a CVSS version 4 score.

func ParseV4

func ParseV4(s string) (v V4, err error)

ParseV4 parses the provided string as a v4 vector.

func (*V4) Environmental

func (v *V4) Environmental() (ok bool)

Environmental reports if the vector has "Environmental" metrics.

func (*V4) Get

func (v *V4) Get(m V4Metric) Value

Get implements Vector.

func (*V4) MarshalText

func (v *V4) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (*V4) Score

func (v *V4) Score() float64

Score implements Vector.

Unlike V2.Score and V3.Score, there's not a set of scores for a given vector, there's only one.

func (*V4) String

func (v *V4) String() string

String implements fmt.Stringer.

Calling this method on an invalid instance results in an invalid vector string.

func (*V4) Supplemental

func (v *V4) Supplemental() (ok bool)

Supplemental reports if the vector has "Supplemental" metrics.

func (*V4) Threat

func (v *V4) Threat() bool

Threat reports if the vector has "Threat" metrics.

func (*V4) UnmarshalText

func (v *V4) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type V4Metric

type V4Metric int

V4Metric is a metric in a v4 vector.

const (
	V4AttackVector                            V4Metric = iota // AV
	V4AttackComplexity                                        // AC
	V4AttackRequirements                                      // AT
	V4PrivilegesRequired                                      // PR
	V4UserInteraction                                         // UI
	V4VulnerableSystemConfidentiality                         // VC
	V4VulnerableSystemIntegrity                               // VI
	V4VulnerableSystemAvailability                            // VA
	V4SubsequentSystemConfidentiality                         // SC
	V4SubsequentSystemIntegrity                               // SI
	V4SubsequentSystemAvailability                            // SA
	V4ExploitMaturity                                         // E
	V4ConfidentialityRequirement                              // CR
	V4IntegrityRequirement                                    // IR
	V4AvailabilityRequirement                                 // AR
	V4ModifiedAttackVector                                    // MAV
	V4ModifiedAttackComplexity                                // MAC
	V4ModifiedAttackRequirements                              // MAT
	V4ModifiedPrivilegesRequired                              // MPR
	V4ModifiedUserInteraction                                 // MUI
	V4ModifiedVulnerableSystemConfidentiality                 // MVC
	V4ModifiedVulnerableSystemIntegrity                       // MVI
	V4ModifiedVulnerableSystemAvailability                    // MVA
	V4ModifiedSubsequentSystemConfidentiality                 // MSC
	V4ModifiedSubsequentSystemIntegrity                       // MSI
	V4ModifiedSubsequentSystemAvailability                    // MSA
	V4Safety                                                  // S
	V4Automatable                                             // AU
	V4Recovery                                                // R
	V4ValueDensity                                            // V
	V4VulnerabilityResponseEffort                             // RE
	V4ProviderUrgency                                         // U

)

These are the metrics defined in the specification.

func (V4Metric) String

func (i V4Metric) String() string

type Value

type Value byte

Value is a "packed" representation of the value of a metric.

When possible, this is the first byte of the abbreviated form in the relevant specification. This is not possible with v2 vectors, so users may need to use UnparseV2Value in that case.

func (Value) GoString

func (v Value) GoString() string

GoString implements fmt.GoStringer.

type Vector

type Vector[M Metric] interface {
	encoding.TextUnmarshaler
	encoding.TextMarshaler
	fmt.Stringer

	// Get reports the Value for the supplied Metric.
	//
	// V2 vectors require calling [UnparseV2Value] to convert the value to the
	// spec-defined abbreviation.
	Get(M) Value
	// Score reports the score for the Vector. The exact formula used depends on
	// what metrics are present.
	Score() float64
	// Environmental reports if the vector contains environmental metrics.
	Environmental() bool
	// contains filtered or unexported methods
}

Vector is a CVSS vector of any version.

Notes

Bugs

  • The spec prescribes the invalid value "Safety (S)" for the "Integrity Impact to the Subsequent System (SI)" and "Availability Impact to the Subsequent System (SA)" metrics for use in the scoring algorithm. These values are only defined for "Modified Subsequent System Integrity (MSI)" and "Modified Subsequent System Availability (MSA)" and so are not accepted for inputs.

Jump to

Keyboard shortcuts

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