Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ namespace AppInstaller::CLI::Workflow

// When running as admin, block attempt to repair user scope installed package.
// [NOTE:] This check is to address the security concern related to above scenario.
if (Runtime::IsRunningAsAdmin())
if (Runtime::IsRunningWithNonDefaultFullToken())
{
auto installedPackageVersion = context.Get<Execution::Data::InstalledPackageVersion>();
const std::string installedScopeString = installedPackageVersion->GetMetadata()[PackageVersionMetadata::InstalledScope];
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/UninstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@
auto packageMetadata = installedPackageVersion->GetMetadata();
auto installedType = ConvertToInstallerTypeEnum(packageMetadata[PackageVersionMetadata::InstalledType]);

// When running as admin, block attempt to uninstall user scope package to prevent EOP paths.

Check failure on line 235 in src/AppInstallerCLICore/Workflows/UninstallFlow.cpp

View workflow job for this annotation

GitHub Actions / Check Spelling

`EOP` is not a recognized word (unrecognized-spelling)
if (AdminExecutionShouldBlockUserScopePackages(installedType) && Runtime::IsRunningAsAdmin())
if (AdminExecutionShouldBlockUserScopePackages(installedType) && Runtime::IsRunningWithNonDefaultFullToken())
{
auto scopeEnum = ConvertToScopeEnum(packageMetadata[PackageVersionMetadata::InstalledScope]);
if (scopeEnum == ScopeEnum::User)
Expand Down
8 changes: 8 additions & 0 deletions src/AppInstallerSharedLib/Public/winget/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ namespace AppInstaller::Runtime
// 3. the token is not already elevated
bool IsRunningWithLimitedToken();

// Determines whether the current token is elevated.
// This only returns true for tokens that are TokenElevationTypeFull.
// Thus, it will only be true if:
// 1. UAC is enabled
// 2. the user is in the Administrators group
// 3. the token is elevated
bool IsRunningWithNonDefaultFullToken();

// Determines if the given amount of stack bytes are available.
// If the answer cannot be determined properly, the return value will be `false`.
DECLSPEC_NOINLINE bool IsStackAvailable(size_t bytes);
Expand Down
20 changes: 20 additions & 0 deletions src/AppInstallerSharedLib/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ namespace AppInstaller::Runtime
return wil::get_token_information<TOKEN_ELEVATION_TYPE>() == TokenElevationTypeLimited;
}

#ifndef AICLI_DISABLE_TEST_HOOKS
static bool* s_IsRunningWithNonDefaultFullToken_TestHook_Override = nullptr;

void TestHook_SetIsRunningWithNonDefaultFullToken_Override(bool* value)
{
s_IsRunningWithNonDefaultFullToken_TestHook_Override = value;
}
#endif

bool IsRunningWithNonDefaultFullToken()
{
#ifndef AICLI_DISABLE_TEST_HOOKS
if (s_IsRunningWithNonDefaultFullToken_TestHook_Override)
{
return *s_IsRunningWithNonDefaultFullToken_TestHook_Override;
}
#endif
return wil::get_token_information<TOKEN_ELEVATION_TYPE>() == TokenElevationTypeFull;
}
Comment on lines +222 to +240

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we bringing in the test hooks but not the tests?


DECLSPEC_NOINLINE bool IsStackAvailable(size_t bytes)
{
// https://devblogs.microsoft.com/oldnewthing/20200610-00/?p=103855
Expand Down
Loading