Skip to content

Commit

Permalink
Merge pull request #108 from raboof/expose-public-cve4-cves
Browse files Browse the repository at this point in the history
Expose public CVE4 cves
  • Loading branch information
raboof committed Sep 6, 2023
2 parents 3765d49 + ed2154c commit f1e1fed
Showing 1 changed file with 46 additions and 21 deletions.
67 changes: 46 additions & 21 deletions custom/asf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,73 @@ async function asfemaillists (req, res) {
}

async function asfpublicjsonlist(req, res) {
const query = [
let Document4 = res.locals.docs.cve.Document;
var r4 = await Document4.aggregate([
{ $match: { 'body.CVE_data_meta.STATE': 'PUBLIC' }},
{ $project: {
ID: '$body.CVE_data_meta.ID',
title: '$body.CVE_data_meta.TITLE',
state: '$body.CVE_data_meta.STATE',
updated: '$updatedAt',
owner: '$body.CNA_private.owner'
}}
]);

let Document5 = res.locals.docs.cve5.Document;
var r5 = await Document5.aggregate([
{ $match: { 'body.CNA_private.state': 'PUBLIC' }},
{ $project: {
ID: '$body.cveMetadata.cveId',
title: '$body.containers.cna.title',
state: '$body.CNA_private.state',
updated: '$updatedAt',
product: '$body.containers.cna.affected.product',
owner: '$body.CNA_private.owner'
}}
];

let Document4 = res.locals.docs.cve.Document;
var r4 = await Document4.aggregate(query);

let Document5 = res.locals.docs.cve5.Document;
var r5 = await Document5.aggregate(query);
]);

res.json(r4.concat(r5));
}

const nodoc = {"error":"nodoc"};
async function findCVE(Document, idField, id, cb) {
var q = {};
q[idField] = id;
Document.findOne(q, async function (err, docs) {
if (err) {
res.json(nodoc);
} else {
cb(docs);
}
});
}

async function asfpublicjson(req, res) {
var ids = req.params.id.match(RegExp('CVE-[0-9-]+', 'img'));
allerr = {"error":"nodoc"};
if (!ids || !ids[0]) {
res.json(allerr)
res.json(nodoc)
return;
}
let Document = res.locals.docs.cve5.Document;
var q = {};
q["body.cveMetadata.cveId"] = ids[0];
Document.findOne(q, async function (err, docs) {
if (err) {
res.json(allerr)
} else {
findCVE(
res.locals.docs.cve5.Document,
"body.cveMetadata.cveId",
ids[0],
async function (docs) {
if (docs && docs.body && docs.body.CNA_private && docs.body.CNA_private.state == "PUBLIC") {
res.json(docs.body)
} else {
res.json(allerr)
findCVE(
res.locals.docs.cve.Document,
"body.CVE_data_meta.ID",
ids[0],
async function (docs) {
if (docs && docs.body && docs.body.CVE_data_meta && docs.body.CVE_data_meta.STATE && docs.body.CVE_data_meta.STATE == "PUBLIC") {
res.json(docs.body)
} else {
res.json(nodoc)
}
})
}
}
});
})
}

function asflogout (req, res) {
Expand Down

0 comments on commit f1e1fed

Please sign in to comment.