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

feat(java): add support of dependency graph for jar files #5486

Open
DmitriyLewen opened this issue Nov 1, 2023 Discussed in #5469 · 8 comments
Open

feat(java): add support of dependency graph for jar files #5486

DmitriyLewen opened this issue Nov 1, 2023 Discussed in #5469 · 8 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. scan/vulnerability Issues relating to vulnerability scanning

Comments

@DmitriyLewen
Copy link
Contributor

Description

We already use full path for nested jar files - #3992.
It looks like adding a support dependency tree shouldn't be a problem.

Related Discussions:

@DmitriyLewen DmitriyLewen added kind/feature Categorizes issue or PR as related to a new feature. scan/vulnerability Issues relating to vulnerability scanning labels Nov 1, 2023
@DmitriyLewen DmitriyLewen added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Nov 1, 2023
@knqyf263
Copy link
Collaborator

knqyf263 commented Nov 2, 2023

Do you think it is feasible? AFAIK, all dependencies are flattened, and it looks hard to build the dependency tree.

@DmitriyLewen
Copy link
Contributor Author

I thought of the following logic:
Package from pom.properties (when it matches jar name) or package from MANIFEST is main package, the remaining packages (nested jars, pom.properties with other names) are dependencies of this main package.

@knqyf263
Copy link
Collaborator

knqyf263 commented Nov 6, 2023

Interesting. You mean maven doesn't flatten dependencies. Let's see how maven works.

@DmitriyLewen
Copy link
Contributor Author

I think I understand you
Do you mean that maven just copies class files inside jar file and doesn't use nested jar files?
In this case, we still can't detect these dependencies.

But in some cases, users use nested jars.
for example spring - https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html

In this case, we will find each jar file as a dependency and can create a graph with these dependencies.

But there is problem with shaded jars.
If I remember correctly, main jar contains all required jars and we can't reproduce dependency chains.

@knqyf263
Copy link
Collaborator

knqyf263 commented Nov 8, 2023

If my project depends on jackson-databind which depends on jackson-annotations, what does my JAR look like? Does it depend on how to make the JAR file?

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.15.3</version>
</dependency>

@DmitriyLewen
Copy link
Contributor Author

DmitriyLewen commented Nov 20, 2023

Sorry. I missed your message.

I think I understand what you mean.
Maven stores all required libraries in root jar file dir.
We can't build graph in this case.

I used this example to check - https://github.com/OldAl67/Samples.Sample1:

➜   mvn install
...
➜  unzip -d jar ./target/sample1-1.0-SNAPSHOT.jar | grep .jar
...
 extracting: jar/BOOT-INF/lib/spring-boot-starter-web-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-boot-starter-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-boot-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-boot-autoconfigure-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-boot-starter-logging-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/logback-classic-1.2.3.jar  
 extracting: jar/BOOT-INF/lib/logback-core-1.2.3.jar  
 extracting: jar/BOOT-INF/lib/slf4j-api-1.7.29.jar  
 extracting: jar/BOOT-INF/lib/log4j-to-slf4j-2.12.1.jar  
 extracting: jar/BOOT-INF/lib/log4j-api-2.12.1.jar  
 extracting: jar/BOOT-INF/lib/jul-to-slf4j-1.7.29.jar  
 extracting: jar/BOOT-INF/lib/jakarta.annotation-api-1.3.5.jar  
 extracting: jar/BOOT-INF/lib/spring-core-5.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-jcl-5.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/snakeyaml-1.25.jar  
 extracting: jar/BOOT-INF/lib/spring-boot-starter-json-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/jackson-databind-2.10.1.jar  
 extracting: jar/BOOT-INF/lib/jackson-annotations-2.10.1.jar  
 extracting: jar/BOOT-INF/lib/jackson-core-2.10.1.jar  
 extracting: jar/BOOT-INF/lib/jackson-datatype-jdk8-2.10.1.jar  
 extracting: jar/BOOT-INF/lib/jackson-datatype-jsr310-2.10.1.jar  
 extracting: jar/BOOT-INF/lib/jackson-module-parameter-names-2.10.1.jar  
 extracting: jar/BOOT-INF/lib/spring-boot-starter-tomcat-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/tomcat-embed-core-9.0.29.jar  
 extracting: jar/BOOT-INF/lib/tomcat-embed-el-9.0.29.jar  
 extracting: jar/BOOT-INF/lib/tomcat-embed-websocket-9.0.29.jar  
 extracting: jar/BOOT-INF/lib/spring-boot-starter-validation-2.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/jakarta.validation-api-2.0.1.jar  
 extracting: jar/BOOT-INF/lib/hibernate-validator-6.0.18.Final.jar  
 extracting: jar/BOOT-INF/lib/jboss-logging-3.4.1.Final.jar  
 extracting: jar/BOOT-INF/lib/classmate-1.5.1.jar  
 extracting: jar/BOOT-INF/lib/spring-web-5.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-beans-5.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-webmvc-5.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-aop-5.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-context-5.2.2.RELEASE.jar  
 extracting: jar/BOOT-INF/lib/spring-expression-5.2.2.RELEASE.jar  

I think we can wait for response from users.
If they need this feature - we will check their use cases and try to make it happen.

@knqyf263
Copy link
Collaborator

Maven stores all required libraries in root jar file dir.
We can't build graph in this case.

Yes, that is what I was concerned.

@DmitriyLewen DmitriyLewen removed the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Nov 21, 2023
@mcandre
Copy link

mcandre commented Jul 20, 2024

Raw JAR files are named inconsistently, and their contents are inconsistent as well. However, you could reasonably check hashes of the archive against hashes of vulnerable version artifacts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. scan/vulnerability Issues relating to vulnerability scanning
Projects
None yet
Development

No branches or pull requests

3 participants