|
let init = { |
|
"containers": { |
|
"cna": { |
|
"affected": [ |
|
{ |
|
"product": "Product 1", |
|
"vendor": "Vendor 1", |
|
"defaultStatus": "Unknown", |
|
"versions": [ |
|
{ |
|
"version": "2.0.0", |
|
"versionType": "semver", |
|
"lessThan": "2.*", |
|
"status": "affected", |
|
"changes": [ |
|
{ |
|
"at": "2.5.2", |
|
"status": "unaffected" |
|
}, |
|
{ |
|
"at": "2.6.0", |
|
"status": "affected" |
|
}, |
|
{ |
|
"at": "2.6.3", |
|
"status": "unaffected" |
|
} |
|
] |
|
} |
|
] |
|
}, |
|
{ |
|
"product": "Product 2", |
|
"vendor": "Vendor 1", |
|
"defaultStatus": "Affected", |
|
"versions": [ |
|
{ |
|
"version": "0", |
|
"versionType": "git", |
|
"lessThan": "*", |
|
"repo": "https://github.com/example/test", |
|
"status": "unaffected", |
|
"changes": [ |
|
{ |
|
"at": "123abc...", |
|
"status": "affected" |
|
}, |
|
{ |
|
"at": "234bcd...", |
|
"status": "unaffected" |
|
}, |
|
{ |
|
"at": "567ef0...", |
|
"status": "unaffected" |
|
} |
|
] |
|
} |
|
] |
|
} |
|
], |
|
"descriptions": [ |
|
{ |
|
"lang": "en", |
|
"value": "A Sample from CVE Project" |
|
} |
|
], |
|
"problemTypes": [ |
|
{ |
|
"descriptions": [ |
|
{ |
|
"description": "Elevation of Privilege", |
|
"lang": "en", |
|
"type": "text" |
|
} |
|
] |
|
} |
|
], |
|
"providerMetadata": { |
|
"dateUpdated": "2100-06-17T00:00:00", |
|
"orgId": "f38d0000-7300-4000-92c1-6c4a2c647800", |
|
"shortName": "cveproject" |
|
}, |
|
"references": [ |
|
{ |
|
"tags": [ |
|
"related", |
|
"x_refsource_MISC" |
|
], |
|
"url": "https://mitre.org" |
|
} |
|
], |
|
"state": "PUBLISHED", |
|
"cveId": "CVE-2100-1000", |
|
"dateUpdated": "2100-06-17T00:00:00", |
|
"shortName": "cveproject", |
|
"cvssList": [] |
|
} |
|
}, |
|
"cveMetadata": { |
|
"assignerOrgId": "f38d0000-7300-4000-92c1-6c4a2c647800", |
|
"assignerShortName": "cveproject", |
|
"cveId": "CVE-2100-1000", |
|
"dateUpdated": "2100-06-17T00:00:00", |
|
"state": "PUBLISHED" |
|
}, |
|
"dataType": "CVE_RECORD", |
|
"dataVersion": "5.0" |
|
} |
|
|
|
|
|
|
|
function loadCVE(value) { |
|
var realId = value.toUpperCase().match(/(CVE-(\d{4})-(\d{1,12})(\d{3}))/); |
|
if (realId) { |
|
$('#cve').val(value.toUpperCase()); |
|
var id = realId[1]; |
|
var year = realId[2]; |
|
var bucket = realId[3]; |
|
var jsonURL = 'https://github.com/CVEProject/cvelistV5/tree/master/review_set/' + year + '/' + bucket + 'xxx/' + id + '.json' |
|
fetch('https://raw.githubusercontent.com/CVEProject/cvelistV5/master/review_set/' + year + '/' + bucket + 'xxx/' + id + '.json', { |
|
method: 'GET', |
|
credentials: 'omit', |
|
headers: { |
|
'Accept': 'application/json, text/plain, */*' |
|
}, |
|
redirect: 'error' |
|
}) |
|
.then(function (response) { |
|
if (!response.ok) { |
|
throw Error(id + ' ' + response.statusText); |
|
} |
|
return response.json(); |
|
}) |
|
.then(function (res) { |
|
if (res.containers) { |
|
update(res); |
|
|
|
} else { |
|
alert("CVE does not have correct information"); |
|
} |
|
}) |
|
.catch(function (error) { |
|
alert("Error in collecting CVE record for " + error.message); |
|
}) |
|
} else { |
|
alert("CVE number is invalid "+value); |
|
} |
|
return false; |
|
} |
|
|
|
function vparse(cve) { |
|
var rstring = '<div><ul>' |
|
for(var i=0; i<cve.containers.cna.affected.length; i++) { |
|
var p = cve.containers.cna.affected[i]; |
|
rstring += '<li class="products text-left"> '; |
|
rstring += '<strong class="vendor">' + p.vendor + '</strong> - '; |
|
rstring += ' '; |
|
rstring += '<strong class="product">' + p.product + '</strong>'; |
|
rstring += '<blockquote class="vendorproductstatus">'; |
|
rstring += '<div class="defaultStatus">Default Status: ' |
|
rstring += '<strong class="status"> ' + |
|
('defaultStatus' in p ? p.defaultStatus : 'Unknown') + |
|
'</strong> </div>' |
|
|
|
if(p.versions) { |
|
var rows = { |
|
affected: [], |
|
unaffected: [], |
|
unknown: [] |
|
}; |
|
|
|
for(v of p.versions) { |
|
if(v.lessThan) { |
|
rows[v.status].push('<code class="versionnumber">' + v.version + '</code> before <code class="versionnumber">' + v.lessThan + '</code>'); |
|
} else if(v.lessThanOrEqual) { |
|
rows[v.status].push('<code class="versionnumber"> ' + v.version + '</code> through <code class="versionnumber">' + v.lessThanOrEqual + '</code>'); |
|
} else { |
|
rows[v.status].push('<code class="versionnumber">' + v.version + '</code>'); |
|
} |
|
|
|
if (v.version) { |
|
if(v.changes) { |
|
for(c of v.changes) { |
|
rows[c.status].push('from <code class="versionnumber">' + c.at + '</code>'); |
|
} |
|
|
|
} |
|
} |
|
|
|
} |
|
for(r in rows) { |
|
if(rows[r].length) { |
|
rstring += '<strong class="status">' + r + '</strong> <ul>'; |
|
for(l in rows[r]) { |
|
rstring += '<li class="statusrow">' + rows[r][l] + '</li>'; |
|
} |
|
rstring += "</ul>"; |
|
} |
|
} |
|
rstring += '</blockquote>'; |
|
|
|
} else { |
|
console.log(p); |
|
rstring += 'No versions listed'; |
|
} |
|
rstring += '</li>' |
|
} |
|
return rstring + '</ul></div>'; |
|
} |
|
$('#tjson').on("change",function() { |
|
this.style.height = ""; |
|
this.style.height = this.scrollHeight + "px"; |
|
}); |
|
$('#tjson').val(JSON.stringify(init,null,3)).trigger('change'); |
|
function update(p) { |
|
if(!p) { |
|
if($('#cve').val()) |
|
return loadCVE($('#cve').val()); |
|
else |
|
p = JSON.parse($('#tjson').val()); |
|
} |
|
if('containers' in p) |
|
$('#pv').html(vparse(p)); |
|
$('#tjson').val(JSON.stringify(p,null,3)).trigger('change'); |
|
|
|
} |
|
if(location.hash) |
|
loadCVE(location.hash.substr(1)) |
|
else |
|
update(init); |
|
|