CVE-2024-29187 (C++, published 2024-03-24T20:15Z)
Description: value: WiX toolset lets developers create installers for Windows Installer, the Windows installation engine. When a bundle runs as SYSTEM user, Burn uses GetTempPathW which points to an insecure directory C:\Windows\Temp to drop and load multiple binaries. Standard users can hijack the binary before it's loaded in the application resulting in elevation of privileges. This vulnerability is fixed in 3.14.1 and 4.0.5.
Severity: nan (CVSS v3 base score: )
Weakness: NVD-CWE-noinfo \u2014 Insufficient Information
There is insufficient information about the issue to classify it; details are unkown or unspecified.
Repository: https://github.com/wixtoolset/wix3
Files changed:
src/DTF/Tools/SfxCA/SfxUtil.cpp
src/burn/engine/cache.cpp
Commit message: Protect elevated working folder from malicious data

When running elevated, Burn uses the Windows Temp folder as its working folder
to prevent normal processes from tampering with the files. Windows Temp does
allow non-elevated processes to write to the folder but they cannot see the
files there. Unfortunately, contrary to our belief, non-elevated processes
can read the files in Windows Temp by watching for directory changes. This
allows a malicious process to lie in wait, watching the Windows Temp folder
until a Burn process is launched elevated, then attack the working folder.
Mitigate that attack by protecting the working folder to only elevated users.

Managed custom actions also fall back to using the Windows Temp folder in
some cases and thus can be exposed in a similar fashion as an elevated Burn
process. Remove that possibility.


Vulnerable code:
        for (int i = 0; DirectoryExists(szTempDir); i++)
        if (!CreateDirectory(szTempDir, NULL))
                cchCopied = GetTempPath(cchTempDirBuf, szTempDir);
                if (cchCopied == 0 || cchCopied >= cchTempDirBuf)
                {
                        Log(hSession, L"Failed to get temp directory. Error code %d", GetLastError());
                        return false;
                }

                wchar_t* szModuleName = wcsrchr(szModule, L'\\');
                if (szModuleName == NULL) szModuleName = szModule;
                else szModuleName = szModuleName + 1;
                StringCchCat(szTempDir, cchTempDirBuf, szModuleName);
                StringCchCat(szTempDir, cchTempDirBuf, L"-");

                cchTempDir = (DWORD) wcslen(szTempDir);
                for (int i = 0; DirectoryExists(szTempDir); i++)
                {
                        swprintf_s(szTempDir + cchTempDir, cchTempDirBuf - cchTempDir, L"%d", i);
                }

                if (!CreateDirectory(szTempDir, NULL))
                {
                        Log(hSession, L"Failed to create temp directory. Error code %d", GetLastError());
                        return false;
                }
    __deref_out_z LPWSTR* psczWorkingFolder
    hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder);
    hr = DirEnsureExists(sczWorkingFolder, NULL);
        hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder);
    hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath);
    hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath);
    hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath);
        hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder);
        hr = CalculateWorkingFolder(wzBundleId, &sczFolder);
    __deref_out_z LPWSTR* psczWorkingFolder

Fixed code:
        BOOL fCreatedDirectory = FALSE;
        for (int i = 0; i < 10000 && !fCreatedDirectory; i++)
                fCreatedDirectory = ::CreateDirectory(szTempDir, NULL);
        if (!fCreatedDirectory)
                Log(hSession, L"Failed to create temp directory. Error code %d", ::GetLastError());
                return false;
static BOOL vfWorkingFolderElevated = FALSE;
    __deref_out_z LPWSTR* psczWorkingFolder,
    __out_opt BOOL* pfWorkingFolderElevated
    BOOL fElevatedWorkingFolder = FALSE;
    PSECURITY_DESCRIPTOR psd = NULL;
    LPSECURITY_ATTRIBUTES pWorkingFolderAcl = NULL;
    hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder, &fElevatedWorkingFolder);
    // If elevated, allocate the pWorkingFolderAcl to protect the working folder to only Admins and SYSTEM.
    if (fElevatedWorkingFolder)
    {
        LPCWSTR wzSddl = L"D:PAI(A;;FA;;;BA)(A;OICIIO;GA;;;BA)(A;;FA;;;SY)(A;OICIIO;GA;;;SY)";
        if (!::ConvertStringSecurityDescriptorToSecurityDescriptorW(wzSddl, SDDL_REVISION_1, &psd, NULL))
        {
            ExitWithLastError(hr, "Failed to create the security descriptor for the working folder.");
        }

        pWorkingFolderAcl = reinterpret_cast<LPSECURITY_ATTRIBUTES>(MemAlloc(sizeof(SECURITY_ATTRIBUTES), TRUE));
        pWorkingFolderAcl->nLength = sizeof(SECURITY_ATTRIBUTES);
        pWorkingFolderAcl->lpSecurityDescriptor = psd;
        pWorkingFolderAcl->bInheritHandle = FALSE;
    }

    hr = DirEnsureExists(sczWorkingFolder, pWorkingFolderAcl);
    ReleaseMem(pWorkingFolderAcl);
    if (psd)
    {
        ::LocalFree(psd);
    }
        hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder, NULL);
    hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath, NULL);
    hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath, NULL);
    hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath, NULL);
        hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder, NULL);
        hr = CalculateWorkingFolder(wzBundleId, &sczFolder, NULL);
    __deref_out_z LPWSTR* psczWorkingFolder,
    __out_opt BOOL* pfWorkingFolderElevated

        vfWorkingFolderElevated = fElevated;
    if (pfWorkingFolderElevated)
    {
        *pfWorkingFolderElevated = vfWorkingFolderElevated;
    }