Skip to content

Validate file cache paths before accessing cached files - #6610

Open
AmirMS (AmelBawa-msft) wants to merge 3 commits into
microsoft:masterfrom
AmelBawa-msft:user/amelbawa/fix-cache-path-containment
Open

AmirMS (AmelBawa-msft) wants to merge 3 commits into
microsoft:masterfrom
AmelBawa-msft:user/amelbawa/fix-cache-path-containment

Conversation

@AmelBawa-msft

@AmelBawa-msft AmirMS (AmelBawa-msft) commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

📖 Description

FileCache::GetFile now validates the relative path from source data before using it, so cache reads, cleanup, and writes stay inside the cache directory. This covers the manifest, package version data, and icon caches.

It rejects paths that:

  • have no file name, such as . or nested/
  • are rooted, such as C:\file, C:file, or \file
  • use .. to leave the cache directory
  • have a segment that contains : or NUL, or ends in . or a space (Windows can resolve these to a different file)

Rejected paths fail with APPINSTALLER_CLI_ERROR_SOURCE_DATA_INTEGRITY_FAILURE. Valid paths are normalized for the cache; the upstream request still uses the original path.

🔗 References

🔍 Validation

✅ Checklist

🤖 AI Assistance

  • AI assistance was used and has been disclosed in this PR
  • No AI assistance was used

📋 Issue Type

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

Copilot AI 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.

🟡 Changes recommended

Unresolved validation gaps allow device aliases and normalized-away invalid components, while encoding conversion can reject valid Unicode paths.

3 open issues
What changed in this PR

This PR adds path validation to WinGet’s shared file cache to keep source-provided paths within the cache directory.

Changes:

  • Rejects escaping paths, missing filenames, and selected Windows path aliases before cache access.
  • Normalizes cache paths while preserving the original path for upstream requests.
  • Adds tests for invalid paths, external reads/deletes/writes, and valid nested paths.
File Description
src/​AppInstallerCommonCore/​FileCache.cpp Validates and normalizes paths before cache operations.
src/​AppInstallerCLITests/​FileCache.cpp Adds path-validation and cache-containment regression tests.

Review effort: Balanced

Comment thread src/AppInstallerCommonCore/FileCache.cpp Outdated
Comment thread src/AppInstallerCommonCore/FileCache.cpp Outdated
Comment thread src/AppInstallerCommonCore/FileCache.cpp Outdated
Comment thread src/AppInstallerCommonCore/FileCache.cpp
@AmelBawa-msft
AmirMS (AmelBawa-msft) marked this pull request as draft October 23, 2026 17:52

Copilot AI 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.

🟡 Changes recommended

Unicode grapheme handling still allows colons to bypass validation and retain NTFS alternate data stream syntax.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/AppInstallerCommonCore/FileCache.cpp Outdated
Comment thread src/AppInstallerCommonCore/FileCache.cpp Outdated

Copilot AI 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.

🔵 Needs a closer look

Security-sensitive Windows path handling needs native regression-test validation and final human review before approval.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

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.

4 participants