Skip to content

Commit 47915c1

Browse files
committed
feat: mention advisories that have warnings as part of validation
1 parent 41b425a commit 47915c1

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

scripts/validate_advisories.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
import json
44
import os
5+
import typing
56
from textwrap import indent
67

78
import jsonschema
89

10+
from typings import osv
11+
912
report_valid = False
1013

1114
with open('schema.json') as f:
@@ -16,19 +19,46 @@
1619
total = 0
1720
passed = 0
1821

22+
23+
def load_advisory_data(path_to_advisory: str) -> osv.Vulnerability:
24+
with open(path_to_advisory) as fi:
25+
return typing.cast(osv.Vulnerability, json.load(fi))
26+
27+
28+
def has_database_specific_warnings(vuln: osv.Vulnerability) -> bool:
29+
if len(vuln.get('database_specific', {}).get('warnings', [])) > 0:
30+
return True
31+
32+
for affected in vuln['affected']:
33+
if len(affected.get('database_specific', {}).get('warnings', [])) > 0:
34+
return True
35+
for ran in affected['ranges']:
36+
if len(ran.get('database_specific', {}).get('warnings', [])) > 0:
37+
return True
38+
return False
39+
40+
1941
for dirpath, _, filenames in os.walk('advisories'):
2042
for filename in filenames:
21-
advisory = os.path.join(dirpath, filename)
43+
advisory_filepath = os.path.join(dirpath, filename)
2244
total += 1
2345

2446
try:
25-
with open(advisory) as f:
26-
validator.validate(json.load(f))
27-
if report_valid:
28-
print(f'✅ {advisory} is valid')
47+
data = load_advisory_data(advisory_filepath)
48+
49+
validator.validate(data)
50+
51+
if has_database_specific_warnings(data):
52+
if 'CI' in os.environ:
53+
print(
54+
f'::warning file={advisory_filepath},line=1::has warnings that should be reviewed and patched if possible'
55+
)
56+
print(f'⚠️ {advisory_filepath} is valid with warnings')
57+
elif report_valid:
58+
print(f'✅ {advisory_filepath} is valid')
2959
passed += 1
3060
except (json.JSONDecodeError, jsonschema.ValidationError) as err:
31-
print(f'❌ {advisory} is invalid')
61+
print(f'❌ {advisory_filepath} is invalid')
3262
print(indent(str(err), prefix=' '))
3363

3464
print(f'ℹ️ validated {total} advisories, with {total - passed} invalid')

0 commit comments

Comments
 (0)