Skip to content

Potential fix for code scanning alert no. 95: Uncontrolled data used in path expression#726

Merged
alitokmen merged 1 commit into
masterfrom
alert-autofix-95
Jul 14, 2026
Merged

Potential fix for code scanning alert no. 95: Uncontrolled data used in path expression#726
alitokmen merged 1 commit into
masterfrom
alert-autofix-95

Conversation

@alitokmen

Copy link
Copy Markdown
Contributor

Potential fix for https://github.com/codehaus-cargo/cargo/security/code-scanning/95

The safest minimal fix is to validate and normalize relativeFile in FileManager.saveFile(...) before appending it to the workspace path, then enforce that the resolved target remains inside the workspace directory.

Best concrete approach (without changing intended functionality):

  • In extensions/daemon/webapp/src/main/java/org/codehaus/cargo/daemon/file/FileManager.java:
    • Add a private helper method that:
      • rejects null/empty names,
      • rejects absolute paths,
      • resolves workspaceDir.resolve(relativeFile).normalize(),
      • verifies the normalized path starts with normalized workspace dir,
      • returns the safe normalized path as string.
    • Use this helper in both saveFile(String relativeFile, InputStream inputStream) and saveFile(String handleId, String relativeFile, InputStream inputStream) so both write paths are protected.
  • Add java.nio.file.Path and java.nio.file.Paths imports.
  • Throw IllegalArgumentException on invalid path input (keeps behavior explicit and avoids silent rewriting).

This preserves existing behavior for valid relative inputs while blocking traversal and absolute-path abuse.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@alitokmen
alitokmen marked this pull request as ready for review July 14, 2026 04:42
@alitokmen
alitokmen merged commit 117e0aa into master Jul 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant