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: Experimental code to start java class reachability. #1480

Merged
merged 8 commits into from
Jan 13, 2025
Merged

Conversation

oliverchang
Copy link
Collaborator

This adds the beginnings of a Java reachability analyser that recursively parses class constant pools (https://docs.oracle.com/javase/specs/jvms/se22/html/jvms-4.html#jvms-4.7) for references to other classes.

The intention is to see if this can be used to exclude transitive dependencies
from vulnerability scanning completely, if they can be proven to be
unreachable.

There's still a lot of TODOs remaining (recorded in the Go source as comments). This tool currently expects
all dependency class files to be available (passed via --classpath).

@oliverchang oliverchang changed the title Experimental code to start java class reachability. feat: Experimental code to start java class reachability. Jan 7, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.93%. Comparing base (71e372e) to head (48aa3ce).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1480   +/-   ##
=======================================
  Coverage   66.93%   66.93%           
=======================================
  Files         197      197           
  Lines       18621    18621           
=======================================
  Hits        12464    12464           
  Misses       5471     5471           
  Partials      686      686           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oliverchang oliverchang requested a review from cuixq January 13, 2025 00:16
)

// ClassFile struct represents the overall structure of a Java class file.
// This only contains the fields we care about for reachability analysis.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

@oliverchang oliverchang merged commit 6cd1233 into main Jan 13, 2025
14 checks passed
@oliverchang oliverchang deleted the javareach branch January 13, 2025 05:19
oliverchang added a commit that referenced this pull request Jan 15, 2025
Followup to #1480

This adds support for analyzing uber .jar files by:

- Unpacking the .jar
- Finding the main class from META-INF/MANIFEST.MF
- Building a map of class -> Maven jar by extracting the list of Maven
dependencies from META-INF/maven/**/pom.properties files (using
OSV-Scalibr), downloading the .jar files and unpacking them to discover
.class files.
- Enumerating class reachability from the main class.
- Determining the list of reachable Maven dependencies by using the
class -> Maven jar map we built.

Usage:

```
go run ./cmd/reachable -verbose /path/to/file.jar

...
2025/01/14 13:50:52 INFO Reachable dep=io.swagger.parser.v3:swagger-parser-v3
2025/01/14 13:50:52 INFO Reachable dep=com.dorkbox:Desktop
2025/01/14 13:50:52 INFO Reachable dep=ch.qos.logback:logback-core
2025/01/14 13:50:52 INFO Reachable dep=commons-io:commons-io
2025/01/14 13:50:52 INFO Not reachable dep=com.dorkbox:NetworkUtils
2025/01/14 13:50:52 INFO Not reachable dep=io.swagger.parser.v3:swagger-parser
2025/01/14 13:50:52 INFO Not reachable dep=io.swagger.parser.v3:swagger-parser-v2-converter
2025/01/14 13:50:52 INFO Not reachable dep=com.reprezen.kaizen:openapi-parser
...
```
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.

3 participants