This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27565-audit-by-artifact in repository https://gitbox.apache.org/repos/asf/camel.git
commit db167346f27a53b1be6b8c4aaae841d9610f0cae Author: Claus Ibsen <[email protected]> AuthorDate: Thu Nov 26 10:12:16 2026 +0100 CAMEL-27565: camel-report-maven-plugin - camel-report:audit can list the vulnerabilities by artifact, as camel dependency audit --by-artifact Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../src/main/docs/camel-report-maven-plugin.adoc | 18 +++++++++ .../java/org/apache/camel/maven/AuditMojo.java | 15 +++++++- .../java/org/apache/camel/maven/AuditReport.java | 44 +++++++++++++++++++--- .../org/apache/camel/maven/AuditReportTest.java | 44 +++++++++++++++++++++- 4 files changed, 113 insertions(+), 8 deletions(-) diff --git a/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc b/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc index 13b3e95da7e9..ff27368c9552 100644 --- a/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc +++ b/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc @@ -242,6 +242,23 @@ mvn camel-report:audit *FIX* is the version that fixes the JAR, or the Camel release to upgrade to for a Camel advisory, and *VIA* the dependency chain that brings it in. +To see what to upgrade, `byArtifact` lists one row per vulnerable JAR instead, as `camel dependency audit +--by-artifact`: the worst severity of its vulnerabilities, how many there are, and the version that fixes all of them +(*FIXES ALL*): + +[source,bash] +---- +mvn camel-report:audit -Dcamel.audit.byArtifact=true +---- + +[source,text] +---- +[WARNING] SEVERITY SCORE ARTIFACT CVES FIXES ALL VIA +[WARNING] CRITICAL 9.8 org.apache.commons:commons-text:1.9 1 1.10.0 +[WARNING] MEDIUM 6.5 org.apache.commons:commons-lang3:3.11 1 3.18.0 commons-text +[WARNING] 2 vulnerabilities in 2 of 3 dependencies of com.acme:orders, 1 suppressed +---- + By default the goal only reports. To fail the build, set `failOn` to a severity: [source,bash] @@ -331,6 +348,7 @@ which then shows the vulnerabilities in the Security tab of the repository: | skip | false | Skips the audit. | scopes | compile,runtime | The scopes of the dependencies to check, separated by commas. | severity | low | The lowest severity to list: critical, high, medium or low. +| byArtifact | false | Lists the vulnerabilities by artifact: one row per vulnerable JAR, with the version that fixes all of them. The JSON report then also has the artifacts. | failOn | none | Fails the build when a vulnerability at or above this severity is found (also one below `severity`): critical, high, medium, low, or none to only report them. | failOnError | false | Fails the build when the dependencies could not be checked with OSV.dev or the OSV database (not reachable, no database). Otherwise only the Apache Camel security advisories are checked then, with a warning. | offline | false | Checks the Apache Camel security advisories of the catalog only, without OSV.dev and without checking the advisories online. diff --git a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditMojo.java b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditMojo.java index 83cd19aaebe6..d79ad77eedde 100644 --- a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditMojo.java +++ b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditMojo.java @@ -97,6 +97,14 @@ public class AuditMojo extends AbstractMojo { @Parameter(property = "camel.audit.severity", defaultValue = "low") private String severity; + /** + * Lists the vulnerabilities by artifact, as {@code camel dependency audit --by-artifact}: one row per vulnerable + * JAR, with the number of vulnerabilities and the version that fixes all of them, to tell what to upgrade. The JSON + * report then also has the artifacts. + */ + @Parameter(property = "camel.audit.byArtifact", defaultValue = "false") + private boolean byArtifact; + /** * Fails the build when a vulnerability at or above this severity is found (also when it is below the severity * listed): critical, high, medium, low, or none to only report them. @@ -267,7 +275,9 @@ public class AuditMojo extends AbstractMojo { "No known vulnerabilities" + ("low".equals(listLevel) ? "" : " of " + listLevel + " severity or worse") + " in " + collected.deps().size() + " dependencies of " + name + note + more); } else { - AuditReport.table(listed).forEach(line -> getLog().warn(line)); + List<String> table = byArtifact + ? AuditReport.artifactTable(CveScan.artifactRows(listed)) : AuditReport.table(listed); + table.forEach(line -> getLog().warn(line)); getLog().warn(listed.size() + " vulnerabilities in " + CveScan.artifactRows(listed).size() + " of " + collected.deps().size() + " dependencies of " + name + note + more); } @@ -365,7 +375,8 @@ public class AuditMojo extends AbstractMojo { try { if (jsonReport != null && !jsonReport.getPath().isBlank()) { write(jsonReport.toPath(), - Jsoner.prettyPrint(AuditReport.json(name, scanned, findings, hidden, failOn, failed, osvError) + Jsoner.prettyPrint(AuditReport.json(name, scanned, findings, hidden, failOn, failed, osvError, + byArtifact) .toJson())); } if (sarifReport != null && !sarifReport.getPath().isBlank()) { diff --git a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditReport.java b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditReport.java index bcb03910ad79..1204c0c14336 100644 --- a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditReport.java +++ b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/AuditReport.java @@ -24,7 +24,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; +import org.apache.camel.catalog.cve.CveArtifact; import org.apache.camel.catalog.cve.CveFinding; import org.apache.camel.catalog.cve.CveScan; import org.apache.camel.catalog.cve.CvssScore; @@ -32,8 +34,8 @@ import org.apache.camel.util.json.JsonArray; import org.apache.camel.util.json.JsonObject; /** - * The parts of {@code camel-report:audit} that need no Maven project: the suppressions, the console table, and the JSON - * and SARIF reports. + * The parts of {@code camel-report:audit} that need no Maven project: the suppressions, the console tables, and the + * JSON and SARIF reports. */ final class AuditReport { @@ -105,6 +107,28 @@ final class AuditReport { via != null ? via : "", summary }); } } + return lines(rows, Set.of(1)); + } + + /** + * The lines of the console table by artifact, as {@code camel dependency audit --by-artifact}: what to upgrade. The + * worst severity and highest score of the vulnerabilities of each JAR, how many there are, the version that fixes + * all of them, and the dependency that brings it in. + */ + static List<String> artifactTable(List<CveArtifact> artifacts) { + List<String[]> rows = new ArrayList<>(); + rows.add(new String[] { "SEVERITY", "SCORE", "ARTIFACT", "CVES", "FIXES ALL", "VIA" }); + for (CveArtifact a : artifacts) { + String fix = a.fix() == null ? "none" : a.camelRelease() ? "Camel " + a.fix() : a.fix(); + rows.add(new String[] { + a.severity(), CvssScore.format(a.score()), a.gav(), String.valueOf(a.cves().size()), fix, + a.via() != null ? a.via() : "" }); + } + return lines(rows, Set.of(1, 3)); + } + + // the rows in columns, with the numbers of the given columns aligned right + private static List<String> lines(List<String[]> rows, Set<Integer> right) { int[] width = new int[rows.get(0).length]; for (String[] row : rows) { for (int i = 0; i < row.length; i++) { @@ -115,7 +139,7 @@ final class AuditReport { for (String[] row : rows) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < row.length; i++) { - sb.append(i == 1 ? pad(row[i], width[i], true) : pad(row[i], width[i], false)); + sb.append(pad(row[i], width[i], right.contains(i))); if (i < row.length - 1) { sb.append(" "); } @@ -130,10 +154,13 @@ final class AuditReport { return right ? spaces + text : text + spaces; } - /** The JSON report, in the shape of {@code camel dependency audit --json}, with the suppressed findings. */ + /** + * The JSON report, in the shape of {@code camel dependency audit --json}, with the suppressed findings. With + * {@code byArtifact} it also has the findings by artifact, as {@code --by-artifact}. + */ static JsonObject json( String project, int scanned, List<CveFinding> findings, Map<CveFinding, String> suppressed, String failOn, - boolean failed, String osvError) { + boolean failed, String osvError, boolean byArtifact) { JsonObject doc = new JsonObject(); doc.put("source", project); doc.put("scanned", scanned); @@ -154,6 +181,13 @@ final class AuditReport { hidden.add(row); }); doc.put("suppressedFindings", hidden); + if (byArtifact) { + List<CveArtifact> artifacts = CveScan.artifactRows(findings); + doc.put("vulnerableArtifacts", artifacts.size()); + JsonArray rowsByArtifact = new JsonArray(); + artifacts.forEach(a -> rowsByArtifact.add(a.toJson())); + doc.put("artifacts", rowsByArtifact); + } return doc; } diff --git a/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/AuditReportTest.java b/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/AuditReportTest.java index bb322b5865f4..0044702942f4 100644 --- a/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/AuditReportTest.java +++ b/catalog/camel-report-maven-plugin/src/test/java/org/apache/camel/maven/AuditReportTest.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import org.apache.camel.catalog.cve.CveFinding; +import org.apache.camel.catalog.cve.CveScan; import org.apache.camel.util.json.JsonArray; import org.apache.camel.util.json.JsonObject; import org.apache.maven.artifact.Artifact; @@ -167,7 +168,7 @@ public class AuditReportTest { Map<CveFinding, String> hidden = new LinkedHashMap<>(); hidden.put(finding("CVE-2", "LOW", "c:d:1", null), "not used"); - JsonObject doc = AuditReport.json("com.acme:app", 12, List.of(listed), hidden, "high", true, null); + JsonObject doc = AuditReport.json("com.acme:app", 12, List.of(listed), hidden, "high", true, null, false); assertEquals(12, doc.getInteger("scanned")); assertEquals(1, doc.getInteger("vulnerabilities")); @@ -175,5 +176,46 @@ public class AuditReportTest { assertTrue(doc.getBoolean("failed")); JsonObject row = (JsonObject) ((JsonArray) doc.get("suppressedFindings")).get(0); assertEquals("not used", row.getString("suppression")); + assertNull(doc.get("artifacts")); + } + + /** + * CAMEL-27565: by artifact, as camel dependency audit --by-artifact. + */ + @Test + void theTableByArtifactHasTheVersionThatFixesAll() { + String text = "org.apache.commons:commons-text:1.9"; + String lang = "org.apache.commons:commons-lang3:3.11"; + CveFinding critical = finding("CVE-2022-42889", "CRITICAL", text, "1.10.0"); + CveFinding medium = finding("CVE-2024-1", "MEDIUM", text, "1.13.0"); + CveFinding noFix = finding("CVE-2025-48924", "MEDIUM", lang, null); + noFix.gavVia().put(lang, "commons-text"); + + List<String> lines = AuditReport.artifactTable(CveScan.artifactRows(List.of(critical, medium, noFix))); + + assertEquals(3, lines.size()); + assertTrue(lines.get(0).startsWith("SEVERITY SCORE ARTIFACT")); + assertTrue(lines.get(0).contains("CVES FIXES ALL VIA")); + // the worst severity of the two, and the higher of the two fixes + assertEquals("CRITICAL 9.8 " + text + " 2 1.13.0", lines.get(1).replaceAll(" +", " ")); + assertEquals("MEDIUM 9.8 " + lang + " 1 none commons-text", lines.get(2).replaceAll(" +", " ")); + } + + @Test + void theJsonReportHasTheArtifacts() { + CveFinding critical = finding("CVE-2022-42889", "CRITICAL", "org.apache.commons:commons-text:1.9", "1.10.0"); + CveFinding medium = finding("CVE-2024-1", "MEDIUM", "org.apache.commons:commons-text:1.9", "1.13.0"); + + JsonObject doc = AuditReport.json("com.acme:app", 12, List.of(critical, medium), Map.of(), "none", false, null, + true); + + assertEquals(2, doc.getInteger("vulnerabilities")); + assertEquals(2, ((JsonArray) doc.get("findings")).size()); + assertEquals(1, doc.getInteger("vulnerableArtifacts")); + JsonObject row = (JsonObject) ((JsonArray) doc.get("artifacts")).get(0); + assertEquals("org.apache.commons:commons-text:1.9", row.getString("artifact")); + assertEquals("CRITICAL", row.getString("severity")); + assertEquals(2, row.getInteger("cveCount")); + assertEquals("1.13.0", row.getString("fixesAll")); } }
