Skip to content

Commit 20f8fe4

Browse files
authored
feat(vulnerabilities): add reference_link field with priority-based URL selection (#3988)
Signed-off-by: anilb <[email protected]>
1 parent 11e8337 commit 20f8fe4

5 files changed

Lines changed: 33 additions & 2 deletions

File tree

services/apps/git_integration/src/crowdgit/services/vulnerability_scanner/db.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ func (db *InsightsDB) saveVulnerabilities(ctx context.Context, repoURL string, v
107107
source_path, source_type,
108108
status, fixed_version,
109109
published_at, modified_at,
110+
reference_link,
110111
scanned_at
111-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
112+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)
112113
ON CONFLICT (repo_url, vulnerability_id, package_name, source_path)
113114
DO UPDATE SET
114115
scan_id = EXCLUDED.scan_id,
@@ -126,6 +127,7 @@ func (db *InsightsDB) saveVulnerabilities(ctx context.Context, repoURL string, v
126127
source_type = EXCLUDED.source_type,
127128
published_at = EXCLUDED.published_at,
128129
modified_at = EXCLUDED.modified_at,
130+
reference_link = EXCLUDED.reference_link,
129131
scanned_at = EXCLUDED.scanned_at,
130132
resolved_at = NULL
131133
RETURNING (xmax = 0) AS is_new`
@@ -139,6 +141,7 @@ func (db *InsightsDB) saveVulnerabilities(ctx context.Context, repoURL string, v
139141
v.SourcePath, v.SourceType,
140142
v.Status, v.FixedVersion,
141143
v.PublishedAt, v.ModifiedAt,
144+
v.ReferenceLink,
142145
now,
143146
)
144147
}

services/apps/git_integration/src/crowdgit/services/vulnerability_scanner/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ type Vulnerability struct {
6868
FixedVersion string `json:"fixed_version"`
6969
PublishedAt *time.Time `json:"published_at"`
7070
ModifiedAt *time.Time `json:"modified_at"`
71+
ReferenceLink string `json:"reference_link"`
7172
}

services/apps/git_integration/src/crowdgit/services/vulnerability_scanner/vulnerability_scanner.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,28 @@ func (s *VulnerabilityScanner) scan(transitiveScanning bool) (models.Vulnerabili
139139
}
140140
}
141141

142+
func (s *VulnerabilityScanner) selectBestReference(v *osvschema.Vulnerability, cveIDs []string) string {
143+
// First priority: Construct NVD URL from CVE ID if available
144+
if len(cveIDs) > 0 && cveIDs[0] != "" {
145+
return "https://nvd.nist.gov/vuln/detail/" + cveIDs[0]
146+
}
147+
148+
if v == nil || v.References == nil || len(v.References) == 0 {
149+
return ""
150+
}
151+
152+
// Second priority: Select by reference type priority
153+
for _, priorityType := range []string{"ADVISORY", "ARTICLE", "WEB", "INTRODUCED"} {
154+
for _, ref := range v.References {
155+
if ref.Type.String() == priorityType && ref.Url != "" {
156+
return ref.Url
157+
}
158+
}
159+
}
160+
161+
return ""
162+
}
163+
142164
func (s *VulnerabilityScanner) processResults(scanID string, results models.VulnerabilityResults) []Vulnerability {
143165
flattened := results.Flatten()
144166

@@ -167,6 +189,7 @@ func (s *VulnerabilityScanner) processResults(scanID string, results models.Vuln
167189
status, fixedVersion := s.getFixInfo(v)
168190
publishedAt := protoTimestampToTime(v.Vulnerability.Published)
169191
modifiedAt := protoTimestampToTime(v.Vulnerability.Modified)
192+
referenceLink := s.selectBestReference(v.Vulnerability, cveIDs)
170193

171194
seen[key] = Vulnerability{
172195
RepoURL: s.gitURL,
@@ -188,6 +211,7 @@ func (s *VulnerabilityScanner) processResults(scanID string, results models.Vuln
188211
FixedVersion: fixedVersion,
189212
PublishedAt: publishedAt,
190213
ModifiedAt: modifiedAt,
214+
ReferenceLink: referenceLink,
191215
}
192216
}
193217

services/libs/tinybird/datasources/vulnerabilities.datasource

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DESCRIPTION >
2020
- `fixedVersion` is the version that fixes the vulnerability.
2121
- `publishedAt` is when the vulnerability was publicly disclosed.
2222
- `modifiedAt` is when the vulnerability record was last modified.
23+
- `referenceLink` is the reference URL for this vulnerability.
2324
- `firstDetectedAt` is when the vulnerability was first detected in this repository.
2425
- `scannedAt` is the timestamp of the scan that last detected this vulnerability.
2526
- `resolvedAt` is when the vulnerability was resolved within this repository.
@@ -45,6 +46,7 @@ SCHEMA >
4546
`fixedVersion` String `json:$.record.fixed_version` DEFAULT '',
4647
`publishedAt` Nullable(DateTime64(3)) `json:$.record.published_at`,
4748
`modifiedAt` Nullable(DateTime64(3)) `json:$.record.modified_at`,
49+
`referenceLink` String `json:$.record.reference_link` DEFAULT '',
4850
`firstDetectedAt` DateTime64(3) `json:$.record.first_detected_at`,
4951
`scannedAt` DateTime64(3) `json:$.record.scanned_at`,
5052
`resolvedAt` Nullable(DateTime64(3)) `json:$.record.resolved_at`

services/libs/tinybird/pipes/vulnerabilities_list.pipe

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ SQL >
2323
any (v.publishedAt) as publishedAt,
2424
any (v.status) as status,
2525
groupArray(concat(v.repoUrl, '/blob/HEAD', v.sourcePath)) as paths,
26-
max(v.fixedVersion) as fixedVersion
26+
max(v.fixedVersion) as fixedVersion,
27+
anyIf(v.referenceLink, v.referenceLink != '') as referenceLink
2728
FROM vulnerabilities as v FINAL
2829
WHERE
2930
repoUrl in (select arrayJoin(repositories) from segments_filtered)

0 commit comments

Comments
 (0)