@@ -128,6 +128,41 @@ $Url = "$BaseUrl/$Archive"
128128$TmpDir = Join-Path ([System.IO.Path ]::GetTempPath()) " cbm-install-$ ( Get-Random ) "
129129New-Item - ItemType Directory - Path $TmpDir - Force | Out-Null
130130
131+ # Give the staging directory a protected owner-only DACL.
132+ #
133+ # Without this it inherits whatever %TEMP% carries, and the binary we are about
134+ # to run from here validates its own directory and refuses inherited
135+ # cross-account mutation grants. That is not a hypothetical: sandboxed clients
136+ # leave ACEs on %TEMP% (a CodexSandboxUsers group, AppContainer SIDs, and
137+ # orphaned SIDs from uninstalled software have all been reported), and installs
138+ # failed with
139+ # activation transaction I/O failed: acl-grants-cross-account-mutation to S-1-5-21-...
140+ # naming an ACE the installer itself inherited. See issues 1529, 1614 and 1571.
141+ #
142+ # cbm's own C staging already creates its directory this way; install.ps1 was
143+ # the one path that did not, which is why redirecting TMP/TEMP worked around it.
144+ #
145+ # Applied after creation rather than atomically on purpose: the overload that
146+ # takes a DirectorySecurity exists on Windows PowerShell 5.1 but not on
147+ # PowerShell 7, and Set-Acl works on both. The directory name is unpredictable
148+ # and nothing is written into it until the download below, so the window is not
149+ # usefully attackable.
150+ #
151+ # Best-effort: a filesystem that cannot carry a DACL must not fail the install.
152+ # If this does not take, the binary's own validation still refuses to proceed,
153+ # which is the honest outcome rather than a silent downgrade.
154+ try {
155+ $stagingAcl = New-Object System.Security.AccessControl.DirectorySecurity
156+ $stagingAcl.SetAccessRuleProtection ($true , $false )
157+ $stagingOwner = ([System.Security.Principal.WindowsIdentity ]::GetCurrent()).User
158+ $stagingAcl.SetOwner ($stagingOwner )
159+ $stagingAcl.AddAccessRule ((New-Object System.Security.AccessControl.FileSystemAccessRule(
160+ $stagingOwner , ' FullControl' , ' ContainerInherit,ObjectInherit' , ' None' , ' Allow' )))
161+ Set-Acl - Path $TmpDir - AclObject $stagingAcl - ErrorAction Stop
162+ } catch {
163+ Write-Host " note: could not harden the staging directory ACL: $ ( $_.Exception.Message ) "
164+ }
165+
131166Write-Host " Downloading $Archive ..."
132167try {
133168 Invoke-CbmDownload - Url $Url - OutFile " $TmpDir \$Archive "
0 commit comments