Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change download file name to match the installer URL #1722

Merged
merged 2 commits into from
Nov 19, 2021

Conversation

JohnMcPMS
Copy link
Member

@JohnMcPMS JohnMcPMS commented Nov 18, 2021

Change

Change the installer download file from:

%TEMP%\WinGet\<ID>.<Version>.<Installer Extension>

to

%TEMP%\WinGet\<ID>.<Version>\<Installer URL File Stem>.<Installer Extension>

Example:

"%TEMP%\WinGet\Notepad++.Notepad++.8.1.9.1.exe"

becomes

"%TEMP%\WinGet\Notepad++.Notepad++.8.1.9.1\npp.8.1.9.1.Installer.x64.exe"

In addition, this change uses:

%TEMP%\WinGet\<ID>.<Version>\<Installer SHA256 hash>

as the name of the file before hash validation. This prevents the potential for any user input to create an executable file name since the SHA256 hash must be a hexadecimal string.

Validation

Existing regression tests and manual runs to ensure consistency for golden path.

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS JohnMcPMS requested a review from a team as a code owner November 18, 2021 03:18
std::filesystem::path filename = GetFileNameFromURI(context.Get<Execution::Data::Installer>()->Url);

// Assuming that we find a stem value in the URI, use it
if (filename.has_stem())
Copy link
Contributor

Choose a reason for hiding this comment

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

filename

If the filename happens to be ".exe", has_stem() will return true and stem() will just return ".exe", I think that's not what we wanted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you concerned about the "it already has an executable extension" or the "that is a weird file name" or the "we will create an even weirder file name"?

I don't think we care about weird file names; this is more in line with the name that the developer created (although maybe not perfectly).

As to the file having an executable extension before being hashed, you could already do that by setting PackageVersion: exe. If we want to truly avoid that then we will have to change the code a bit more to use the hash as the temp file name. But then the "rename with extension" code will have to generate the whole name. In any case I see it as defense in depth of the general case, not a true security barrier to a dedicated attacker. But if you feel strongly we can discuss it more.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel strongly about the concern. It just does not match what the comment says at the top of the method. So just wanted to confirm we are ok with the less common cases.

@yao-msft
Copy link
Contributor

Thanks for fixing! Looks good to me.

@JohnMcPMS JohnMcPMS merged commit 7775eba into microsoft:master Nov 19, 2021
@JohnMcPMS JohnMcPMS deleted the downloadchange branch November 19, 2021 00: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.

2 participants