Skip to content

Ensure relative paths are rooted#6357

Open
florelis wants to merge 2 commits into
microsoft:masterfrom
florelis:relativepath
Open

Ensure relative paths are rooted#6357
florelis wants to merge 2 commits into
microsoft:masterfrom
florelis:relativepath

Conversation

@florelis

@florelis florelis commented Jul 7, 2026

Copy link
Copy Markdown
Member

📖 Description

The way we were checking that a relative path was inside a directory was wrong because it didn't check if the path was rooted. This PR fixes that.

🔗 References

🔍 Validation

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

@florelis florelis requested a review from Copilot July 7, 2026 23:29
@florelis florelis requested a review from a team as a code owner July 7, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown

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 fixes AppInstaller::Filesystem::PathEscapesBaseDirectory() so that it correctly treats any path with a root component (absolute, root-relative, drive-relative, UNC, extended-length) as escaping, instead of only checking for leading .. after lexical normalization. This hardens validation of manifest-provided nested installer paths and portable command aliases against incorrectly-accepted rooted paths.

Changes:

  • Reject rooted paths up front via std::filesystem::path::has_root_path() before lexical ./.. normalization.
  • Keep the existing lexical traversal check by rejecting normalized paths whose first component is ...
  • Expand unit tests to cover rooted path forms (absolute, UNC, \\?\), root-relative, drive-relative, plus additional relative edge cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/AppInstallerSharedLib/Filesystem.cpp Updates PathEscapesBaseDirectory() to reject any rooted path and then apply lexical ..-based escape detection.
src/AppInstallerCLITests/Filesystem.cpp Adds broader test coverage for relative/escaping cases, including absolute/UNC/root-relative/drive-relative paths.

@Trenly Trenly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a minor change, but should there be an entry in ReleaseNotes under the bug fix section?

* Fixed relative path handling for rooted paths

@florelis

florelis commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

I know this is a minor change, but should there be an entry in ReleaseNotes under the bug fix section?

* Fixed relative path handling for rooted paths

Sure. I forgot we had a section for bug fixes, and it didn't seem big enough to list it otherwise.

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.

3 participants