Skip to content

fix(java): don't inherit a relativePath POM that only matches the parent ArtifactID - #11059

Open
sueun-dev wants to merge 1 commit into
aquasecurity:mainfrom
sueun-dev:fix-java-pom-parent-groupid
Open

fix(java): don't inherit a relativePath POM that only matches the parent ArtifactID#11059
sueun-dev wants to merge 1 commit into
aquasecurity:mainfrom
sueun-dev:fix-java-pom-parent-groupid

Conversation

@sueun-dev

Copy link
Copy Markdown
Contributor

Description

tryRelativePath resolves a <parent> declared with a relativePath (or the default ../pom.xml). It first matches the local POM's ArtifactID against the declared parent, because resolveParent hasn't run yet and the GroupID/Version aren't available. After resolveParent fills those in, it re-checks the identity with artifact.Equal:

func (a artifact) Equal(o artifact) bool {
	return a.GroupID == o.GroupID || a.ArtifactID == o.ArtifactID || a.Version.String() == o.Version.String()
}

The fields are combined with ||, so Equal returns true whenever any single field matches. The ArtifactID is already guaranteed equal by the first check, so the second check can never reject anything. A ../pom.xml (or relativePath target) that shares the ArtifactID but has a different GroupID is then treated as the parent, and its dependencies/dependencyManagement are inherited — dependencies that aren't really there end up in the SBOM graph.

Example: a module declares parent com.example:parent:1.0.0, but the sibling ./parent/pom.xml is an unrelated com.unrelated:parent:9.9.9 that depends on org.phantom:phantom-lib:6.6.6. Before this change phantom-lib is reported as a dependency of the module; after it isn't.

This compares the resolved GroupID at that call site instead. The declared parent Version can still be an unevaluated property (e.g. ${revision}) there, so comparing it would reject valid parents — the parent version in property and inherit parent dependencies tests exercise exactly that — and it is left out. The now-unused artifact.Equal helper is removed.

Checklist

…nt's ArtifactID

tryRelativePath first matches the parent's ArtifactID before resolveParent
runs (GroupID/Version aren't available yet), then re-checks the full identity
afterwards. That second check used artifact.Equal, which compared the GAV
fields with OR, so it returned true whenever any single field matched. Since
the ArtifactID always matches at that point, the check could never reject a
POM, and a ../pom.xml (or relativePath) that merely shares the ArtifactID but
has a different GroupID was treated as the parent, inheriting its
dependencies and dependencyManagement into the SBOM graph.

Compare the GroupID (now resolved) instead. The declared parent Version can
still be an unevaluated property at this point, so it is left out of the
comparison. Removed the now-unused, misleading artifact.Equal helper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant