Skip to content

Conversation

@DerekRoberts
Copy link
Member

@DerekRoberts DerekRoberts commented Dec 8, 2025

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:

  1. Canonicalize the hostname before comparison, stripping any trailing dots, converting to lowercase, and rejecting any use of subdomains or alternate forms.
  2. Optionally, you could restrict to a specific path or URL prefix, but for Maven repositories the host is likely sufficient.
  3. Edit the isAllowedUrl method in .mvn/wrapper/MavenWrapperDownloader.java to:
    • Canonicalize both the incoming URL host and allowed hosts.
    • Prevent the use of subdomains (i.e., require exact match).
    • Optionally, reject the use of alternate forms of hostnames (such as Unicode).
  4. You may add a helper function to canonicalize hostnames if necessary.

All code edits are restricted to the shown .mvn/wrapper/MavenWrapperDownloader.java code.


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:

…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
@DerekRoberts DerekRoberts changed the title Potential fix for code scanning alert no. 34: Server-side request forgery chore: potential fix for code scanning alert no. 34: Server-side request forgery Dec 8, 2025
@DerekRoberts DerekRoberts marked this pull request as ready for review December 8, 2025 02:56
Copilot AI review requested due to automatic review settings December 8, 2025 02:56
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 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)
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

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.

@DerekRoberts DerekRoberts merged commit e1ac08f into main Dec 8, 2025
24 checks passed
@DerekRoberts DerekRoberts deleted the alert-autofix-34 branch December 8, 2025 03:14
@github-project-automation github-project-automation bot moved this from New to Done in DevOps (NR) Dec 8, 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