Skip to content

Commit

Permalink
enable further deduplication by filtering out SNYK based IDs where po…
Browse files Browse the repository at this point in the history
…ssible (#930)
  • Loading branch information
NovemberTang authored Apr 15, 2024
1 parent 3d0f379 commit 28561d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/repocop/src/evaluation/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
hasDependencyTracking,
hasOldAlerts,
snykAlertToRepocopVulnerability,
snykVulnIdFilter,
} from './repository';

function evaluateRepoTestHelper(
Expand Down Expand Up @@ -973,3 +974,23 @@ describe('Deduplication of repocop vulnerabilities', () => {
expect(actual.length).toStrictEqual(2);
});
});

describe('NO RULE - Snyk vulnerability ID filter', () => {
test('Should not remove any IDs if no CVE id is present', () => {
const ids = ['SNYK-1234', 'SNYK-1235'];
const actual = snykVulnIdFilter(ids);
expect(actual).toStrictEqual(ids);
});

test('Should remove vulnerability IDs that start with Snyk, if a CVE id is present', () => {
const ids = ['SNYK-1234', 'CVE-1234'];
const actual = snykVulnIdFilter(ids);
expect(actual).toStrictEqual(['CVE-1234']);
});

test('Should return the original list if only CVEs are present', () => {
const ids = ['CVE-1234', 'CVE-1235'];
const actual = snykVulnIdFilter(ids);
expect(actual).toStrictEqual(ids);
});
});
11 changes: 10 additions & 1 deletion packages/repocop/src/evaluation/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ export function dependabotAlertToRepocopVulnerability(
};
}

export function snykVulnIdFilter(ids: string[]): string[] {
const hasCvePrefixedIssue = !!ids.find((cve) => cve.startsWith('CVE-'));
if (hasCvePrefixedIssue) {
return ids.filter((cve) => cve.startsWith('CVE-'));
} else {
return ids;
}
}

export function snykAlertToRepocopVulnerability(
fullName: string,
issue: SnykIssue,
Expand Down Expand Up @@ -460,7 +469,7 @@ export function snykAlertToRepocopVulnerability(
ecosystem: ecosystem ?? 'unknown ecosystem',
alert_issue_date: new Date(issue.attributes.created_at),
is_patchable: isPatchable,
cves: issue.attributes.problems.map((p) => p.id),
cves: snykVulnIdFilter(issue.attributes.problems.map((p) => p.id)),
};
}

Expand Down

0 comments on commit 28561d5

Please sign in to comment.