Skip to content

Commit 4eda2f5

Browse files
authored
🌱 Set OSV User-Agent for scorecard cli and cron workers. (#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 df89a3b commit 4eda2f5

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
@@ -41,7 +41,7 @@ require (
4141
github.com/caarlos0/env/v6 v6.10.1
4242
github.com/gobwas/glob v0.2.3
4343
github.com/google/go-github/v82 v82.0.0
44-
github.com/google/osv-scanner/v2 v2.2.4
44+
github.com/google/osv-scanner/v2 v2.3.2
4545
github.com/hmarr/codeowners v1.2.1
4646
github.com/in-toto/attestation v1.1.2
4747
github.com/mcuadros/go-jsonschema-generator v0.0.0-20200330054847-ba7a369d4303
@@ -63,18 +63,18 @@ require (
6363
cloud.google.com/go/pubsub/v2 v2.2.1 // indirect
6464
cyphar.com/go-pathrs v0.2.1 // indirect
6565
dario.cat/mergo v1.0.2 // indirect
66-
deps.dev/api/v3 v3.0.0-20250917073939-6ff3dd7d2eea // indirect
67-
deps.dev/api/v3alpha v0.0.0-20250903005441-604c45d5b44b // indirect
68-
deps.dev/util/maven v0.0.0-20250917073939-6ff3dd7d2eea // indirect
66+
deps.dev/api/v3 v3.0.0-20251219105704-58e32bc05c71 // indirect
67+
deps.dev/api/v3alpha v0.0.0-20251219105704-58e32bc05c71 // indirect
68+
deps.dev/util/maven v0.0.0-20251219105704-58e32bc05c71 // indirect
6969
deps.dev/util/pypi v0.0.0-20250903005441-604c45d5b44b // indirect
70-
deps.dev/util/resolve v0.0.0-20250917073939-6ff3dd7d2eea // indirect
71-
deps.dev/util/semver v0.0.0-20250917073939-6ff3dd7d2eea // indirect
70+
deps.dev/util/resolve v0.0.0-20251219105704-58e32bc05c71 // indirect
71+
deps.dev/util/semver v0.0.0-20251219105704-58e32bc05c71 // indirect
7272
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
7373
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20250520111509-a70c2aa677fa // indirect
74-
github.com/BurntSushi/toml v1.5.0 // indirect
74+
github.com/BurntSushi/toml v1.6.0 // indirect
7575
github.com/CycloneDX/cyclonedx-go v0.9.3 // indirect
7676
github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5 // indirect
77-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.29.0 // indirect
77+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.30.0 // indirect
7878
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.54.0 // indirect
7979
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.54.0 // indirect
8080
github.com/Masterminds/semver/v3 v3.4.0 // indirect
@@ -86,7 +86,7 @@ require (
8686
github.com/bmatcuk/doublestar/v4 v4.9.1 // indirect
8787
github.com/cespare/xxhash/v2 v2.3.0 // indirect
8888
github.com/cloudflare/circl v1.6.1 // indirect
89-
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
89+
github.com/cncf/xds/go v0.0.0-20251022180443-0feb69152e9f // indirect
9090
github.com/compose-spec/compose-go/v2 v2.8.1 // indirect
9191
github.com/containerd/cgroups/v3 v3.1.0 // indirect
9292
github.com/containerd/containerd v1.7.29 // indirect
@@ -115,12 +115,12 @@ require (
115115
github.com/edsrzf/mmap-go v1.2.0 // indirect
116116
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
117117
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
118-
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
118+
github.com/envoyproxy/go-control-plane/envoy v1.35.0 // indirect
119119
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
120120
github.com/erikvarga/go-rpmdb v0.0.0-20250523120114-a15a62cd4593 // indirect
121121
github.com/felixge/httpsnoop v1.0.4 // indirect
122122
github.com/go-errors/errors v1.0.2 // indirect
123-
github.com/go-jose/go-jose/v4 v4.1.2 // indirect
123+
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
124124
github.com/go-logr/stdr v1.2.2 // indirect
125125
github.com/go-ole/go-ole v1.2.6 // indirect
126126
github.com/go-openapi/jsonpointer v0.20.2 // indirect
@@ -135,13 +135,13 @@ require (
135135
github.com/google/gnostic-models v0.6.8 // indirect
136136
github.com/google/go-github/v75 v75.0.0 // indirect
137137
github.com/google/gofuzz v1.2.0 // indirect
138-
github.com/google/osv-scalibr v0.3.7-0.20251023161426-90e9ac9cc1b3 // indirect
138+
github.com/google/osv-scalibr v0.4.2-0.20260109123902-cf20290d7624 // indirect
139139
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
140140
github.com/google/s2a-go v0.1.9 // indirect
141141
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
142142
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
143-
github.com/ianlancetaylor/demangle v0.0.0-20250628045327-2d64ad6b7ec5 // indirect
144-
github.com/jedib0t/go-pretty/v6 v6.6.8 // indirect
143+
github.com/ianlancetaylor/demangle v0.0.0-20251118225945-96ee0021ea0f // indirect
144+
github.com/jedib0t/go-pretty/v6 v6.7.8 // indirect
145145
github.com/josharian/intern v1.0.0 // indirect
146146
github.com/json-iterator/go v1.1.12 // indirect
147147
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
@@ -165,9 +165,9 @@ require (
165165
github.com/olekukonko/ll v0.0.9 // indirect
166166
github.com/opencontainers/runtime-spec v1.2.1 // indirect
167167
github.com/opencontainers/selinux v1.13.0 // indirect
168-
github.com/ossf/osv-schema/bindings/go v0.0.0-20251012234424-434020c6442f // indirect
168+
github.com/ossf/osv-schema/bindings/go v0.0.0-20251230224438-88c48750ddae // indirect
169169
github.com/otiai10/mint v1.6.3 // indirect
170-
github.com/owenrumney/go-sarif/v3 v3.2.3 // indirect
170+
github.com/owenrumney/go-sarif/v3 v3.3.0 // indirect
171171
github.com/package-url/packageurl-go v0.1.3 // indirect
172172
github.com/pandatix/go-cvss v0.6.2 // indirect
173173
github.com/pierrec/lz4/v4 v4.1.21 // indirect
@@ -185,7 +185,7 @@ require (
185185
github.com/skeema/knownhosts v1.3.1 // indirect
186186
github.com/spdx/gordf v0.0.0-20250128162952-000978ccd6fb // indirect
187187
github.com/spdx/tools-golang v0.5.5 // indirect
188-
github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect
188+
github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect
189189
github.com/thoas/go-funk v0.9.3 // indirect
190190
github.com/tidwall/gjson v1.18.0 // indirect
191191
github.com/tidwall/jsonc v0.3.2 // indirect
@@ -198,11 +198,10 @@ require (
198198
github.com/ulikunitz/xz v0.5.15 // indirect
199199
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
200200
github.com/yusufpapurcu/wmi v1.2.4 // indirect
201-
github.com/zeebo/errs v1.4.0 // indirect
202201
github.com/zeebo/xxh3 v1.0.2 // indirect
203202
go.etcd.io/bbolt v1.4.3 // indirect
204203
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
205-
go.opentelemetry.io/contrib/detectors/gcp v1.37.0 // indirect
204+
go.opentelemetry.io/contrib/detectors/gcp v1.38.0 // indirect
206205
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0 // indirect
207206
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 // indirect
208207
go.opentelemetry.io/otel v1.38.0 // indirect
@@ -215,13 +214,13 @@ require (
215214
go.yaml.in/yaml/v4 v4.0.0-rc.3 // indirect
216215
golang.org/x/mod v0.30.0 // indirect
217216
golang.org/x/telemetry v0.0.0-20251111182119-bc8e575c7b54 // indirect
218-
golang.org/x/term v0.37.0 // indirect
217+
golang.org/x/term v0.39.0 // indirect
219218
golang.org/x/time v0.14.0 // indirect
220219
golang.org/x/vuln v1.1.4 // indirect
221-
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba // indirect
222-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirect
220+
google.golang.org/genproto/googleapis/api v0.0.0-20251222181119-0a764e51fe1b // indirect
221+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251213004720-97cd9d5aeac2 // indirect
223222
gopkg.in/inf.v0 v0.9.1 // indirect
224-
gopkg.in/ini.v1 v1.67.0 // indirect
223+
gopkg.in/ini.v1 v1.67.1 // indirect
225224
gopkg.in/yaml.v2 v2.4.0 // indirect
226225
gopkg.in/yaml.v3 v3.0.1 // indirect
227226
k8s.io/api v0.29.3 // indirect
@@ -234,7 +233,7 @@ require (
234233
modernc.org/mathutil v1.7.1 // indirect
235234
modernc.org/memory v1.11.0 // indirect
236235
modernc.org/sqlite v1.38.0 // indirect
237-
osv.dev/bindings/go v0.0.0-20251013010847-b847e93bd9b0 // indirect
236+
osv.dev/bindings/go v0.0.0-20260109041851-2d38aed9758f // indirect
238237
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
239238
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
240239
sigs.k8s.io/yaml v1.6.0 // indirect
@@ -290,14 +289,14 @@ require (
290289
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
291290
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
292291
go.uber.org/mock v0.6.0
293-
golang.org/x/crypto v0.45.0 // indirect
292+
golang.org/x/crypto v0.46.0 // indirect
294293
golang.org/x/exp v0.0.0-20250911091902-df9299821621 // indirect
295-
golang.org/x/net v0.47.0 // indirect
294+
golang.org/x/net v0.48.0 // indirect
296295
golang.org/x/oauth2 v0.34.0
297296
golang.org/x/sync v0.19.0 // indirect
298-
golang.org/x/sys v0.39.0 // indirect
297+
golang.org/x/sys v0.40.0 // indirect
299298
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
300299
google.golang.org/api v0.256.0 // indirect
301-
google.golang.org/grpc v1.76.0 // indirect
300+
google.golang.org/grpc v1.78.0 // indirect
302301
gopkg.in/warnings.v0 v0.1.2 // indirect
303302
)

0 commit comments

Comments
 (0)