New Github support for CVE verification.
All checks were successful
Build & Deploy Backend / build (push) Successful in 47s
Build & Deploy Backend / deploy (push) Successful in 31s

This commit is contained in:
2025-10-08 10:41:19 +08:00
parent 80c6aae9c2
commit c43b3a65c5
8 changed files with 476 additions and 20 deletions

View File

@@ -223,21 +223,28 @@ async function importCVEFeed() {
}
async function importCVEFeedBackfill() {
const now = new Date();
const resumeFrom = loadLastSyncedDate();
let startFrom = resumeFrom ? new Date(resumeFrom) : now;
const EARLIEST_CVE_DATE = new Date('2002-01-01T00:00:00.000Z');
const MAX_RANGE_DAYS = 120;
const resumeFrom = loadLastSyncedDate();
let currentStart = resumeFrom ? new Date(resumeFrom) : EARLIEST_CVE_DATE;
log(resumeFrom
? `🔁 Resuming CVE backfill from ${formatShortDate(startFrom.toISOString())}`
: `⏮️ Starting CVE backfill from today (${formatShortDate(startFrom.toISOString())})`
? `🔁 Resuming CVE backfill from ${formatShortDate(currentStart.toISOString())}`
: `⏮️ Starting CVE backfill from ${formatShortDate(EARLIEST_CVE_DATE.toISOString())}`
);
while (true) {
const end = new Date(startFrom);
const start = new Date(startFrom);
start.setDate(start.getDate() - MAX_RANGE_DAYS + 1); // 120-day window
const now = new Date();
while (currentStart < now) {
const start = new Date(currentStart);
const end = new Date(currentStart);
end.setDate(end.getDate() + MAX_RANGE_DAYS - 1); // 120-day window
// Don't go past today
if (end > now) {
end.setTime(now.getTime());
}
const startISO = start.toISOString();
const endISO = end.toISOString();
@@ -260,7 +267,7 @@ async function importCVEFeedBackfill() {
break;
}
log(`📄 Page ${++pageCount}${vulnerabilities.length} CVEs from index ${startIndex}`);
log(`📄 Page ${++pageCount}${vulnerabilities.length} CVEs from index ${startIndex} of ~${totalResults}`);
for (const vuln of vulnerabilities) {
await processCVE(vuln);
@@ -270,16 +277,20 @@ async function importCVEFeedBackfill() {
await new Promise((r) => setTimeout(r, 6000));
} while (startIndex < totalResults);
// Move the window backward
saveLastSyncedDate(start.toISOString());
startFrom = start;
// Move the window forward
currentStart.setDate(currentStart.getDate() + MAX_RANGE_DAYS);
saveLastSyncedDate(currentStart.toISOString());
log(`✅ Completed ${humanRange}. Next start: ${formatShortDate(currentStart.toISOString())}`);
} catch (err) {
log(`❌ Error during ${humanRange}: ${err.message}`);
log(`💾 Progress saved. You can restart to resume from ${formatShortDate(currentStart.toISOString())}`);
break;
}
if (start < new Date('2002-01-01')) {
log(`🛑 Reached earliest supported CVE publication date — halting backfill.`);
// Check if we've reached today
if (currentStart >= now) {
log(`🎉 Reached current date — backfill complete!`);
break;
}
}
@@ -291,9 +302,8 @@ async function importCVEFeedBackfill() {
//importCVEFeed().catch((err) => {
importCVEFeedBackfill(9000) // ~25 years (goes back to 2000)
.catch((err) => {
// Use importCVEFeed() for daily sync or importCVEFeedBackfill() for full backfill
importCVEFeedBackfill().catch((err) => {
log(`❌ Fatal error during import: ${err.message}`);
logFile.end();
});