src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

vex.go (4529B)


      1 // Copyright 2024 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // Package vex defines the Vulnerability EXchange Format (VEX) types
      6 // supported by govulncheck.
      7 //
      8 // These types match the OpenVEX standard. See https://github.com/openvex for
      9 // more information on VEX and OpenVEX.
     10 //
     11 // This is intended to be the minimimal amount of information required to output
     12 // a complete VEX document according to the specification.
     13 package openvex
     14 
     15 import "time"
     16 
     17 const (
     18 	ContextURI = "https://openvex.dev/ns/v0.2.0"
     19 	Tooling    = "https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck"
     20 	Impact     = "Govulncheck determined that the vulnerable code isn't called"
     21 
     22 	DefaultAuthor = "Unknown Author"
     23 	DefaultPID    = "Unknown Product"
     24 
     25 	// The following are defined by the VEX standard.
     26 	StatusAffected    = "affected"
     27 	StatusNotAffected = "not_affected"
     28 
     29 	// The following are defined by the VEX standard.
     30 	JustificationNotExecuted = "vulnerable_code_not_in_execute_path"
     31 	JustificationNotPresent  = "vulnerable_code_not_present"
     32 )
     33 
     34 // Document is the top-level struct for a VEX document.
     35 type Document struct {
     36 	// Context is an IRI pointing to the version of openVEX being used by the doc
     37 	// For govulncheck, it will always be https://openvex.dev/ns/v0.2.0
     38 	Context string `json:"@context,omitempty"`
     39 
     40 	// ID is the identifying string for the VEX document.
     41 	// govulncheck/vex-[content-based-hash]
     42 	ID string `json:"@id,omitempty"`
     43 
     44 	// Author is the identifier for the author of the VEX statement.
     45 	// Govulncheck will leave this field default (Unknown author) to be filled in by the user.
     46 	Author string `json:"author,omitempty"`
     47 
     48 	// Timestamp defines the time at which the document was issued.
     49 	Timestamp time.Time `json:"timestamp,omitempty"`
     50 
     51 	// Version is the document version. For govulncheck's output, this will always be 1.
     52 	Version int `json:"version,omitempty"`
     53 
     54 	// Tooling expresses how the VEX document and contained VEX statements were
     55 	// generated. In this case, it will always be:
     56 	// "https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck"
     57 	Tooling string `json:"tooling,omitempty"`
     58 
     59 	// Statements are all statements for a given govulncheck output.
     60 	// Each OSV emitted by govulncheck will have a corresponding statement.
     61 	Statements []Statement `json:"statements,omitempty"`
     62 }
     63 
     64 // Statement conveys a single status for a single vulnerability for one or more products.
     65 type Statement struct {
     66 	// Vulnerability is the vuln being referenced by the statement.
     67 	Vulnerability Vulnerability `json:"vulnerability,omitempty"`
     68 
     69 	// Products are the products associated with the given vulnerability in the statement.
     70 	Products []Product `json:"products,omitempty"`
     71 
     72 	// The status of the vulnerability. Will be either not_affected or affected for govulncheck.
     73 	Status string `json:"status,omitempty"`
     74 
     75 	// If the status is not_affected, this must be filled. The official VEX justification that
     76 	// best matches govulncheck's vuln filtering is "vulnerable_code_not_in_execute_path"
     77 	Justification string `json:"justification,omitempty"`
     78 
     79 	// If the status is not_affected, this must be filled. For govulncheck, this will always be:
     80 	// "Govulncheck determined that the vulnerable code isn't called"
     81 	ImpactStatement string `json:"impact_statement,omitempty"`
     82 }
     83 
     84 // Vulnerability captures a vulnerability and its identifiers/aliases.
     85 type Vulnerability struct {
     86 	// ID is a URI that in govulncheck's case points to the govulndb link for the vulnerability.
     87 	// I.E. https://pkg.go.dev/vuln/GO-2024-2497
     88 	ID string `json:"@id,omitempty"`
     89 
     90 	// Name is the main identifier for the vulnerability (GO-YYYY-XXXX)
     91 	Name string `json:"name,omitempty"`
     92 
     93 	// Description is a short text description of the vulnerability.
     94 	// It will be populated from the 'summary' field of the vuln's OSV if it exists,
     95 	// and the 'description' field of the osv if a summary isn't present.
     96 	Description string `json:"description,omitempty"`
     97 
     98 	// Aliases a list of identifiers that other systems are using to track the vulnerability.
     99 	// I.E. GHSA or CVE ids.
    100 	Aliases []string `json:"aliases,omitempty"`
    101 }
    102 
    103 // Product identifies the products associated with the given vuln.
    104 type Product struct {
    105 	// The main product ID will remian default for now.
    106 	Component
    107 	// The subcomponent ID will be a PURL to the vulnerable dependency.
    108 	Subcomponents []Component `json:"subcomponents,omitempty"`
    109 }
    110 
    111 type Component struct {
    112 	ID string `json:"@id,omitempty"`
    113 }