Skip to content

Conversation

@DerekRoberts
Copy link
Member

@DerekRoberts DerekRoberts commented Dec 12, 2025

Description

This PR fixes a CodeQL SSRF alert by adding URL validation and reconstruction in the downloadFileFromURL() method. CodeQL's data flow analysis requires validation to occur immediately before the network request to recognize the security guard.

Changes

  • Added URL validation check at the start of downloadFileFromURL() method
  • Reconstructs URL using whitelist host (not user-provided host)
  • Uses validated URL for openStream() to ensure sanitized data is used

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Security

Fixes CodeQL alert: Potential server-side request forgery (java/ssrf)

This is a defense-in-depth approach that ensures CodeQL's static analysis recognizes:

  1. The URL is validated immediately before network request
  2. The URL used for the request is reconstructed from trusted whitelist data
  3. No user-provided input directly flows into the network request

Testing

  • Existing URL validation in isAllowedUrl() remains intact
  • Only specific Maven repository hostnames are allowed (repo.maven.apache.org, repo1.maven.org)
  • URLs are validated twice: once in main() and again in downloadFileFromURL() for CodeQL recognition

Thanks for the PR!

Deployments, as required, will be available below:

Please create PRs in draft mode. Mark as ready to enable:

After merge, new images are deployed in:

… CodeQL

Addresses CodeQL SSRF alert (java/ssrf) by:
- Validating URL immediately before network request (CodeQL data flow recognition)
- Reconstructing URL using whitelist host instead of user-provided host
- Using validated URL for openStream() to ensure sanitized data is used

This defense-in-depth approach ensures CodeQL recognizes the URL is validated
and sanitized before being used in the network request.

Fixes CodeQL alert: Potential server-side request forgery
Copilot AI review requested due to automatic review settings December 12, 2025 00:19
@DerekRoberts DerekRoberts self-assigned this Dec 12, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances SSRF protection in the Maven wrapper downloader by adding URL validation and reconstruction directly in the downloadFileFromURL() method. The changes are designed to help CodeQL's static analysis recognize the security guard by placing validation immediately before the network operation and reconstructing the URL from trusted whitelist data rather than using user-provided input directly.

Key Changes:

  • Added validation call to isAllowedUrl() at the start of downloadFileFromURL() method
  • Implemented URL reconstruction logic that finds the matching allowlisted host and builds a new URL using trusted data
  • Modified the network operation to use the reconstructed URL instead of the user-provided URL

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Addresses three Copilot code review suggestions:

1. Port validation: Only allow default HTTPS port (443), reject non-standard ports
   to prevent SSRF attacks via non-standard ports. Always use -1 when constructing URL.

2. Optimize host lookup: Use pre-computed reverse mapping (CANONICALIZED_TO_ORIGINAL)
   instead of loop with repeated canonicalization calls.

3. Defensive null check: Kept for code clarity and safety, with explanatory comment.

These changes improve security (port validation) and performance (optimized lookup).
Remove the null check for allowedHost since isAllowedUrl() validation
guarantees the canonicalized host exists in CANONICALIZED_TO_ORIGINAL map.
The check was technically unreachable code.

This simplifies the code while maintaining the same security guarantees.
Remove the null check for allowedHost since isAllowedUrl() validation
guarantees the canonicalized host exists in CANONICALIZED_TO_ORIGINAL map.
The check was technically unreachable code.

This simplifies the code while maintaining the same security guarantees.
@DerekRoberts DerekRoberts changed the title fix: add URL validation in downloadFileFromURL for CodeQL SSRF recognition fix: URL validation in downloadFileFromURL for CodeQL SSRF recognition Dec 12, 2025
@DerekRoberts DerekRoberts merged commit be25914 into main Dec 12, 2025
19 checks passed
@DerekRoberts DerekRoberts deleted the fix/codeql-ssrf-maven-wrapper branch December 12, 2025 00:38
@github-project-automation github-project-automation bot moved this from New to Done in DevOps (NR) Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants