Skip to content

Commit 988d8d0

Browse files
Fix version downgrade risk in Update-ElvUI; add path traversal guard and ErrorAction Stop in Install-TukuiAddon
1 parent 8b3b15b commit 988d8d0

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/functions/private/Install-TukuiAddon.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,46 @@
2828
$tempDir = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath "Tukui_$($Addon.Slug)_Update_$([guid]::NewGuid().ToString('N'))"
2929
try {
3030
if (Test-Path $tempDir) {
31-
Remove-Item $tempDir -Recurse -Force
31+
Remove-Item $tempDir -Recurse -Force -ErrorAction Stop
3232
}
33-
$null = New-Item -ItemType Directory -Path $tempDir
33+
$null = New-Item -ItemType Directory -Path $tempDir -ErrorAction Stop
3434

3535
# Download
3636
$zipPath = Join-Path -Path $tempDir -ChildPath "$($Addon.Slug)-$($Addon.Version).zip"
3737
Write-Verbose "Downloading $($Addon.Name) $($Addon.Version) ..."
38-
Invoke-WebRequest -Uri $Addon.DownloadUrl -OutFile $zipPath
38+
Invoke-WebRequest -Uri $Addon.DownloadUrl -OutFile $zipPath -ErrorAction Stop
3939

4040
# Extract
4141
$extractPath = Join-Path -Path $tempDir -ChildPath 'extracted'
4242
Write-Verbose 'Extracting...'
43-
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
43+
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force -ErrorAction Stop
4444

4545
# Remove old addon folders matching the known directory names
46+
$normalizedAddOnsPath = [System.IO.Path]::GetFullPath($AddOnsPath)
47+
$normalizedAddOnsPath = $normalizedAddOnsPath.TrimEnd([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar) + [System.IO.Path]::DirectorySeparatorChar
4648
foreach ($dir in $Addon.Directories) {
49+
if ([string]::IsNullOrWhiteSpace($dir) -or $dir.Contains('\') -or $dir.Contains('/') -or $dir.Contains('..')) {
50+
throw "Invalid addon directory entry '$dir' returned by API."
51+
}
52+
4753
$oldPath = Join-Path -Path $AddOnsPath -ChildPath $dir
48-
if (Test-Path $oldPath) {
54+
$resolvedOldPath = [System.IO.Path]::GetFullPath($oldPath)
55+
if (-not $resolvedOldPath.StartsWith($normalizedAddOnsPath, [System.StringComparison]::OrdinalIgnoreCase)) {
56+
throw "Resolved addon directory path '$resolvedOldPath' is outside the AddOns directory."
57+
}
58+
59+
if (Test-Path -LiteralPath $resolvedOldPath) {
4960
Write-Verbose " Removing $dir"
50-
Remove-Item $oldPath -Recurse -Force
61+
Remove-Item -LiteralPath $resolvedOldPath -Recurse -Force -ErrorAction Stop
5162
}
5263
}
5364

5465
# Copy new folders
55-
$extractedFolders = Get-ChildItem -Path $extractPath -Directory
66+
$extractedFolders = Get-ChildItem -Path $extractPath -Directory -ErrorAction Stop
5667
foreach ($folder in $extractedFolders) {
5768
$destination = Join-Path -Path $AddOnsPath -ChildPath $folder.Name
5869
Write-Verbose " Installing $($folder.Name)"
59-
Copy-Item -Path $folder.FullName -Destination $destination -Recurse -Force
70+
Copy-Item -Path $folder.FullName -Destination $destination -Recurse -Force -ErrorAction Stop
6071
}
6172

6273
Write-Verbose "$($Addon.Name) $($Addon.Version) installed successfully!"

src/functions/public/Update-ElvUI.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,27 @@
5656
$addon = Get-TukuiAddon -Name elvui
5757
Write-Verbose "Latest ElvUI version: $($addon.Version)"
5858

59+
# Compare versions to prevent unintentional downgrades
60+
$installedVer = $null
61+
$latestVer = $null
62+
$canCompareVersions = $installedVersion -and
63+
[version]::TryParse($installedVersion, [ref]$installedVer) -and
64+
[version]::TryParse($addon.Version, [ref]$latestVer)
65+
66+
if ($canCompareVersions -and $installedVer -gt $latestVer -and -not $Force) {
67+
Write-Verbose "Installed version ($installedVersion) is newer than the latest available ($($addon.Version)). Use -Force to reinstall."
68+
return
69+
}
70+
5971
if ($installedVersion -eq $addon.Version -and -not $Force) {
6072
Write-Verbose 'ElvUI is already up to date. Use -Force to reinstall.'
6173
return
6274
}
6375

6476
if ($installedVersion -eq $addon.Version) {
6577
Write-Verbose "Forcing reinstall of $($addon.Version) ..."
78+
} elseif ($canCompareVersions -and $installedVer -gt $latestVer) {
79+
Write-Verbose "Forcing reinstall — installed version ($installedVersion) is newer than latest available ($($addon.Version))."
6680
} elseif ($installedVersion) {
6781
Write-Verbose "Updating from $installedVersion to $($addon.Version) ..."
6882
}

0 commit comments

Comments
 (0)