-
Notifications
You must be signed in to change notification settings - Fork 91
feat: add CVE checking in java upgrade promotion #948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
6e02353
7df5940
761ecd7
5caa6b0
6365b6c
1a30bb6
35136d1
744fea2
a9d1dbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,188 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { UpgradeIssue, UpgradeReason } from "./type"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Octokit } from "@octokit/rest"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as semver from "semver"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Severity levels ordered by criticality (higher number = more critical) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The official doc about the severity levels can be found at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * https://docs.github.com/en/rest/security-advisories/global-advisories?apiVersion=2022-11-28 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export enum Severity { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unknown = 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| low = 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| medium = 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| high = 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| critical = 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface CVE { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ghsa_id: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: keyof typeof Severity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| html_url: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| affectedDeps: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name?: string | null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vulVersions?: string | null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| patchedVersion?: string | null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type CveUpgradeIssue = UpgradeIssue & { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reason: UpgradeReason.CVE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| severity: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export async function batchGetCVEIssues( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| coordinates: string[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<CveUpgradeIssue[]> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Split dependencies into smaller batches to avoid URL length limit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const BATCH_SIZE = 30; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const allCVEUpgradeIssues: CveUpgradeIssue[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Process dependencies in batches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (let i = 0; i < coordinates.length; i += BATCH_SIZE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const batchCoordinates = coordinates.slice(i, i + BATCH_SIZE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cveUpgradeIssues = await getCveUpgradeIssues(batchCoordinates); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allCVEUpgradeIssues.push(...cveUpgradeIssues); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+49
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const batchCoordinates = coordinates.slice(i, i + BATCH_SIZE); | |
| const cveUpgradeIssues = await getCveUpgradeIssues(batchCoordinates); | |
| allCVEUpgradeIssues.push(...cveUpgradeIssues); | |
| try { | |
| const batchCoordinates = coordinates.slice(i, i + BATCH_SIZE); | |
| const cveUpgradeIssues = await getCveUpgradeIssues(batchCoordinates); | |
| allCVEUpgradeIssues.push(...cveUpgradeIssues); | |
| } catch (error) { | |
| // Log error but continue processing other batches | |
| console.error('Error fetching CVE issues for batch:', error); | |
| } |
yezhu6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing pagination handling for GitHub Security Advisories API. The per_page: 100 parameter limits results to 100 CVEs, but if there are more than 100 matching advisories, they will be silently ignored. This could miss critical vulnerabilities.
Consider implementing pagination to fetch all results:
let allData = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await octokit.securityAdvisories.listGlobalAdvisories({
ecosystem: "maven",
affects: deps.map((p) => `${p.name}@${p.version}`),
direction: "asc",
sort: "published",
per_page: 100,
page
});
allData.push(...response.data);
hasMore = response.data.length === 100;
page++;
}| const response = await octokit.securityAdvisories.listGlobalAdvisories({ | |
| ecosystem: "maven", | |
| affects: deps.map((p) => `${p.name}@${p.version}`), | |
| direction: "asc", | |
| sort: "published", | |
| per_page: 100, | |
| }); | |
| const allCves: CVE[] = response.data | |
| let allAdvisories: typeof response.data = []; | |
| let page = 1; | |
| let hasMore = true; | |
| while (hasMore) { | |
| const response = await octokit.securityAdvisories.listGlobalAdvisories({ | |
| ecosystem: "maven", | |
| affects: deps.map((p) => `${p.name}@${p.version}`), | |
| direction: "asc", | |
| sort: "published", | |
| per_page: 100, | |
| page, | |
| }); | |
| allAdvisories.push(...response.data); | |
| hasMore = response.data.length === 100; | |
| page++; | |
| } | |
| const allCves: CVE[] = allAdvisories |
Uh oh!
There was an error while loading. Please reload this page.