Skip to content

Conversation

@DerekRoberts
Copy link
Member

@DerekRoberts DerekRoberts commented Dec 7, 2025

Potential fix for https://github.com/bcgov/quickstart-openshift-backends/security/code-scanning/35

To remediate this vulnerability, we need to properly restrict the use of the user-supplied path argument so that it cannot be used for path traversal or writing files outside a desired directory.

  • General Fix: Normalize the user input, and enforce that it resolves to a path within an intended directory (here, likely the current working directory or a specific subdirectory). Reject any input that is an absolute path, contains path traversal, or otherwise escapes that intended directory.
  • Detailed fix for this context: After constructing the jarPath, create a Path object relative to a safe base directory (such as the project root or working directory), resolve the filename, normalize the path, and check that the result is still contained within the intended base directory. If not, throw an exception and abort.
  • Location: In main(), after receiving args[1] and before using it to download the file.
  • Imports: The file already imports the required java.nio.file classes.
  • Additional Needs: Add code to determine the base directory (Path baseDir = Paths.get("").toAbsolutePath().normalize();), and compare the resolved file's parent directory with this base. Throw an error if not contained.

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:

…a used in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@DerekRoberts DerekRoberts changed the title Potential fix for code scanning alert no. 35: Uncontrolled data used in path expression chore: Potential fix for code scanning alert no. 35: Uncontrolled data used in path expression Dec 7, 2025
@DerekRoberts DerekRoberts marked this pull request as ready for review December 7, 2025 20:41
Copilot AI review requested due to automatic review settings December 7, 2025 20:41
@DerekRoberts DerekRoberts self-assigned this Dec 7, 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 addresses a path traversal vulnerability (Code Scanning Alert #35) in the Maven wrapper downloader by replacing insufficient string-based sanitization with proper path validation using the Java NIO Path API.

Key Changes:

  • Removes inadequate .replace("..", "") sanitization that could be bypassed
  • Implements proper path validation using Path.resolve() and normalize() to construct safe file paths
  • Adds startsWith() check to ensure the resolved path remains within the working directory

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

Addresses Copilot AI feedback by adding symlink resolution validation.
This prevents path traversal attacks that could bypass directory restrictions
using symlinks in parent directories.

- Resolve symlinks using toRealPath() on parent directory
- Validate resolved path remains within base directory
- Create parent directories if they don't exist
@DerekRoberts DerekRoberts merged commit a40d488 into main Dec 8, 2025
18 checks passed
@DerekRoberts DerekRoberts deleted the alert-autofix-35 branch December 8, 2025 01:45
@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