mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge branch 'zsh-safe-chain-detection' into powershell-safe-chain-detection
This commit is contained in:
commit
823fa2936e
2 changed files with 22 additions and 56 deletions
|
|
@ -42,5 +42,6 @@
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/AikidoSec/safe-chain/issues"
|
"url": "https://github.com/AikidoSec/safe-chain/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/AikidoSec/safe-chain#readme"
|
"homepage": "https://github.com/AikidoSec/safe-chain#readme",
|
||||||
|
"packageManager": "npm@11.4.1+sha512.fcee43884166b6f9c5d04535fb95650e9708b6948a1f797eddf40e9778646778a518dfa32651b1c62ff36f4ac42becf177ca46ca27d53f24b539190c8d91802b"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,13 @@
|
||||||
|
|
||||||
function installIfCommandNotFound() {
|
function printSafeChainWarning() {
|
||||||
local cmd="$1"
|
# \033[43;30m is used to set the background color to yellow and text color to black
|
||||||
|
# \033[0m is used to reset the text formatting
|
||||||
# Check if the command already exists
|
printf "\033[43;30mWarning:\033[0m safe-chain is not available to protect you from installing malware. %s will be run directly.\n" "$1"
|
||||||
if command -v "$cmd" > /dev/null 2>&1; then
|
# \033[36m is used to set the text color to cyan
|
||||||
return 0
|
printf "Install safe-chain by using \033[36mnpm install -g @aikidosec/safe-chain\033[0m.\n"
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if Node.js version is below 18
|
|
||||||
# Safe-chain requires Node.js 18 or higher
|
|
||||||
local node_version=$(node -v | sed 's/v//' | cut -d'.' -f1)
|
|
||||||
if [ "$node_version" -lt 18 ]; then
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Command not found, ask user if they want to install safe-chain
|
|
||||||
printf "The command '%s' is not available. Do you want to install safe-chain to provide it? (y/N): " "$cmd"
|
|
||||||
read -r response
|
|
||||||
|
|
||||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
|
||||||
printf "Installing safe-chain...\n"
|
|
||||||
installSafeChain
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
printf "\nFailed to install safe-chain. Exiting.\n"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
printf "Skipping safe-chain installation. Using original command instead.\n"
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function installSafeChain() {
|
function wrapSafeChainCommand() {
|
||||||
command npm install -g @aikidosec/safe-chain
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf "------\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function wrapCommand() {
|
|
||||||
local original_cmd="$1"
|
local original_cmd="$1"
|
||||||
local aikido_cmd="$2"
|
local aikido_cmd="$2"
|
||||||
|
|
||||||
|
|
@ -52,29 +15,31 @@ function wrapCommand() {
|
||||||
# so that "$@" now contains only the arguments passed to the original command
|
# so that "$@" now contains only the arguments passed to the original command
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
installIfCommandNotFound "$aikido_cmd"
|
if command -v "$aikido_cmd" > /dev/null 2>&1; then
|
||||||
local install_result=$?
|
# If the aikido command is available, just run it with the provided arguments
|
||||||
if [ $install_result -eq 2 ]; then
|
|
||||||
command "$original_cmd" "$@"
|
|
||||||
else
|
|
||||||
"$aikido_cmd" "$@"
|
"$aikido_cmd" "$@"
|
||||||
|
else
|
||||||
|
# If the aikido command is not available, print a warning and run the original command
|
||||||
|
printSafeChainWarning "$original_cmd"
|
||||||
|
|
||||||
|
command "$original_cmd" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function npx() {
|
function npx() {
|
||||||
wrapCommand "npx" "aikido-npx" "$@"
|
wrapSafeChainCommand "npx" "aikido-npx" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function yarn() {
|
function yarn() {
|
||||||
wrapCommand "yarn" "aikido-yarn" "$@"
|
wrapSafeChainCommand "yarn" "aikido-yarn" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function pnpm() {
|
function pnpm() {
|
||||||
wrapCommand "pnpm" "aikido-pnpm" "$@"
|
wrapSafeChainCommand "pnpm" "aikido-pnpm" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function pnpx() {
|
function pnpx() {
|
||||||
wrapCommand "pnpx" "aikido-pnpx" "$@"
|
wrapSafeChainCommand "pnpx" "aikido-pnpx" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function npm() {
|
function npm() {
|
||||||
|
|
@ -85,5 +50,5 @@ function npm() {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wrapCommand "npm" "aikido-npm" "$@"
|
wrapSafeChainCommand "npm" "aikido-npm" "$@"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue