Repository navigation
fix(remediate): cover subproject dependencies when remediating a Gradle catalog #697
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { PackageURL } from 'packageurl-js' | |
|
|
||
| import analysis from './analysis.js' | ||
| import { availableProviders, match } from './provider.js' | ||
| import { discoverGradleSubprojects, findNearestBuildFile } from './providers/java_gradle.js' | ||
| import { extractRemediations, compareVersions } from './remediation.js' | ||
| import { mavenChangeKey, mavenDepsForEditSite, updateMavenVersions } from './updaters/maven_updater.js' | ||
| import { tomlChangeKey, tomlDepsForEditSite, updateTomlVersions } from './updaters/toml_updater.js' | ||
|
|
@@ -203,6 +204,33 @@ export function findManifests(targetPath) { | |
| return manifests | ||
| } | ||
|
|
||
| /** | ||
| * Resolves which manifests must be analyzed to produce remediations for `manifestPath`. | ||
| * | ||
| * Maven manifests are analyzed as-is. A Gradle version catalog is shared by every project | ||
| * in its build, while `gradle dependencies` only reports the project it runs in, so the | ||
| * catalog's owning build is expanded to all of its projects. Falls back to analyzing the | ||
| * catalog itself when the build cannot be discovered (no settings file) or has no projects. | ||
| * | ||
| * @param {string} manifestPath - the manifest being remediated | ||
| * @param {ManifestType} manifestType | ||
| * @param {Object} opts - client options | ||
| * @returns {Promise<string[]>} manifests to analyze | ||
| */ | ||
| async function analysisPathsFor(manifestPath, manifestType, opts) { | ||
| if (manifestType.label !== 'toml') { | ||
| return [manifestPath] | ||
| } | ||
|
|
||
| const buildFile = findNearestBuildFile(path.dirname(manifestPath)) | ||
| if (!buildFile) { | ||
| return [manifestPath] | ||
| } | ||
|
Comment on lines
+225
to
+228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Catalog fallback is silently skipped When a target catalog has no nearby Gradle build file, Do not route the catalog through provider matching in this state; either report the missing build as an error or implement a fallback that can actually analyze it. Also at Prompt for AI agentsIn `src/remediate.js` at lines 225-228:
**Catalog fallback is silently skipped**
When a target catalog has no nearby Gradle build file, `analysisPathsFor` returns the catalog path when no build file is found, but `match` rejects that path because the Gradle provider requires a nearby build file. The catch then skips it, so remediation returns no results instead of performing the advertised fallback or reporting that analysis is impossible.
Do not route the catalog through provider matching in this state; either report the missing build as an error or implement a fallback that can actually analyze it.
Also at `src/remediate.js:329-333`. |
||
|
|
||
| const projects = await discoverGradleSubprojects(path.dirname(buildFile), opts) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Subproject dependencies go unreported When a settings-included subproject has no local build file, or Gradle project listing fails while a root build file exists, Discover and analyze every settings-included project, including projects without local build files, and ensure a failed project listing does not silently reduce analysis to the root. Also at Prompt for AI agentsIn `src/remediate.js` at line 230:
**Subproject dependencies go unreported**
When a settings-included subproject has no local build file, or Gradle project listing fails while a root build file exists, `discoverGradleSubprojects()` returns only projects with their own build files, and `analysisPathsFor()` treats a nonempty result as complete; when listing fails, it likewise falls back to the root manifest. Dependencies configured for omitted subprojects never reach analysis, so the remediation report misses them.
Discover and analyze every settings-included project, including projects without local build files, and ensure a failed project listing does not silently reduce analysis to the root.
Also at `README.md:866`, `src/remediate.js:231`.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Gradle discovery can block remediation When gradle configuration or plugin resolution stalls while listing projects, Run project discovery with a bounded timeout and surface a clear failure rather than waiting indefinitely. Prompt for AI agentsIn `src/remediate.js` at line 230:
**Gradle discovery can block remediation**
When gradle configuration or plugin resolution stalls while listing projects, `discoverGradleSubprojects` runs Gradle synchronously before analysis, and `invokeCommand` has no timeout. A Gradle configuration or plugin-resolution process that stalls therefore blocks `runRemediation` indefinitely before it can return a report.
Run project discovery with a bounded timeout and surface a clear failure rather than waiting indefinitely. |
||
| return projects.length > 0 ? projects : [manifestPath] | ||
| } | ||
|
|
||
| /** | ||
| * Resolves a version conflict among candidates. Default: highest version wins. | ||
| * @param {string[]} versions | ||
|
|
@@ -289,17 +317,29 @@ export async function runRemediation(targetPath, options = {}) { | |
| continue | ||
| } | ||
|
|
||
| let provider | ||
| try { | ||
| provider = match(manifestPath, availableProviders, opts) | ||
| } catch { | ||
| continue | ||
| } | ||
| const providerPriority = providers ? providers.split(',').map(p => p.trim()).filter(Boolean) : undefined | ||
| const analysisPaths = await analysisPathsFor(manifestPath, manifestType, opts) | ||
|
|
||
| // A dependency visible from several projects yields one remediation per analysis. | ||
| // Keep a single entry per purl so it is reported and edited once. | ||
| /** @type {Map<string, import('./remediation.js').Remediation>} */ | ||
| const remediationsByPurl = new Map() | ||
| for (const analysisPath of analysisPaths) { | ||
| let provider | ||
| try { | ||
| provider = match(analysisPath, availableProviders, opts) | ||
| } catch { | ||
| continue | ||
| } | ||
|
|
||
| const analysisReport = await analysis.requestStack(provider, manifestPath, url, false, opts) | ||
| const extracted = extractRemediations(analysisReport, { | ||
| providerPriority: providers ? providers.split(',').map(p => p.trim()).filter(Boolean) : undefined, | ||
| }) | ||
| const analysisReport = await analysis.requestStack(provider, analysisPath, url, false, opts) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Catalog audit metadata is replaced When a version catalog is analyzed through the new project fan-out, Preserve the catalog path and content as the audit manifest while separately selecting the project build file used to generate each project's SBOM. Prompt for AI agentsIn `src/remediate.js` at line 335:
**Catalog audit metadata is replaced**
When a version catalog is analyzed through the new project fan-out, `analysis.requestStack()` receives each project build file, so it encodes that file as the source manifest and labels it `build.gradle` or `build.gradle.kts`; the backend receives no version-catalog content for the catalog remediation request.
Preserve the catalog path and content as the audit manifest while separately selecting the project build file used to generate each project's SBOM. |
||
| for (const remediation of extractRemediations(analysisReport, { providerPriority })) { | ||
| if (!remediationsByPurl.has(remediation.purl)) { | ||
| remediationsByPurl.set(remediation.purl, remediation) | ||
| } | ||
| } | ||
| } | ||
| const extracted = [...remediationsByPurl.values()].sort((a, b) => a.purl.localeCompare(b.purl)) | ||
|
Comment on lines
+325
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Conflicting remediation details disappear When analyses report different fixed versions, vulnerability details, or recommendations for the same dependency PURL, Merge or resolve all remediations for each PURL across project reports instead of retaining only the first. Prompt for AI agentsIn `src/remediate.js` at lines 325-342:
**Conflicting remediation details disappear**
When analyses report different fixed versions, vulnerability details, or recommendations for the same dependency PURL, `remediationsByPurl` keeps the first remediation and discards later reports, so project discovery order determines the fix and the merged remediation omits details from other projects; the catalog can remain vulnerable and callers receive incomplete results.
Merge or resolve all remediations for each PURL across project reports instead of retaining only the first. |
||
|
|
||
| let remediations = excludeMatchers.length === 0 | ||
| ? extracted | ||
|
|
@@ -333,7 +373,9 @@ export async function runRemediation(targetPath, options = {}) { | |
| groupId: remediation.groupId, | ||
| artifactId: remediation.artifactId, | ||
| newVersion: remediation.fixedInVersion, | ||
| reason: 'Dependency not directly declared in the manifest', | ||
| reason: manifestType.label === 'toml' | ||
| ? 'Dependency not declared in the version catalog' | ||
| : 'Dependency not directly declared in the manifest', | ||
| }) | ||
| continue | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| plugins { id 'java' } | ||
|
|
||
| group = 'com.example' | ||
| version = '1.0.0' | ||
|
|
||
| repositories { mavenCentral() } | ||
|
|
||
| // Intentionally no dependencies: exercises empty configuration blocks. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| > Task :dependencies | ||
|
|
||
| compileClasspath - Compile classpath for source set 'main'. | ||
| No dependencies | ||
|
|
||
| runtimeClasspath - Runtime classpath of source set 'main'. | ||
| No dependencies | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "bomFormat": "CycloneDX", | ||
| "specVersion": "1.6", | ||
| "version": 1, | ||
| "metadata": { | ||
| "timestamp": "2023-08-07T00:00:00.000Z", | ||
| "component": { | ||
| "group": "com.example", | ||
| "name": "empty_dependencies", | ||
| "version": "1.0.0", | ||
| "purl": "pkg:maven/com.example/empty_dependencies@1.0.0", | ||
| "type": "application", | ||
| "bom-ref": "pkg:maven/com.example/empty_dependencies@1.0.0" | ||
| }, | ||
| "tools": { | ||
| "components": [ | ||
| { | ||
| "type": "application", | ||
| "name": "trustify-da-javascript-client", | ||
| "version": "0.4.0" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "components": [], | ||
| "dependencies": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
|
|
||
| > Task :properties | ||
|
|
||
| ------------------------------------------------------------ | ||
| Root project 'empty_dependencies' | ||
| ------------------------------------------------------------ | ||
|
|
||
| allprojects: [root project 'empty_dependencies'] | ||
| group: com.example | ||
| name: empty_dependencies | ||
| version: 1.0.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,11 @@ | ||
| // app build | ||
| plugins { id 'java' } | ||
|
|
||
| group = 'com.example' | ||
| version = '1.0.0' | ||
|
|
||
| repositories { mavenCentral() } | ||
|
|
||
| dependencies { | ||
| implementation 'org.apache.commons:commons-lang3:3.16.0' | ||
| implementation 'commons-io:commons-io:2.16.1' | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| > Task :app:dependencies | ||
|
|
||
| compileClasspath - Compile classpath for source set 'main'. | ||
| +--- org.apache.commons:commons-lang3:3.16.0 | ||
| \--- commons-io:commons-io:2.16.1 | ||
|
|
||
| runtimeClasspath - Runtime classpath of source set 'main'. | ||
| +--- org.apache.commons:commons-lang3:3.16.0 | ||
| \--- commons-io:commons-io:2.16.1 | ||
|
|
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.
🟡 Medium · Sibling dependencies go unreported
When a version catalog is stored beneath a subproject that has its own build file while the build settings file is in an ancestor directory,
findNearestBuildFile()selects the subproject build file, soanalysisPathsFor()starts discovery in that subproject and cannot find the ancestor settings file. Discovery falls back to the catalog or analyzes only that subproject, leaving sibling-project dependencies out of the report.Find the build and settings context that owns the catalog before discovering projects, rather than starting from the nearest subproject build file.
Also at
src/remediate.js:230.Prompt for AI agents