Skip to content
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

Better support for transitive deps in Maven/Java (pom.xml) #35

Closed
oliverchang opened this issue Dec 12, 2022 · 13 comments
Closed

Better support for transitive deps in Maven/Java (pom.xml) #35

oliverchang opened this issue Dec 12, 2022 · 13 comments
Assignees
Labels
enhancement New feature or request priority

Comments

@oliverchang
Copy link
Collaborator

Currently pom.xml support does not support resolving the full dependency graph.

@inferno-chromium inferno-chromium changed the title Better support for pom.xml Better support for transitive deps in Maven/Java (pom.xml) Dec 12, 2022
@brampat
Copy link

brampat commented Dec 14, 2022

I can't find any documentation on the Maven integration for the scanner. Can anyone point me to it? Or is current "Maven"-support limited to letting the command-line tool read pom.xml files and scan those? Hope there will be ecosystem-native tools as well, like OWASP's Dependency Check Maven-plugin.

@abhisek
Copy link
Contributor

abhisek commented Dec 15, 2022

@oliverchang Can data from deps.dev be used to resolve transitive dependencies from direct dependencies identified from pom.xml? If so, no external tool/plugin will be required to get full list of dependencies.

@oliverchang oliverchang added the enhancement New feature or request label Dec 19, 2022
@h4sh5
Copy link

h4sh5 commented Jan 3, 2023

@h4sh5
Copy link

h4sh5 commented Jan 3, 2023

mvn dependency:list might also help (found in https://github.com/opensbom-generator/spdx-sbom-generator/search?q=mvn)

@davidrabinowitz
Copy link
Member

Also there's a need to configure maven profiles, as some project build different artifacts based on the profile, see https://github.com/GoogleCloudDataproc/spark-bigquery-connector for example

@bestbeforetoday
Copy link

bestbeforetoday commented Feb 28, 2023

Based on the suggestion by @h4sh5 above, my current work-around is to run something like this:

mvn help:effective-pom -Doutput="${TMPDIR}/pom.xml"
osv-scanner --lockfile="${TMPDIR}/pom.xml"

Edit: I found this was not really capturing all the transitive dependencies I was interested in. See my follow-up comment below.

@oliverchang
Copy link
Collaborator Author

Thanks for the suggestions all!

I think it may make sense to support a mode to use ecosystem-specifc tooling (e.g. mvn) to achieve this, but we're hoping to avoid adding additional dependnencies, and there are additional complexities around profiles/environments as pointed out in @davidrabinowitz.

We're also exploring approaches using deps.dev as well to resolve this natively without requiring external tooling. We'll keep this bug updated with any new info!

@bestbeforetoday
Copy link

I found that, since I really care about the dependencies (including transitive dependencies) that will be on the classpath at runtime, and required by any consuming packages, the approach that actually works for me is to generate a Software Bill of Materials (SBOM) and run OSV-Scanner against that SBOM instead of the POM file.

I currently have the CycloneDX Maven plugin configured in a profile within my POM file:

<profile>
  <id>sbom</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.cyclonedx</groupId>
        <artifactId>cyclonedx-maven-plugin</artifactId>
        <version>2.7.9</version>
        <configuration>
          <includeCompileScope>true</includeCompileScope>
          <includeProvidedScope>false</includeProvidedScope>
          <includeRuntimeScope>true</includeRuntimeScope>
          <includeSystemScope>false</includeSystemScope>
          <includeTestScope>false</includeTestScope>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>makeAggregateBom</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

I use this to generate the SBOM, then run OSV-Scanner run against the SBOM:

mvn --activate-profiles sbom -DskipTests install
osv-scanner --sbom=target/bom.json

If anyone has a better solution, I would really like to hear it.

@oliverchang
Copy link
Collaborator Author

We are working on this now :) This is dependent on some other changes coming along the way to help us better parse and resolve pom.xml files. Stay tuned!

@LironJit
Copy link

Hi @oliverchang, are there any news re Maven support for transitive dependencies?
Thanks in advance! :)

@cuixq
Copy link
Contributor

cuixq commented Mar 11, 2024

Hi @LironJit, we are actively working on this! The changes to resolve Maven projects are on their way. :)

@oliverchang
Copy link
Collaborator Author

@cuixq with https://github.com/google/deps.dev/tree/main/util/resolve/maven now being available, do we just need to integrate that into OSV-Scanner?

@cuixq
Copy link
Contributor

cuixq commented Apr 26, 2024

@oliverchang yes, I think so - I just started working on this!

cuixq added a commit that referenced this issue May 24, 2024
The new Maven lockfile extractor aims to resolve the full Maven
dependency graph to provide better transitive support
#35. This is an experimental
feature for now.

This PR uses deps.dev util package to parse Maven pom.xml, also calls
deps.dev API for available versions when resolving a range requirement.
cuixq added a commit that referenced this issue May 31, 2024
Issue #35

In this PR, the new Maven extractor invokes Maven resolver to compute
the transitive dependencies of a Maven pom.xml.

Since managed dependencies are not actually being depended on, they are
not in the resolved dependency graph, and thus they are not included in
the scan results.
josieang pushed a commit to josieang/osv-scanner that referenced this issue Jun 6, 2024
The new Maven lockfile extractor aims to resolve the full Maven
dependency graph to provide better transitive support
google#35. This is an experimental
feature for now.

This PR uses deps.dev util package to parse Maven pom.xml, also calls
deps.dev API for available versions when resolving a range requirement.
josieang pushed a commit to josieang/osv-scanner that referenced this issue Jun 6, 2024
Issue google#35

In this PR, the new Maven extractor invokes Maven resolver to compute
the transitive dependencies of a Maven pom.xml.

Since managed dependencies are not actually being depended on, they are
not in the resolved dependency graph, and thus they are not included in
the scan results.
cuixq added a commit that referenced this issue Jun 19, 2024
#35

In this PR, `MavenResolverExtrator` is invoked when scanning pom.xml to
report vulnerabilities in transitive dependencies.
However, the default Maven extractor is still being used with offline
mode.
@cuixq cuixq closed this as completed Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority
Projects
None yet
Development

No branches or pull requests

8 participants