-
Notifications
You must be signed in to change notification settings - Fork 2
chore: potential fix for code scanning alert no. 34: Server-side request forgery #398
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
…est forgery Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Addresses CodeQL java/polynomial-redos alert by replacing regex-based trailing dot removal with manual string operations. - Remove trailing dots using index-based approach (O(n)) - Avoids polynomial time complexity from regex on uncontrolled input - Maintains same functionality: removes trailing dots and lowercases - Prevents ReDoS (Regular Expression Denial of Service) attacks
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 addresses a Server-Side Request Forgery (SSRF) vulnerability (code scanning alert #34) in the Maven Wrapper downloader by implementing stricter hostname validation with canonicalization.
Key changes:
- Adds a
canonicalizeHost()helper method to normalize hostnames by removing trailing dots and converting to lowercase - Refactors
isAllowedUrl()to use exact hostname matching after canonicalization, preventing bypass attempts using case variations, trailing dots, or subdomain manipulation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Implements all Copilot AI suggestions for improved security and performance: 1. Performance: Pre-compute canonicalized allowed hosts in static field - Avoids recalculating on every URL validation - Uses CANONICALIZED_ALLOWED_HOSTS.contains() for O(1) lookup 2. Security: Return null for invalid hostnames instead of empty string - Prevents potential security bypass with malformed URLs - Adds explicit null check in isAllowedUrl() 3. Edge case: Handle hostnames that are all dots - Returns null when hostname consists entirely of dots - Prevents empty string from matching 4. Locale safety: Use toLowerCase(Locale.ROOT) - Ensures consistent behavior across all locales - Prevents locale-specific case conversion issues (e.g., Turkish locale)
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
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Potential fix for https://github.com/bcgov/quickstart-openshift-backends/security/code-scanning/34
The best way to fix the SSRF risk is to make the URL validation more robust and ensure that even tricky edge cases (e.g., subdomains, mixed case, trailing dots, etc.) are handled. Specifically:
isAllowedUrlmethod in.mvn/wrapper/MavenWrapperDownloader.javato:All code edits are restricted to the shown
.mvn/wrapper/MavenWrapperDownloader.javacode.Suggested fixes powered by Copilot Autofix. Review carefully before merging.
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: