Skip to content

Validate installer download destination#678

Merged
AmelBawa-msft merged 6 commits into
mainfrom
user/amelbawa/download-dir
Jul 22, 2026
Merged

Validate installer download destination#678
AmelBawa-msft merged 6 commits into
mainfrom
user/amelbawa/download-dir

Conversation

@AmelBawa-msft

@AmelBawa-msft AmelBawa-msft commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

📖 Description

Improves how the installer download path is derived from the server response.
The filename from the Content-Disposition header is now normalized the same
way as the URL-derived filenames, and a check ensures downloads always land
inside the intended installer download directory.

🔗 References

🔍 Validation

✅ Checklist

📋 Issue Type

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

@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

1 similar comment
@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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 hardens PackageParser.DownloadFileAsync to better normalize server-provided filenames (via Content-Disposition) and adds a defense-in-depth validation to ensure the resolved installer download path cannot escape the intended download directory.

Changes:

  • Normalize Content-Disposition filenames with Path.GetFileName(...) and validate the resolved download path remains within InstallerDownloadPath.
  • Add a new unit test ensuring directory traversal sequences in Content-Disposition don’t escape the download directory.
  • Improve test reliability/cleanup for zip-with-nested-installers scenarios and expand test utilities for HTTP mocking and cleanup.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs Wraps zip/nested-installer test setup/cleanup in try/finally and ensures stale resource copies are removed before running.
src/WingetCreateTests/WingetCreateTests/UnitTests/PackageParserTests.cs Adds a regression test asserting Content-Disposition traversal can’t write outside the download directory.
src/WingetCreateTests/WingetCreateTests/TestUtils.cs Adds helper overload to mock Content-Disposition filenames and improves cleanup utilities used by tests.
src/WingetCreateCore/Common/PackageParser.cs Normalizes server-provided filenames and adds a “stay within download dir” validation before writing the installer to disk.

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

Comment thread src/WingetCreateCore/Common/PackageParser.cs Outdated
@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@AmelBawa-msft

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@AmelBawa-msft
AmelBawa-msft merged commit 1aa9b66 into main Jul 22, 2026
13 checks passed
@AmelBawa-msft
AmelBawa-msft deleted the user/amelbawa/download-dir branch July 22, 2026 22:52
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