diff --git a/src/main/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandler.java b/src/main/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandler.java index 7b970285..b9a54ded 100644 --- a/src/main/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandler.java +++ b/src/main/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandler.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -104,16 +105,25 @@ private List toIssues(String ref, ArrayNode response) { } else { iTitle = title; } + Map issuesByCveSource = new HashMap<>(); affected.forEach( data -> { - var issue = - new Issue().id(id).title(iTitle).source(getSource(data)).cves(List.of(id)); + var source = getSource(data); + if (source == null) { + return; + } + var key = String.format("%s:%s", source, id); + if (issuesByCveSource.containsKey(key)) { + return; + } + var issue = new Issue().id(id).title(iTitle).source(source).cves(List.of(id)); setCvssData(issue, data); if (issue.getCvssScore() != null) { - issues.add(issue); + issuesByCveSource.put(key, issue); } }); + issues.addAll(issuesByCveSource.values()); }); return issues; diff --git a/src/test/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandlerTest.java b/src/test/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandlerTest.java index 02cd34c9..81c1c9c2 100644 --- a/src/test/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandlerTest.java +++ b/src/test/java/com/redhat/exhort/integration/providers/tpa/TpaResponseHandlerTest.java @@ -62,34 +62,91 @@ void testResponseToIssuesWithValidData() throws IOException { { "pkg:maven/org.postgresql/postgresql@42.5.0": [ { + "normative": true, + "identifier": "CVE-2022-41946", + "title": "TemporaryFolder on unix-like systems does not limit access to created files in pgjdbc", + "description": "pgjdbc is an open source postgresql JDBC Driver. In affected versions a prepared statement using either `PreparedStatement.setText(int, InputStream)` or `PreparedStatemet.setBytea(int, InputStream)` will create a temporary file if the InputStream is larger than 2k. This will create a temporary file which is readable by other users on Unix like systems, but not MacOS. On Unix like systems, the system's temporary directory is shared between all users on that system. Because of this, when files and directories are written into this directory they are, by default, readable by other users on that same system. This vulnerability does not allow other users to overwrite the contents of these directories or files. This is purely an information disclosure vulnerability. Because certain JDK file system APIs were only added in JDK 1.7, this this fix is dependent upon the version of the JDK you are using. Java 1.7 and higher users: this vulnerability is fixed in 4.5.0. Java 1.6 and lower users: no patch is available. If you are unable to patch, or are stuck running on Java 1.6, specifying the java.io.tmpdir system environment variable to a directory that is exclusively owned by the executing user will mitigate this vulnerability.", + "cwes": [ + "CWE-200", + "CWE-377" + ], + "status": { + "affected": [ + { + "uuid": "urn:uuid:595a7085-f230-42b5-9c8f-ab25939d99ed", + "identifier": "GHSA-562r-vg33-8x8h", + "document_id": "GHSA-562r-vg33-8x8h", + "title": "TemporaryFolder on unix-like systems does not limit access to created files", + "labels": { + "type": "osv", + "file": "github-reviewed/2022/11/GHSA-562r-vg33-8x8h/GHSA-562r-vg33-8x8h.json", + "importer": "osv-github", + "source": "https://github.com/github/advisory-database" + }, + "scores": [ + { + "type": "3.1", + "value": 5.8, + "severity": "medium" + } + ] + } + ] + } + }, + { + "normative": true, "identifier": "CVE-2024-1597", - "title": "SQL Injection vulnerability in PostgreSQL JDBC Driver", - "description": "The PostgreSQL JDBC driver contains a flaw that allows SQL injection attacks.", + "title": "pgjdbc SQL Injection via line comment generation", + "description": "pgjdbc, the PostgreSQL JDBC Driver, allows attacker to inject SQL if using PreferQueryMode=SIMPLE. Note this is not the default. In the default mode there is no vulnerability. A placeholder for a numeric value must be immediately preceded by a minus. There must be a second placeholder for a string value after the first placeholder; both must be on the same line. By constructing a matching string payload, the attacker can inject SQL to alter the query,bypassing the protections that parameterized queries bring against SQL Injection attacks. Versions before 42.7.2, 42.6.1, 42.5.5, 42.4.4, 42.3.9, and 42.2.28 are affected.", + "cwes": [ + "CWE-89" + ], "status": { "affected": [ { - "id": "RHSA-2024:1999", - "title": "Red Hat Security Advisory: postgresql-jdbc security update", - "source": "Red Hat Product Security", + "uuid": "urn:uuid:020c0585-32db-4949-bd41-87850add2277", + "identifier": "https://www.redhat.com/#RHSA-2024_1797", + "document_id": "RHSA-2024:1797", + "issuer": { + "id": "aa42c1b1-0591-447c-b2bb-80888252c85f", + "name": "Red Hat Product Security" + }, + "title": "Red Hat Security Advisory: Red Hat build of Quarkus 2.13.9.SP2 release and security update", + "labels": { + "importer": "redhat-csaf", + "file": "2024/rhsa-2024_1797.json", + "source": "https://security.access.redhat.com/data/csaf/v2/advisories/", + "type": "csaf" + }, "scores": [ { "type": "3.1", "value": 9.8, "severity": "critical" - }, - { - "type": "2", - "value": 8.5, - "severity": "high" } - ], - "ranges": [ + ] + }, + { + "uuid": "urn:uuid:ea8dd8f5-40a9-4817-ba11-9606f799fe6e", + "identifier": "https://www.redhat.com/#RHSA-2024_1662", + "document_id": "RHSA-2024:1662", + "issuer": { + "id": "aa42c1b1-0591-447c-b2bb-80888252c85f", + "name": "Red Hat Product Security" + }, + "title": "Red Hat Security Advisory: Red Hat build of Quarkus 3.2.11 release and security update", + "labels": { + "file": "2024/rhsa-2024_1662.json", + "importer": "redhat-csaf", + "source": "https://security.access.redhat.com/data/csaf/v2/advisories/", + "type": "csaf" + }, + "scores": [ { - "events": [ - { - "fixed": "42.5.5" - } - ] + "type": "3.1", + "value": 9.8, + "severity": "critical" } ] } @@ -109,15 +166,25 @@ void testResponseToIssuesWithValidData() throws IOException { List issues = result.issues().get("pkg:maven/org.postgresql/postgresql@42.5.0"); assertNotNull(issues); - assertEquals(1, issues.size()); + assertEquals(2, issues.size()); - Issue issue = issues.get(0); + var issue = + issues.stream().filter(i -> i.getId().equals("CVE-2024-1597")).findFirst().orElseThrow(); assertEquals("CVE-2024-1597", issue.getId()); - assertEquals("SQL Injection vulnerability in PostgreSQL JDBC Driver", issue.getTitle()); + assertEquals("pgjdbc SQL Injection via line comment generation", issue.getTitle()); assertEquals(9.8f, issue.getCvssScore()); assertEquals(Severity.CRITICAL, issue.getSeverity()); // assertNotNull(issue.getRemediation()); // assertEquals(List.of("42.5.5"), issue.getRemediation().getFixedIn()); + + issue = + issues.stream().filter(i -> i.getId().equals("CVE-2022-41946")).findFirst().orElseThrow(); + assertEquals("CVE-2022-41946", issue.getId()); + assertEquals( + "TemporaryFolder on unix-like systems does not limit access to created files in pgjdbc", + issue.getTitle()); + assertEquals(5.8f, issue.getCvssScore()); + assertEquals(Severity.MEDIUM, issue.getSeverity()); } @Test @@ -132,6 +199,12 @@ void testResponseToIssuesWithMultipleScoreTypes() throws IOException { "status": { "affected": [ { + "labels": { + "file": "2024/rhsa-2024_1662.json", + "importer": "redhat-csaf", + "source": "https://security.access.redhat.com/data/csaf/v2/advisories/", + "type": "csaf" + }, "scores": [ { "type": "4", @@ -301,6 +374,12 @@ void testResponseToIssuesWithFallbackToDescription() throws IOException { "status": { "affected": [ { + "labels": { + "file": "2024/rhsa-2024_1662.json", + "importer": "redhat-csaf", + "source": "https://security.access.redhat.com/data/csaf/v2/advisories/", + "type": "csaf" + }, "scores": [ { "type": "3.1", @@ -346,6 +425,12 @@ void testResponseToIssuesWithMultipleFixedVersions() throws IOException { "status": { "affected": [ { + "labels": { + "file": "2024/rhsa-2024_1662.json", + "importer": "redhat-csaf", + "source": "https://security.access.redhat.com/data/csaf/v2/advisories/", + "type": "csaf" + }, "scores": [ { "type": "3.1", @@ -406,6 +491,12 @@ void testResponseToIssuesWithDependencyNotInTree() throws IOException { "status": { "affected": [ { + "labels": { + "file": "2024/rhsa-2024_1662.json", + "importer": "redhat-csaf", + "source": "https://security.access.redhat.com/data/csaf/v2/advisories/", + "type": "csaf" + }, "scores": [ { "type": "3.1", diff --git a/src/test/resources/__files/reports/batch_report_all_token.json b/src/test/resources/__files/reports/batch_report_all_token.json index 9f91cb5d..e3f7edee 100644 --- a/src/test/resources/__files/reports/batch_report_all_token.json +++ b/src/test/resources/__files/reports/batch_report_all_token.json @@ -420,11 +420,11 @@ "csaf": { "summary": { "direct": 0, - "transitive": 12, - "total": 12, + "transitive": 2, + "total": 2, "dependencies": 2, - "critical": 8, - "high": 4, + "critical": 1, + "high": 1, "medium": 0, "low": 0, "remediations": 0, @@ -441,83 +441,6 @@ { "ref": "pkg:maven/org.postgresql/postgresql@42.5.0?type=jar", "issues": [ - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, { "id": "CVE-2024-1597", "title": "pgjdbc SQL Injection via line comment generation", @@ -565,39 +488,6 @@ { "ref": "pkg:maven/io.quarkus/quarkus-core@2.13.5.Final?type=jar", "issues": [ - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, { "id": "CVE-2024-2700", "title": "Quarkus-core: leak of local configuration properties into quarkus applications", diff --git a/src/test/resources/__files/reports/report_all_token.json b/src/test/resources/__files/reports/report_all_token.json index a660061b..2ded6504 100644 --- a/src/test/resources/__files/reports/report_all_token.json +++ b/src/test/resources/__files/reports/report_all_token.json @@ -419,11 +419,11 @@ "csaf": { "summary": { "direct": 0, - "transitive": 12, - "total": 12, + "transitive": 2, + "total": 2, "dependencies": 2, - "critical": 8, - "high": 4, + "critical": 1, + "high": 1, "medium": 0, "low": 0, "remediations": 0, @@ -440,83 +440,6 @@ { "ref": "pkg:maven/org.postgresql/postgresql@42.5.0?type=jar", "issues": [ - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, { "id": "CVE-2024-1597", "title": "pgjdbc SQL Injection via line comment generation", @@ -564,39 +487,6 @@ { "ref": "pkg:maven/io.quarkus/quarkus-core@2.13.5.Final?type=jar", "issues": [ - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, { "id": "CVE-2024-2700", "title": "Quarkus-core: leak of local configuration properties into quarkus applications", diff --git a/src/test/resources/__files/reports/report_default_token.json b/src/test/resources/__files/reports/report_default_token.json index 422613a8..0c4a7c1f 100644 --- a/src/test/resources/__files/reports/report_default_token.json +++ b/src/test/resources/__files/reports/report_default_token.json @@ -248,11 +248,11 @@ "csaf": { "summary": { "direct": 0, - "transitive": 12, - "total": 12, + "transitive": 2, + "total": 2, "dependencies": 2, - "critical": 8, - "high": 4, + "critical": 1, + "high": 1, "medium": 0, "low": 0, "remediations": 0, @@ -269,83 +269,6 @@ { "ref": "pkg:maven/org.postgresql/postgresql@42.5.0?type=jar", "issues": [ - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, { "id": "CVE-2024-1597", "title": "pgjdbc SQL Injection via line comment generation", @@ -393,39 +316,6 @@ { "ref": "pkg:maven/io.quarkus/quarkus-core@2.13.5.Final?type=jar", "issues": [ - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, { "id": "CVE-2024-2700", "title": "Quarkus-core: leak of local configuration properties into quarkus applications", diff --git a/src/test/resources/__files/reports/report_default_token_no_recommend.json b/src/test/resources/__files/reports/report_default_token_no_recommend.json index f94b9b9b..3e646920 100644 --- a/src/test/resources/__files/reports/report_default_token_no_recommend.json +++ b/src/test/resources/__files/reports/report_default_token_no_recommend.json @@ -218,11 +218,11 @@ "csaf": { "summary": { "direct": 0, - "transitive": 12, - "total": 12, + "transitive": 2, + "total": 2, "dependencies": 2, - "critical": 8, - "high": 4, + "critical": 1, + "high": 1, "medium": 0, "low": 0, "remediations": 0, @@ -239,83 +239,6 @@ { "ref": "pkg:maven/org.postgresql/postgresql@42.5.0?type=jar", "issues": [ - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, - { - "id": "CVE-2024-1597", - "title": "pgjdbc SQL Injection via line comment generation", - "source": "csaf", - "cvssScore": 9.8, - "severity": "CRITICAL", - "cves": [ - "CVE-2024-1597" - ], - "unique": false - }, { "id": "CVE-2024-1597", "title": "pgjdbc SQL Injection via line comment generation", @@ -362,39 +285,6 @@ { "ref": "pkg:maven/io.quarkus/quarkus-core@2.13.5.Final?type=jar", "issues": [ - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, - { - "id": "CVE-2024-2700", - "title": "Quarkus-core: leak of local configuration properties into quarkus applications", - "source": "csaf", - "cvssScore": 7.0, - "severity": "HIGH", - "cves": [ - "CVE-2024-2700" - ], - "unique": false - }, { "id": "CVE-2024-2700", "title": "Quarkus-core: leak of local configuration properties into quarkus applications",