Address more code quality issues

This commit is contained in:
Reinier Criel 2026-04-10 15:25:50 -07:00
parent eb9d0bba3e
commit 94f77e1330
4 changed files with 49 additions and 54 deletions

View file

@ -5,6 +5,18 @@
# Use HOME on Unix, USERPROFILE on Windows (PowerShell Core is cross-platform)
$HomeDir = if ($env:HOME) { $env:HOME } else { $env:USERPROFILE }
$DotSafeChain = if ($env:SAFE_CHAIN_DIR) { $env:SAFE_CHAIN_DIR } else { Join-Path $HomeDir ".safe-chain" }
# Validate $DotSafeChain before any filesystem operations
if (-not [System.IO.Path]::IsPathRooted($DotSafeChain)) {
Write-Host "[ERROR] SAFE_CHAIN_DIR must be an absolute path, got: $DotSafeChain" -ForegroundColor Red; exit 1
}
if ($DotSafeChain -match '\.\.') {
Write-Host "[ERROR] SAFE_CHAIN_DIR must not contain path traversal (..)" -ForegroundColor Red; exit 1
}
if ($DotSafeChain -match '^[A-Za-z]:[/\\]?$' -or $DotSafeChain -eq '/') {
Write-Host "[ERROR] SAFE_CHAIN_DIR cannot be a root or drive-root directory" -ForegroundColor Red; exit 1
}
$InstallDir = Join-Path $DotSafeChain "bin"
# Helper functions
@ -75,19 +87,6 @@ function Remove-VoltaInstallation {
# Main uninstallation
function Uninstall-SafeChain {
# Validate SAFE_CHAIN_DIR before using it to delete files
if ($env:SAFE_CHAIN_DIR) {
if (-not [System.IO.Path]::IsPathRooted($env:SAFE_CHAIN_DIR)) {
Write-Error-Custom "SAFE_CHAIN_DIR must be an absolute path, got: $($env:SAFE_CHAIN_DIR)"
}
if ($env:SAFE_CHAIN_DIR -match '\.\.') {
Write-Error-Custom "SAFE_CHAIN_DIR must not contain path traversal (..)"
}
if ($env:SAFE_CHAIN_DIR -match '^[A-Za-z]:[/\\]?$' -or $env:SAFE_CHAIN_DIR -eq '/') {
Write-Error-Custom "SAFE_CHAIN_DIR cannot be a root or drive-root directory"
}
}
Write-Info "Uninstalling safe-chain..."
# Run teardown if safe-chain is available