Skip to content

Commit 836a426

Browse files
committed
feat: migrate source human_link templates from jinja to Go templates
Rewrite human_link in source.yaml and source_test.yaml to the Go template syntax, and document it in docs/new_source.md. This also fixes AlmaLinux human links, which used ECOSYSTEMS[1] (only valid for the old Python ecosystem list) in prod and the never-populated ECOSYSTEM_VER in staging. Adds a test that every human_link in source.yaml/source_test.yaml is a valid Go template.
1 parent f1734dc commit 836a426

4 files changed

Lines changed: 110 additions & 62 deletions

File tree

‎docs/new_source.md‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Accordingly, the license for any contributed data source **must** at minimum per
5555
repo_url: # The repo URL for the source
5656
db_prefix: # DB prefix, as reserved in ossf. https://ossf.github.io/osv-schema/#id-modified-fields
5757
accepted_ecosystems: # List of OSV ecosystems this datasource will provide vulnerability records for.
58-
human_link: # HTTP link prefix to individual vulnerability records for humans.
58+
human_link: # Template for the human readable link to individual vulnerability records (see below).
5959
link: # HTTP link prefix to individual OSV source records.
6060
directory_path: # Vulnerability data not under this path is ignored by the importer.
6161
extension: '.json' # Default extension.
@@ -83,7 +83,7 @@ Advanced and optional fields
8383
rest_api_url: # URL pointing to a REST endpoint containing at least all of the vulnerabilities' IDs and date modified
8484
db_prefix: # DB prefix, as reserved in ossf. https://ossf.github.io/osv-schema/#id-modified-fields
8585
accepted_ecosystems: # List of OSV ecosystems this datasource will provide vulnerability records for.
86-
human_link: # The human readable link
86+
human_link: # Template for the human readable link (see below)
8787
link: # The base link
8888
directory_path: # Vulnerability data not under this path is ignored by the importer
8989
extension: # Extension for vulnerability data
@@ -105,7 +105,7 @@ Advanced and optional fields
105105
bucket: # Bucket name
106106
db_prefix: # DB prefix, as reserved in ossf. https://ossf.github.io/osv-schema/#id-modified-fields
107107
accepted_ecosystems: # List of OSV ecosystems this datasource will provide vulnerability records for.
108-
human_link: # The human readable link
108+
human_link: # Template for the human readable link (see below)
109109
link: # The base link
110110
directory_path: # Vulnerability data not under this path is ignored by the importer
111111
extension: '.json' # Extension for vulnerability data
@@ -121,6 +121,27 @@ Advanced and optional fields
121121
strict_validation: False # Apply strict validation (JSON Schema + linter checks) to this source.
122122
```
123123
124+
### `human_link` templates
125+
126+
{% raw %}
127+
`human_link` is a [Go template](https://pkg.go.dev/text/template) rendered for each vulnerability. The following are available:
128+
129+
- `.ID`: the vulnerability ID.
130+
- `.Ecosystems`: the ecosystems of each affected package, in order (e.g. `{{ index .Ecosystems 0 }}`).
131+
- `field SEP N`: splits the input on `SEP` and returns the `N`th part (0-indexed).
132+
- `replace OLD NEW`: replaces all occurrences of `OLD` with `NEW`.
133+
- `lower`: lowercases the input.
134+
135+
If the template fails to render (e.g. `field` is out of range), no link is shown.
136+
137+
``` yaml
138+
human_link: 'https://github.com/advisories/{{ .ID }}'
139+
human_link: 'https://security.alpinelinux.org/vuln/{{ .ID | replace "ALPINE-" "" }}'
140+
# SUSE-SU-2024:1234-1 -> https://www.suse.com/support/update/announcement/2024/suse-su-20241234-1/
141+
human_link: 'https://www.suse.com/support/update/announcement/{{ .ID | field ":" 0 | field "-" 2 }}/{{ .ID | replace ":" "" | lower }}/'
142+
```
143+
{% endraw %}
144+
124145
</details>
125146

126147
Do you have a question, suggestion or feedback? Please [open an issue](https://github.com/google/osv.dev/issues).

‎go/internal/website/human_link_test.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package website
22

33
import (
44
"context"
5+
"os"
6+
"path/filepath"
57
"testing"
68

79
"github.com/ossf/osv-schema/bindings/go/osvschema"
10+
"sigs.k8s.io/yaml"
811
)
912

1013
func TestRenderHumanLink(t *testing.T) {
@@ -99,3 +102,27 @@ func TestRenderHumanLink(t *testing.T) {
99102
})
100103
}
101104
}
105+
106+
// TestSourceHumanLinks checks that every human_link in source.yaml and source_test.yaml is a valid Go template.
107+
func TestSourceHumanLinks(t *testing.T) {
108+
for _, file := range []string{"source.yaml", "source_test.yaml"} {
109+
t.Run(file, func(t *testing.T) {
110+
b, err := os.ReadFile(filepath.Join("..", "..", "..", file))
111+
if err != nil {
112+
t.Fatalf("failed to read %s: %v", file, err)
113+
}
114+
var sources []struct {
115+
Name string `json:"name"`
116+
HumanLink string `json:"human_link"`
117+
}
118+
if err := yaml.Unmarshal(b, &sources); err != nil {
119+
t.Fatalf("failed to parse %s: %v", file, err)
120+
}
121+
for _, s := range sources {
122+
if _, err := parseHumanLink(s.HumanLink); err != nil {
123+
t.Errorf("%s: invalid human_link %q: %v", s.Name, s.HumanLink, err)
124+
}
125+
}
126+
})
127+
}
128+
}

‎source.yaml‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
db_prefix: ['ALBA-']
1111
accepted_ecosystems: ['AlmaLinux']
1212
ignore_git: False
13-
human_link: '{% if ECOSYSTEMS|length >= 2 %}https://errata.almalinux.org/{{ ECOSYSTEMS[1].split(":")[1] }}/{{ BUG_ID | replace(":", "-", 1) }}.html{% endif %}'
13+
human_link: 'https://errata.almalinux.org/{{ index .Ecosystems 0 | field ":" 1 }}/{{ .ID | replace ":" "-" }}.html'
1414
link: 'https://github.com/AlmaLinux/osv-database/blob/master/'
1515
editable: False
1616
strict_validation: False
@@ -26,7 +26,7 @@
2626
db_prefix: ['ALEA-']
2727
accepted_ecosystems: ['AlmaLinux']
2828
ignore_git: False
29-
human_link: '{% if ECOSYSTEMS|length >= 2 %}https://errata.almalinux.org/{{ ECOSYSTEMS[1].split(":")[1] }}/{{ BUG_ID | replace(":", "-", 1) }}.html{% endif %}'
29+
human_link: 'https://errata.almalinux.org/{{ index .Ecosystems 0 | field ":" 1 }}/{{ .ID | replace ":" "-" }}.html'
3030
link: 'https://github.com/AlmaLinux/osv-database/blob/master/'
3131
editable: False
3232
strict_validation: False
@@ -42,7 +42,7 @@
4242
db_prefix: ['ALSA-']
4343
accepted_ecosystems: ['AlmaLinux']
4444
ignore_git: False
45-
human_link: '{% if ECOSYSTEMS|length >= 2 %}https://errata.almalinux.org/{{ ECOSYSTEMS[1].split(":")[1] }}/{{ BUG_ID | replace(":", "-", 1) }}.html{% endif %}'
45+
human_link: 'https://errata.almalinux.org/{{ index .Ecosystems 0 | field ":" 1 }}/{{ .ID | replace ":" "-" }}.html'
4646
link: 'https://github.com/AlmaLinux/osv-database/blob/master/'
4747
editable: False
4848
strict_validation: False
@@ -58,7 +58,7 @@
5858
db_prefix: ['ALPINE-']
5959
accepted_ecosystems: ['Alpine']
6060
ignore_git: True
61-
human_link: 'https://security.alpinelinux.org/vuln/{{ BUG_ID | replace("ALPINE-", "") }}'
61+
human_link: 'https://security.alpinelinux.org/vuln/{{ .ID | replace "ALPINE-" "" }}'
6262
link: 'https://storage.googleapis.com/cve-osv-conversion/'
6363
editable: False
6464
strict_validation: True
@@ -103,7 +103,7 @@
103103
db_prefix: ['BELL-']
104104
accepted_ecosystems: ['Alpaquita', 'BellSoft Hardened Containers']
105105
ignore_git: False
106-
human_link: 'https://docs.bell-sw.com/security/cves/{{ BUG_ID }}/'
106+
human_link: 'https://docs.bell-sw.com/security/cves/{{ .ID }}/'
107107
link: 'https://github.com/bell-sw/osv-database/blob/master/'
108108
editable: False
109109
strict_validation: True
@@ -134,7 +134,7 @@
134134
db_prefix: ['ROOT-']
135135
accepted_ecosystems: ['Root']
136136
ignore_git: True
137-
human_link: 'https://root.io/security/{{ BUG_ID }}'
137+
human_link: 'https://root.io/security/{{ .ID }}'
138138
link: 'https://api.root.io/external/osv/'
139139
editable: False
140140
strict_validation: True
@@ -151,7 +151,7 @@
151151
accepted_ecosystems: ['Chainguard', 'Wolfi']
152152
ignore_git: True
153153
link: 'https://advisories.cgr.dev/chainguard/v3/osv/'
154-
human_link: 'https://images.chainguard.dev/security/{{ BUG_ID }}'
154+
human_link: 'https://images.chainguard.dev/security/{{ .ID }}'
155155
editable: False
156156
strict_validation: True
157157

@@ -181,7 +181,7 @@
181181
db_prefix: ['CURL-']
182182
accepted_ecosystems: [] # None: There is no curl ecosystem, they just publish GIT advisories
183183
ignore_git: False
184-
human_link: 'https://curl.se/docs/{{ BUG_ID | replace("CURL-", "") }}.html'
184+
human_link: 'https://curl.se/docs/{{ .ID | replace "CURL-" "" }}.html'
185185
link: 'https://curl.se/docs/'
186186
editable: False
187187
strict_validation: False
@@ -197,7 +197,7 @@
197197
db_prefix: ['CVE-']
198198
accepted_ecosystems: ['*'] # All ecosystems (we maintain these conversions)
199199
ignore_git: False
200-
human_link: 'https://cve.org/CVERecord?id={{ BUG_ID }}'
200+
human_link: 'https://cve.org/CVERecord?id={{ .ID }}'
201201
link: 'https://storage.googleapis.com/cve-osv-conversion/'
202202
editable: False
203203
strict_validation: True
@@ -213,7 +213,7 @@
213213
db_prefix: ['DEBIAN-']
214214
accepted_ecosystems: ['Debian']
215215
ignore_git: True
216-
human_link: 'https://security-tracker.debian.org/tracker/{{ BUG_ID | replace("DEBIAN-", "") }}'
216+
human_link: 'https://security-tracker.debian.org/tracker/{{ .ID | replace "DEBIAN-" "" }}'
217217
link: 'https://storage.googleapis.com/debian-osv/'
218218
editable: False
219219
strict_validation: True
@@ -229,7 +229,7 @@
229229
db_prefix: ['DLA-']
230230
accepted_ecosystems: ['Debian']
231231
ignore_git: True
232-
human_link: 'https://security-tracker.debian.org/tracker/{{ BUG_ID }}'
232+
human_link: 'https://security-tracker.debian.org/tracker/{{ .ID }}'
233233
link: 'https://storage.googleapis.com/debian-osv/'
234234
editable: False
235235
strict_validation: True
@@ -245,7 +245,7 @@
245245
db_prefix: ['DSA-']
246246
accepted_ecosystems: ['Debian']
247247
ignore_git: True
248-
human_link: 'https://security-tracker.debian.org/tracker/{{ BUG_ID }}'
248+
human_link: 'https://security-tracker.debian.org/tracker/{{ .ID }}'
249249
link: 'https://storage.googleapis.com/debian-osv/'
250250
editable: False
251251
strict_validation: True
@@ -261,7 +261,7 @@
261261
db_prefix: ['DTSA-']
262262
accepted_ecosystems: ['Debian']
263263
ignore_git: True
264-
human_link: 'https://security-tracker.debian.org/tracker/{{ BUG_ID }}'
264+
human_link: 'https://security-tracker.debian.org/tracker/{{ .ID }}'
265265
link: 'https://storage.googleapis.com/debian-osv/'
266266
editable: False
267267
strict_validation: True
@@ -301,7 +301,7 @@
301301
rest_api_url: 'https://cna.erlef.org/osv/all.json'
302302
db_prefix: ['EEF-']
303303
accepted_ecosystems: ['Hex','npm']
304-
human_link: 'https://cna.erlef.org/osv/{{ BUG_ID }}.html'
304+
human_link: 'https://cna.erlef.org/osv/{{ .ID }}.html'
305305
link: 'https://cna.erlef.org/osv/'
306306
directory_path: 'osv'
307307
extension: '.json'
@@ -322,7 +322,7 @@
322322
db_prefix: ['GHSA-']
323323
accepted_ecosystems: ['*'] # All ecosystems (We trust GHSA)
324324
ignore_git: False
325-
human_link: 'https://github.com/advisories/{{ BUG_ID }}'
325+
human_link: 'https://github.com/advisories/{{ .ID }}'
326326
link: 'https://github.com/github/advisory-database/blob/main/'
327327
editable: False
328328
strict_validation: False
@@ -338,7 +338,7 @@
338338
db_prefix: ['GO-']
339339
accepted_ecosystems: ['Go']
340340
ignore_git: True
341-
human_link: 'https://pkg.go.dev/vuln/{{ BUG_ID }}'
341+
human_link: 'https://pkg.go.dev/vuln/{{ .ID }}'
342342
link: 'https://vuln.go.dev/'
343343
editable: False
344344
strict_validation: True
@@ -370,7 +370,7 @@
370370
db_prefix: ['JLSEC-']
371371
accepted_ecosystems: ['Julia']
372372
ignore_git: False
373-
human_link: 'https://github.com/JuliaLang/SecurityAdvisories.jl/blob/main/advisories/published/{{ BUG_ID.split("-")[1] }}/{{ BUG_ID }}.md'
373+
human_link: 'https://github.com/JuliaLang/SecurityAdvisories.jl/blob/main/advisories/published/{{ .ID | field "-" 1 }}/{{ .ID }}.md'
374374
link: 'https://github.com/JuliaLang/SecurityAdvisories.jl/tree/generated/osv/'
375375
editable: False
376376
repo_username: 'git'
@@ -387,7 +387,7 @@
387387
db_prefix: ['RHLW-']
388388
accepted_ecosystems: ['Red Hat Lightwell']
389389
ignore_git: False
390-
human_link: 'https://github.com/project-lightwell/lightwell-osv/blob/main/advisories/{{ BUG_ID }}.json'
390+
human_link: 'https://github.com/project-lightwell/lightwell-osv/blob/main/advisories/{{ .ID }}.json'
391391
link: 'https://github.com/project-lightwell/lightwell-osv/blob/main/'
392392
editable: False
393393
strict_validation: False
@@ -403,7 +403,7 @@
403403
db_prefix: ['MGASA-']
404404
accepted_ecosystems: ['Mageia']
405405
ignore_git: True
406-
human_link: 'https://advisories.mageia.org/{{ BUG_ID }}.html'
406+
human_link: 'https://advisories.mageia.org/{{ .ID }}.html'
407407
link: 'https://advisories.mageia.org/'
408408
editable: False
409409
strict_validation: False
@@ -465,7 +465,7 @@
465465
db_prefix: ['OESA-']
466466
accepted_ecosystems: ['openEuler']
467467
ignore_git: True
468-
human_link: 'https://www.openeuler.org/en/security/security-bulletins/detail/?id=openEuler-SA-{{ BUG_ID | replace("OESA-", "") }}'
468+
human_link: 'https://www.openeuler.org/en/security/security-bulletins/detail/?id=openEuler-SA-{{ .ID | replace "OESA-" "" }}'
469469
link: 'https://repo.openeuler.org/security/data/osv/'
470470
editable: False
471471
strict_validation: False
@@ -541,7 +541,7 @@
541541
db_prefix: ['RHBA-', 'RHEA-', 'RHSA-']
542542
accepted_ecosystems: ['Red Hat']
543543
ignore_git: False
544-
human_link: 'https://access.redhat.com/errata/{{ BUG_ID }}'
544+
human_link: 'https://access.redhat.com/errata/{{ .ID }}'
545545
link: 'https://security.access.redhat.com/data/osv/'
546546
editable: False
547547
strict_validation: False
@@ -556,7 +556,7 @@
556556
db_prefix: ['RLSA-']
557557
accepted_ecosystems: ['Rocky Linux']
558558
ignore_git: False
559-
human_link: 'https://errata.rockylinux.org/{{ BUG_ID }}'
559+
human_link: 'https://errata.rockylinux.org/{{ .ID }}'
560560
link: 'https://storage.googleapis.com/resf-osv-data/'
561561
editable: False
562562
strict_validation: False
@@ -571,7 +571,7 @@
571571
db_prefix: ['RXSA-']
572572
accepted_ecosystems: ['Rocky Linux']
573573
ignore_git: False
574-
human_link: 'https://errata.rockylinux.org/{{ BUG_ID }}'
574+
human_link: 'https://errata.rockylinux.org/{{ .ID }}'
575575
link: 'https://storage.googleapis.com/resf-osv-data/'
576576
editable: False
577577
strict_validation: False
@@ -588,7 +588,7 @@
588588
db_prefix: ['RUSTSEC-']
589589
accepted_ecosystems: ['crates.io']
590590
ignore_git: False
591-
human_link: 'https://rustsec.org/advisories/{{ BUG_ID }}'
591+
human_link: 'https://rustsec.org/advisories/{{ .ID }}'
592592
link: 'https://github.com/rustsec/advisory-db/blob/osv/'
593593
editable: False
594594
repo_username: 'git'
@@ -605,7 +605,7 @@
605605
db_prefix: ['openSUSE-', 'SUSE-']
606606
accepted_ecosystems: ['openSUSE', 'SUSE']
607607
ignore_git: True
608-
human_link: 'https://www.suse.com/support/update/announcement/{{ BUG_ID.split(":")[0].split("-")[2] }}/{{ BUG_ID | replace(":", "") | lower }}/'
608+
human_link: 'https://www.suse.com/support/update/announcement/{{ .ID | field ":" 0 | field "-" 2 }}/{{ .ID | replace ":" "" | lower }}/'
609609
link: 'https://ftp.suse.com/pub/projects/security/osv/'
610610
editable: False
611611
strict_validation: False
@@ -636,7 +636,7 @@
636636
db_prefix: ['UBUNTU-']
637637
accepted_ecosystems: ['Ubuntu']
638638
ignore_git: False
639-
human_link: 'https://ubuntu.com/security/{{ BUG_ID | replace("UBUNTU-", "") }}'
639+
human_link: 'https://ubuntu.com/security/{{ .ID | replace "UBUNTU-" "" }}'
640640
link: 'https://github.com/canonical/ubuntu-security-notices/blob/main/'
641641
editable: False
642642
strict_validation: False
@@ -652,7 +652,7 @@
652652
db_prefix: ['LSN-']
653653
accepted_ecosystems: ['Ubuntu']
654654
ignore_git: False
655-
human_link: 'https://ubuntu.com/security/notices/{{ BUG_ID }}'
655+
human_link: 'https://ubuntu.com/security/notices/{{ .ID }}'
656656
link: 'https://github.com/canonical/ubuntu-security-notices/blob/main/'
657657
editable: False
658658
strict_validation: True
@@ -668,7 +668,7 @@
668668
db_prefix: ['USN-']
669669
accepted_ecosystems: ['Ubuntu']
670670
ignore_git: False
671-
human_link: 'https://ubuntu.com/security/notices/{{ BUG_ID }}'
671+
human_link: 'https://ubuntu.com/security/notices/{{ .ID }}'
672672
link: 'https://github.com/canonical/ubuntu-security-notices/blob/main/'
673673
editable: False
674674
strict_validation: False
@@ -683,7 +683,7 @@
683683
db_prefix: ['GSD-']
684684
accepted_ecosystems: ['Linux']
685685
ignore_git: False
686-
human_link: 'https://data.gsd.id/{{ BUG_ID }}'
686+
human_link: 'https://data.gsd.id/{{ .ID }}'
687687
link: 'https://github.com/cloudsecurityalliance/gsd-database/blob/main/'
688688
editable: False
689689
key_path: 'OSV'

0 commit comments

Comments
 (0)