This repository consists of two exersises to resolve Java vulnerabilities in Maven:
- Exersise 1: Direct Dependency Update
- Exersise 2: Direct Dependency Removal
Its your job to go fix the issues being raised to you by your security scanners.
Clone the repository:
git clone https://github.com/endorlabs/fixing-java-vulns.git
cd fixing-java-vulns
Compile and package your project:
mvn clean install
We'll use endorctl
to scan the project for known vulnerabilities.
-
Initialize Endor Labs
Run the following command to authenticate with Endor Labs and set up your environment:./endorctl init --auth-mode <mode> --headless-mode
Replace
<mode>
with your preferred authentication mode (e.g.,google
,github
, etc.). -
Authenticate via Portal
The command will output a URL. You can command-click (⌘+click) the link in your terminal to open the authentication portal.
Log in and copy the generated token. -
Complete Setup
Paste the token back into your terminal.
You'll then be prompted to select a tenant—choose the one you just created. -
Run the Vulnerability Scan
Once authenticated and configured, scan your codebase:./endorctl scan --quick-scan
This will analyze your project for security vulnerabilities.
Exersise #1:
Your security team has identified a vulnerability https://github.com/advisories/GHSA-599f-7c49-w659 in this repository. Its your job to fix it. Okay, go!
Example: Upgrading commons-text to a secure version:
In the pom.xml
update the version of commons-text to a non-vulnerable version of commons-text. Version 1.9 has a known vulnerability.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
Research which version you should upgrade to and perform the upgrade. Then rebuild and rescan the package.
Exersise #2: Removing unused dependencies
Example: Removing unused jackson-databind:
- Search your code for Jackson usage
- If unused, remove from
pom.xml
:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.x.x</version>
</dependency>
Then verify your fixes!
After making changes:
- Rebuild the project:
mvn clean install
- Check dependencies:
mvn dependency:tree
- Re-run vulnerability scan:
./endorctl scan --quick-scan