Skip to content

Commit 47d2b53

Browse files
committed
fix(installer): give the Windows staging directory an owner-only DACL
install.ps1 created its staging directory with New-Item, which inherits whatever %TEMP% carries. It then ran the downloaded binary from that directory, and the binary validates its own directory and refuses inherited cross-account mutation grants. So the installer handed our own validator a directory the installer had made wrong: error: failed to stage install candidate: activation transaction I/O failed: acl-grants-cross-account-mutation to S-1-5-21-...-1003 Five reporters, three different offending identities - a CodexSandboxUsers local group, a synthesized SID recorded in .codex/cap_sid, and orphaned SIDs left by uninstalled software - all naming an ACE the installer inherited rather than anything cbm wrote. Still live on v0.10.4 (DeusData#1614). Closes DeusData#1529, DeusData#1614, DeusData#1571. cbm's own C staging already creates its directory with a protected owner-only DACL (win_mkdtemp_private_create). install.ps1 was the single path that skipped it, which is exactly why redirecting TMP/TEMP to a fresh directory worked around the failure - that workaround is now unnecessary. Applied after creation rather than atomically on purpose: the CreateDirectory overload taking a DirectorySecurity exists on Windows PowerShell 5.1 but not on PowerShell 7, and Set-Acl works on both. The directory name is unpredictable and nothing is written into it before the download, so the window is not usefully attackable. Best-effort by design: a filesystem that cannot carry a DACL must not fail the install, and if the hardening does not take, the binary's own validation still refuses - the honest outcome rather than a silent downgrade. Pure ASCII, as PowerShell 5.1 decodes a BOM-less .ps1 as ANSI. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent c0bd4bb commit 47d2b53

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎install.ps1‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,41 @@ $Url = "$BaseUrl/$Archive"
128128
$TmpDir = Join-Path ([System.IO.Path]::GetTempPath()) "cbm-install-$(Get-Random)"
129129
New-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+
131166
Write-Host "Downloading $Archive..."
132167
try {
133168
Invoke-CbmDownload -Url $Url -OutFile "$TmpDir\$Archive"

0 commit comments

Comments
 (0)