-
Notifications
You must be signed in to change notification settings - Fork 2
fix: URL validation in downloadFileFromURL for CodeQL SSRF recognition #406
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
Conversation
… 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
There was a problem hiding this 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 ofdownloadFileFromURL()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.
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
downloadFileFromURL()methodopenStream()to ensure sanitized data is usedType of Change
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:
Testing
isAllowedUrl()remains intactmain()and again indownloadFileFromURL()for CodeQL recognitionThanks 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: