mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Code Quality
This commit is contained in:
parent
6628e1d4fd
commit
eb9d0bba3e
7 changed files with 68 additions and 3 deletions
|
|
@ -150,6 +150,19 @@ function Remove-VoltaInstallation {
|
|||
|
||||
# Main installation
|
||||
function Install-SafeChain {
|
||||
# Validate SAFE_CHAIN_DIR before using it to write 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"
|
||||
}
|
||||
}
|
||||
|
||||
# Show deprecation warning if SAFE_CHAIN_VERSION is set
|
||||
if (-not [string]::IsNullOrWhiteSpace($env:SAFE_CHAIN_VERSION)) {
|
||||
Write-Warn "SAFE_CHAIN_VERSION environment variable is deprecated."
|
||||
|
|
|
|||
|
|
@ -247,6 +247,20 @@ parse_arguments() {
|
|||
|
||||
# Main installation
|
||||
main() {
|
||||
# Validate SAFE_CHAIN_DIR before using it to write files
|
||||
if [ -n "${SAFE_CHAIN_DIR}" ]; then
|
||||
case "${SAFE_CHAIN_DIR}" in
|
||||
/*) ;; # absolute path — OK
|
||||
*) error "SAFE_CHAIN_DIR must be an absolute path, got: ${SAFE_CHAIN_DIR}" ;;
|
||||
esac
|
||||
case "${SAFE_CHAIN_DIR}" in
|
||||
*../*|*/..*|..) error "SAFE_CHAIN_DIR must not contain path traversal (..)" ;;
|
||||
esac
|
||||
if [ "${SAFE_CHAIN_DIR}" = "/" ]; then
|
||||
error "SAFE_CHAIN_DIR cannot be the root directory"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Initialize argument flags
|
||||
USE_CI_SETUP=false
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,19 @@ 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
|
||||
|
|
|
|||
|
|
@ -139,6 +139,20 @@ remove_nvm_installation() {
|
|||
|
||||
# Main uninstallation
|
||||
main() {
|
||||
# Validate SAFE_CHAIN_DIR before using it to delete files
|
||||
if [ -n "${SAFE_CHAIN_DIR}" ]; then
|
||||
case "${SAFE_CHAIN_DIR}" in
|
||||
/*) ;; # absolute path — OK
|
||||
*) error "SAFE_CHAIN_DIR must be an absolute path, got: ${SAFE_CHAIN_DIR}" ;;
|
||||
esac
|
||||
case "${SAFE_CHAIN_DIR}" in
|
||||
*../*|*/..*|..) error "SAFE_CHAIN_DIR must not contain path traversal (..)" ;;
|
||||
esac
|
||||
if [ "${SAFE_CHAIN_DIR}" = "/" ]; then
|
||||
error "SAFE_CHAIN_DIR cannot be the root directory"
|
||||
fi
|
||||
fi
|
||||
|
||||
SAFE_CHAIN_LOCATION="$DOT_SAFE_CHAIN/bin/safe-chain"
|
||||
|
||||
if [ -x "$SAFE_CHAIN_LOCATION" ]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue