| 1 | // Copyright 2023 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 | // Code generated by copying from golang.org/x/[email protected] (go run copier.go); DO NOT EDIT. |
| 6 | |
| 7 | // Package govulncheck contains the JSON output structs for govulncheck. |
| 8 | package govulncheck |
| 9 | |
| 10 | import ( |
| 11 | "time" |
| 12 | |
| 13 | "golang.org/x/tools/gopls/internal/vulncheck/osv" |
| 14 | ) |
| 15 | |
| 16 | const ( |
| 17 | // ProtocolVersion is the current protocol version this file implements |
| 18 | ProtocolVersion = "v1.0.0" |
| 19 | ) |
| 20 | |
| 21 | // Message is an entry in the output stream. It will always have exactly one |
| 22 | // field filled in. |
| 23 | type Message struct { |
| 24 | Config *Config `json:"config,omitempty"` |
| 25 | Progress *Progress `json:"progress,omitempty"` |
| 26 | OSV *osv.Entry `json:"osv,omitempty"` |
| 27 | Finding *Finding `json:"finding,omitempty"` |
| 28 | } |
| 29 | |
| 30 | // Config must occur as the first message of a stream and informs the client |
| 31 | // about the information used to generate the findings. |
| 32 | // The only required field is the protocol version. |
| 33 | type Config struct { |
| 34 | // ProtocolVersion specifies the version of the JSON protocol. |
| 35 | ProtocolVersion string `json:"protocol_version"` |
| 36 | |
| 37 | // ScannerName is the name of the tool, for example, govulncheck. |
| 38 | // |
| 39 | // We expect this JSON format to be used by other tools that wrap |
| 40 | // govulncheck, which will have a different name. |
| 41 | ScannerName string `json:"scanner_name,omitempty"` |
| 42 | |
| 43 | // ScannerVersion is the version of the tool. |
| 44 | ScannerVersion string `json:"scanner_version,omitempty"` |
| 45 | |
| 46 | // DB is the database used by the tool, for example, |
| 47 | // vuln.go.dev. |
| 48 | DB string `json:"db,omitempty"` |
| 49 | |
| 50 | // LastModified is the last modified time of the data source. |
| 51 | DBLastModified *time.Time `json:"db_last_modified,omitempty"` |
| 52 | |
| 53 | // GoVersion is the version of Go used for analyzing standard library |
| 54 | // vulnerabilities. |
| 55 | GoVersion string `json:"go_version,omitempty"` |
| 56 | |
| 57 | // ScanLevel instructs govulncheck to analyze at a specific level of detail. |
| 58 | // Valid values include module, package and symbol. |
| 59 | ScanLevel ScanLevel `json:"scan_level,omitempty"` |
| 60 | } |
| 61 | |
| 62 | // Progress messages are informational only, intended to allow users to monitor |
| 63 | // the progress of a long running scan. |
| 64 | // A stream must remain fully valid and able to be interpreted with all progress |
| 65 | // messages removed. |
| 66 | type Progress struct { |
| 67 | // A time stamp for the message. |
| 68 | Timestamp *time.Time `json:"time,omitempty"` |
| 69 | |
| 70 | // Message is the progress message. |
| 71 | Message string `json:"message,omitempty"` |
| 72 | } |
| 73 | |
| 74 | // Vuln represents a single OSV entry. |
| 75 | type Finding struct { |
| 76 | // OSV is the id of the detected vulnerability. |
| 77 | OSV string `json:"osv,omitempty"` |
| 78 | |
| 79 | // FixedVersion is the module version where the vulnerability was |
| 80 | // fixed. This is empty if a fix is not available. |
| 81 | // |
| 82 | // If there are multiple fixed versions in the OSV report, this will |
| 83 | // be the fixed version in the latest range event for the OSV report. |
| 84 | // |
| 85 | // For example, if the range events are |
| 86 | // {introduced: 0, fixed: 1.0.0} and {introduced: 1.1.0}, the fixed version |
| 87 | // will be empty. |
| 88 | // |
| 89 | // For the stdlib, we will show the fixed version closest to the |
| 90 | // Go version that is used. For example, if a fix is available in 1.17.5 and |
| 91 | // 1.18.5, and the GOVERSION is 1.17.3, 1.17.5 will be returned as the |
| 92 | // fixed version. |
| 93 | FixedVersion string `json:"fixed_version,omitempty"` |
| 94 | |
| 95 | // Trace contains an entry for each frame in the trace. |
| 96 | // |
| 97 | // Frames are sorted starting from the imported vulnerable symbol |
| 98 | // until the entry point. The first frame in Frames should match |
| 99 | // Symbol. |
| 100 | // |
| 101 | // In binary mode, trace will contain a single-frame with no position |
| 102 | // information. |
| 103 | // |
| 104 | // When a package is imported but no vulnerable symbol is called, the trace |
| 105 | // will contain a single-frame with no symbol or position information. |
| 106 | Trace []*Frame `json:"trace,omitempty"` |
| 107 | } |
| 108 | |
| 109 | // Frame represents an entry in a finding trace. |
| 110 | type Frame struct { |
| 111 | // Module is the module path of the module containing this symbol. |
| 112 | // |
| 113 | // Importable packages in the standard library will have the path "stdlib". |
| 114 | Module string `json:"module"` |
| 115 | |
| 116 | // Version is the module version from the build graph. |
| 117 | Version string `json:"version,omitempty"` |
| 118 | |
| 119 | // Package is the import path. |
| 120 | Package string `json:"package,omitempty"` |
| 121 | |
| 122 | // Function is the function name. |
| 123 | Function string `json:"function,omitempty"` |
| 124 | |
| 125 | // Receiver is the receiver type if the called symbol is a method. |
| 126 | // |
| 127 | // The client can create the final symbol name by |
| 128 | // prepending Receiver to FuncName. |
| 129 | Receiver string `json:"receiver,omitempty"` |
| 130 | |
| 131 | // Position describes an arbitrary source position |
| 132 | // including the file, line, and column location. |
| 133 | // A Position is valid if the line number is > 0. |
| 134 | Position *Position `json:"position,omitempty"` |
| 135 | } |
| 136 | |
| 137 | // Position represents arbitrary source position. |
| 138 | type Position struct { |
| 139 | Filename string `json:"filename,omitempty"` // filename, if any |
| 140 | Offset int `json:"offset"` // byte offset, starting at 0 |
| 141 | Line int `json:"line"` // line number, starting at 1 |
| 142 | Column int `json:"column"` // column number, starting at 1 (byte count) |
| 143 | } |
| 144 | |
| 145 | // ScanLevel represents the detail level at which a scan occurred. |
| 146 | // This can be necessary to correctly interpret the findings, for instance if |
| 147 | // a scan is at symbol level and a finding does not have a symbol it means the |
| 148 | // vulnerability was imported but not called. If the scan however was at |
| 149 | // "package" level, that determination cannot be made. |
| 150 | type ScanLevel string |
| 151 | |
| 152 | const ( |
| 153 | scanLevelModule = "module" |
| 154 | scanLevelPackage = "package" |
| 155 | scanLevelSymbol = "symbol" |
| 156 | ) |
| 157 | |
| 158 | // WantSymbols can be used to check whether the scan level is one that is able |
| 159 | // to generate symbols called findings. |
| 160 | func (l ScanLevel) WantSymbols() bool { return l == scanLevelSymbol } |