Skip to content

Commit ad73998

Browse files
kash2104thomasleplus
authored andcommitted
🌱 Set OSV User-Agent for scorecard cli and cron workers. (ossf#4883)
* Set OSV User-Agent for scorecard cli and cron workers. Signed-off-by: kash2104 <kparikh1104@gmail.com> * Initialise client with OSV UserAgent. Signed-off-by: kash2104 <kparikh1104@gmail.com> --------- Signed-off-by: kash2104 <kparikh1104@gmail.com>
1 parent aec6a7e commit ad73998

6 files changed

Lines changed: 133 additions & 104 deletions

File tree

clients/osv.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,22 @@ import (
3030
var _ VulnerabilitiesClient = osvClient{}
3131

3232
type osvClient struct {
33-
local bool
33+
requestUserAgent string
34+
local bool
35+
}
36+
37+
type OSVConfig struct {
38+
UserAgent string
39+
ExperimentalLocal bool
40+
}
41+
42+
func NewOSVClient(config *OSVConfig) VulnerabilitiesClient {
43+
cfg := osvClient{}
44+
if config != nil {
45+
cfg.local = config.ExperimentalLocal
46+
cfg.requestUserAgent = config.UserAgent
47+
}
48+
return cfg
3449
}
3550

3651
// ListUnfixedVulnerabilities implements VulnerabilityClient.ListUnfixedVulnerabilities.
@@ -54,6 +69,12 @@ func (v osvClient) ListUnfixedVulnerabilities(
5469
if commit != "" {
5570
gitCommits = append(gitCommits, commit)
5671
}
72+
73+
exp := osvscanner.ExperimentalScannerActions{
74+
PluginsEnabled: []string{"python/requirements"},
75+
PluginsDisabled: []string{"python/requirementsenhanceable"},
76+
RequestUserAgent: v.requestUserAgent,
77+
}
5778
res, err := osvscanner.DoScan(osvscanner.ScannerActions{
5879
DirectoryPaths: directoryPaths,
5980
IncludeGitRoot: false,
@@ -62,10 +83,7 @@ func (v osvClient) ListUnfixedVulnerabilities(
6283
CompareOffline: v.local,
6384
DownloadDatabases: v.local,
6485
// swap out the transitive requirements scanning for offline extractor
65-
ExperimentalScannerActions: osvscanner.ExperimentalScannerActions{
66-
PluginsEnabled: []string{"python/requirements"},
67-
PluginsDisabled: []string{"python/requirementsenhanceable"},
68-
},
86+
ExperimentalScannerActions: exp,
6987
}) // TODO: Do logging?
7088

7189
response := VulnerabilitiesResponse{}
@@ -86,8 +104,8 @@ func (v osvClient) ListUnfixedVulnerabilities(
86104
continue
87105
}
88106
response.Vulnerabilities = append(response.Vulnerabilities, Vulnerability{
89-
ID: vulns[i].Vulnerability.ID,
90-
Aliases: vulns[i].Vulnerability.Aliases,
107+
ID: vulns[i].Vulnerability.GetId(),
108+
Aliases: vulns[i].Vulnerability.GetAliases(),
91109
})
92110
// Remove duplicate vulnerability IDs for now as we don't report information
93111
// on the source of each vulnerability yet, therefore having multiple identical

clients/vulnerabilities.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type VulnerabilitiesClient interface {
2929

3030
// DefaultVulnerabilitiesClient returns a new OSV Vulnerabilities client.
3131
func DefaultVulnerabilitiesClient() VulnerabilitiesClient {
32-
return osvClient{local: false}
32+
return NewOSVClient(nil)
3333
}
3434

3535
// ExperimentalLocalOSVClient returns an OSV Vulnerabilities client which

cmd/root.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"sort"
2525
"strings"
2626

27+
"github.com/google/osv-scanner/v2/pkg/osvscanner"
2728
"github.com/spf13/cobra"
2829
"sigs.k8s.io/release-utils/version"
2930

@@ -170,12 +171,19 @@ func rootCmd(o *options.Options) error {
170171

171172
enabledProbes := o.Probes()
172173

174+
info := version.GetVersionInfo()
175+
actions := osvscanner.ExperimentalScannerActions{}
176+
config := clients.OSVConfig{}
177+
actions.RequestUserAgent = fmt.Sprintf("scorecard-cli/%s", info.GitVersion)
178+
config.UserAgent = actions.RequestUserAgent
179+
173180
opts := []scorecard.Option{
174181
scorecard.WithLogLevel(sclog.ParseLevel(o.LogLevel)),
175182
scorecard.WithCommitSHA(o.Commit),
176183
scorecard.WithCommitDepth(o.CommitDepth),
177184
scorecard.WithProbes(enabledProbes),
178185
scorecard.WithChecks(checks),
186+
scorecard.WithVulnerabilitiesClient(clients.NewOSVClient(&config)),
179187
}
180188
if strings.EqualFold(o.FileMode, options.FileModeGit) {
181189
opts = append(opts, scorecard.WithFileModeGit())

cron/internal/worker/main.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import (
2626
"os"
2727
"strings"
2828

29+
"github.com/google/osv-scanner/v2/pkg/osvscanner"
2930
"go.opencensus.io/stats/view"
31+
"sigs.k8s.io/release-utils/version"
3032

3133
"github.com/ossf/scorecard/v5/checker"
3234
"github.com/ossf/scorecard/v5/clients"
@@ -97,7 +99,7 @@ type ScorecardWorker struct {
9799
blacklistedChecks []string
98100
}
99101

100-
func newScorecardWorker() (*ScorecardWorker, error) {
102+
func newScorecardWorker(vulnsClient clients.VulnerabilitiesClient) (*ScorecardWorker, error) {
101103
var err error
102104
sw := &ScorecardWorker{}
103105
if sw.checkDocs, err = docs.Read(); err != nil {
@@ -132,7 +134,7 @@ func newScorecardWorker() (*ScorecardWorker, error) {
132134
if sw.ossFuzzRepoClient, err = ossfuzz.CreateOSSFuzzClientEager(ossfuzz.StatusURL); err != nil {
133135
return nil, fmt.Errorf("ossfuzz.CreateOSSFuzzClientEager: %w", err)
134136
}
135-
sw.vulnsClient = clients.DefaultVulnerabilitiesClient()
137+
sw.vulnsClient = vulnsClient
136138

137139
apiBaseURL, err := config.GetAPIBaseURL()
138140
if err != nil {
@@ -368,11 +370,17 @@ func getPurger(logger *log.Logger, apiBaseURL string) cdn.Purger {
368370
}
369371

370372
func main() {
373+
info := version.GetVersionInfo()
374+
actions := osvscanner.ExperimentalScannerActions{}
375+
actions.RequestUserAgent = fmt.Sprintf("scorecard-cron/%s", info.GitVersion)
376+
osvConfig := clients.OSVConfig{}
377+
osvConfig.UserAgent = actions.RequestUserAgent
378+
vulnsClient := clients.NewOSVClient(&osvConfig)
371379
flag.Parse()
372380
if err := config.ReadConfig(); err != nil {
373381
panic(err)
374382
}
375-
sw, err := newScorecardWorker()
383+
sw, err := newScorecardWorker(vulnsClient)
376384
if err != nil {
377385
panic(err)
378386
}

go.mod

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ossf/scorecard/v5
22

3-
go 1.24.6
3+
go 1.25.5
44

55
require (
66
cloud.google.com/go/bigquery v1.72.0
@@ -42,7 +42,7 @@ require (
4242
github.com/caarlos0/env/v6 v6.10.1
4343
github.com/gobwas/glob v0.2.3
4444
github.com/google/go-github/v82 v82.0.0
45-
github.com/google/osv-scanner/v2 v2.2.4
45+
github.com/google/osv-scanner/v2 v2.3.2
4646
github.com/hmarr/codeowners v1.2.1
4747
github.com/in-toto/attestation v1.1.2
4848
github.com/mcuadros/go-jsonschema-generator v0.0.0-20200330054847-ba7a369d4303
@@ -64,18 +64,18 @@ require (
6464
cloud.google.com/go/pubsub/v2 v2.2.1 // indirect
6565
cyphar.com/go-pathrs v0.2.1 // indirect
6666
dario.cat/mergo v1.0.2 // indirect
67-
deps.dev/api/v3 v3.0.0-20250917073939-6ff3dd7d2eea // indirect
68-
deps.dev/api/v3alpha v0.0.0-20250903005441-604c45d5b44b // indirect
69-
deps.dev/util/maven v0.0.0-20250917073939-6ff3dd7d2eea // indirect
67+
deps.dev/api/v3 v3.0.0-20251219105704-58e32bc05c71 // indirect
68+
deps.dev/api/v3alpha v0.0.0-20251219105704-58e32bc05c71 // indirect
69+
deps.dev/util/maven v0.0.0-20251219105704-58e32bc05c71 // indirect
7070
deps.dev/util/pypi v0.0.0-20250903005441-604c45d5b44b // indirect
71-
deps.dev/util/resolve v0.0.0-20250917073939-6ff3dd7d2eea // indirect
72-
deps.dev/util/semver v0.0.0-20250917073939-6ff3dd7d2eea // indirect
71+
deps.dev/util/resolve v0.0.0-20251219105704-58e32bc05c71 // indirect
72+
deps.dev/util/semver v0.0.0-20251219105704-58e32bc05c71 // indirect
7373
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
7474
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20250520111509-a70c2aa677fa // indirect
75-
github.com/BurntSushi/toml v1.5.0 // indirect
75+
github.com/BurntSushi/toml v1.6.0 // indirect
7676
github.com/CycloneDX/cyclonedx-go v0.9.3 // indirect
7777
github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5 // indirect
78-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.29.0 // indirect
78+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.30.0 // indirect
7979
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.54.0 // indirect
8080
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.54.0 // indirect
8181
github.com/Masterminds/semver/v3 v3.4.0 // indirect
@@ -87,7 +87,7 @@ require (
8787
github.com/bmatcuk/doublestar/v4 v4.9.1 // indirect
8888
github.com/cespare/xxhash/v2 v2.3.0 // indirect
8989
github.com/cloudflare/circl v1.6.1 // indirect
90-
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
90+
github.com/cncf/xds/go v0.0.0-20251022180443-0feb69152e9f // indirect
9191
github.com/compose-spec/compose-go/v2 v2.8.1 // indirect
9292
github.com/containerd/cgroups/v3 v3.1.0 // indirect
9393
github.com/containerd/containerd v1.7.29 // indirect
@@ -116,12 +116,12 @@ require (
116116
github.com/edsrzf/mmap-go v1.2.0 // indirect
117117
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
118118
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
119-
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
119+
github.com/envoyproxy/go-control-plane/envoy v1.35.0 // indirect
120120
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
121121
github.com/erikvarga/go-rpmdb v0.0.0-20250523120114-a15a62cd4593 // indirect
122122
github.com/felixge/httpsnoop v1.0.4 // indirect
123123
github.com/go-errors/errors v1.0.2 // indirect
124-
github.com/go-jose/go-jose/v4 v4.1.2 // indirect
124+
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
125125
github.com/go-logr/stdr v1.2.2 // indirect
126126
github.com/go-ole/go-ole v1.2.6 // indirect
127127
github.com/go-openapi/jsonpointer v0.20.2 // indirect
@@ -136,13 +136,13 @@ require (
136136
github.com/google/gnostic-models v0.6.8 // indirect
137137
github.com/google/go-github/v75 v75.0.0 // indirect
138138
github.com/google/gofuzz v1.2.0 // indirect
139-
github.com/google/osv-scalibr v0.3.7-0.20251023161426-90e9ac9cc1b3 // indirect
139+
github.com/google/osv-scalibr v0.4.2-0.20260109123902-cf20290d7624 // indirect
140140
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
141141
github.com/google/s2a-go v0.1.9 // indirect
142142
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
143143
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
144-
github.com/ianlancetaylor/demangle v0.0.0-20250628045327-2d64ad6b7ec5 // indirect
145-
github.com/jedib0t/go-pretty/v6 v6.6.8 // indirect
144+
github.com/ianlancetaylor/demangle v0.0.0-20251118225945-96ee0021ea0f // indirect
145+
github.com/jedib0t/go-pretty/v6 v6.7.8 // indirect
146146
github.com/josharian/intern v1.0.0 // indirect
147147
github.com/json-iterator/go v1.1.12 // indirect
148148
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
@@ -166,9 +166,9 @@ require (
166166
github.com/olekukonko/ll v0.0.9 // indirect
167167
github.com/opencontainers/runtime-spec v1.2.1 // indirect
168168
github.com/opencontainers/selinux v1.13.0 // indirect
169-
github.com/ossf/osv-schema/bindings/go v0.0.0-20251012234424-434020c6442f // indirect
169+
github.com/ossf/osv-schema/bindings/go v0.0.0-20251230224438-88c48750ddae // indirect
170170
github.com/otiai10/mint v1.6.3 // indirect
171-
github.com/owenrumney/go-sarif/v3 v3.2.3 // indirect
171+
github.com/owenrumney/go-sarif/v3 v3.3.0 // indirect
172172
github.com/package-url/packageurl-go v0.1.3 // indirect
173173
github.com/pandatix/go-cvss v0.6.2 // indirect
174174
github.com/pierrec/lz4/v4 v4.1.21 // indirect
@@ -186,7 +186,7 @@ require (
186186
github.com/skeema/knownhosts v1.3.1 // indirect
187187
github.com/spdx/gordf v0.0.0-20250128162952-000978ccd6fb // indirect
188188
github.com/spdx/tools-golang v0.5.5 // indirect
189-
github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect
189+
github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
190190
github.com/thoas/go-funk v0.9.3 // indirect
191191
github.com/tidwall/gjson v1.18.0 // indirect
192192
github.com/tidwall/jsonc v0.3.2 // indirect
@@ -199,11 +199,10 @@ require (
199199
github.com/ulikunitz/xz v0.5.15 // indirect
200200
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
201201
github.com/yusufpapurcu/wmi v1.2.4 // indirect
202-
github.com/zeebo/errs v1.4.0 // indirect
203202
github.com/zeebo/xxh3 v1.0.2 // indirect
204203
go.etcd.io/bbolt v1.4.3 // indirect
205204
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
206-
go.opentelemetry.io/contrib/detectors/gcp v1.37.0 // indirect
205+
go.opentelemetry.io/contrib/detectors/gcp v1.38.0 // indirect
207206
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0 // indirect
208207
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 // indirect
209208
go.opentelemetry.io/otel v1.38.0 // indirect
@@ -216,13 +215,13 @@ require (
216215
go.yaml.in/yaml/v4 v4.0.0-rc.3 // indirect
217216
golang.org/x/mod v0.30.0 // indirect
218217
golang.org/x/telemetry v0.0.0-20251111182119-bc8e575c7b54 // indirect
219-
golang.org/x/term v0.37.0 // indirect
218+
golang.org/x/term v0.39.0 // indirect
220219
golang.org/x/time v0.14.0 // indirect
221220
golang.org/x/vuln v1.1.4 // indirect
222-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba // indirect
223-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirect
221+
google.golang.org/genproto/googleapis/api v0.0.0-20251222181119-0a764e51fe1b // indirect
222+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251213004720-97cd9d5aeac2 // indirect
224223
gopkg.in/inf.v0 v0.9.1 // indirect
225-
gopkg.in/ini.v1 v1.67.0 // indirect
224+
gopkg.in/ini.v1 v1.67.1 // indirect
226225
gopkg.in/yaml.v2 v2.4.0 // indirect
227226
gopkg.in/yaml.v3 v3.0.1 // indirect
228227
k8s.io/api v0.29.3 // indirect
@@ -235,7 +234,7 @@ require (
235234
modernc.org/mathutil v1.7.1 // indirect
236235
modernc.org/memory v1.11.0 // indirect
237236
modernc.org/sqlite v1.38.0 // indirect
238-
osv.dev/bindings/go v0.0.0-20251013010847-b847e93bd9b0 // indirect
237+
osv.dev/bindings/go v0.0.0-20260109041851-2d38aed9758f // indirect
239238
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
240239
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
241240
sigs.k8s.io/yaml v1.6.0 // indirect
@@ -291,14 +290,14 @@ require (
291290
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
292291
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
293292
go.uber.org/mock v0.6.0
294-
golang.org/x/crypto v0.45.0 // indirect
293+
golang.org/x/crypto v0.46.0 // indirect
295294
golang.org/x/exp v0.0.0-20250911091902-df9299821621 // indirect
296-
golang.org/x/net v0.47.0 // indirect
295+
golang.org/x/net v0.48.0 // indirect
297296
golang.org/x/oauth2 v0.34.0
298297
golang.org/x/sync v0.19.0 // indirect
299-
golang.org/x/sys v0.39.0 // indirect
298+
golang.org/x/sys v0.40.0 // indirect
300299
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
301300
google.golang.org/api v0.256.0 // indirect
302-
google.golang.org/grpc v1.76.0 // indirect
301+
google.golang.org/grpc v1.78.0 // indirect
303302
gopkg.in/warnings.v0 v0.1.2 // indirect
304303
)

0 commit comments

Comments
 (0)