@aikidosec/safe-chain 1.1.10 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -35
- package/bin/aikido-bun.js +4 -2
- package/bin/aikido-bunx.js +4 -2
- package/bin/aikido-npm.js +4 -2
- package/bin/aikido-npx.js +4 -2
- package/bin/aikido-pip.js +5 -3
- package/bin/aikido-pip3.js +5 -3
- package/bin/aikido-pnpm.js +4 -2
- package/bin/aikido-pnpx.js +4 -2
- package/bin/aikido-python.js +15 -13
- package/bin/aikido-python3.js +15 -13
- package/bin/aikido-uv.js +5 -3
- package/bin/aikido-yarn.js +4 -2
- package/bin/safe-chain.js +106 -10
- package/docs/banner.svg +151 -0
- package/docs/npm-to-binary-migration.md +89 -0
- package/package.json +5 -4
- package/src/packagemanager/pip/runPipCommand.js +25 -0
- package/src/registryProxy/mitmRequestHandler.js +8 -4
- package/src/shell-integration/helpers.js +73 -12
- package/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh +2 -2
- package/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd +2 -2
- package/src/shell-integration/setup-ci.js +26 -9
- package/src/shell-integration/setup.js +17 -5
- package/src/shell-integration/startup-scripts/include-python/init-fish.fish +45 -43
- package/src/shell-integration/startup-scripts/include-python/init-posix.sh +36 -39
- package/src/shell-integration/startup-scripts/include-python/init-pwsh.ps1 +65 -61
- package/src/shell-integration/startup-scripts/init-fish.fish +39 -38
- package/src/shell-integration/startup-scripts/init-posix.sh +30 -34
- package/src/shell-integration/startup-scripts/init-pwsh.ps1 +42 -38
|
@@ -8,6 +8,20 @@ import { fileURLToPath } from "url";
|
|
|
8
8
|
import { includePython } from "../config/cliArguments.js";
|
|
9
9
|
import { ECOSYSTEM_PY } from "../config/settings.js";
|
|
10
10
|
|
|
11
|
+
/** @type {string} */
|
|
12
|
+
// This checks the current file's dirname in a way that's compatible with:
|
|
13
|
+
// - Modulejs (import.meta.url)
|
|
14
|
+
// - ES modules (__dirname)
|
|
15
|
+
// This is needed because safe-chain's npm package is built using ES modules,
|
|
16
|
+
// but building the binaries requires commonjs.
|
|
17
|
+
let dirname;
|
|
18
|
+
if (import.meta.url) {
|
|
19
|
+
const filename = fileURLToPath(import.meta.url);
|
|
20
|
+
dirname = path.dirname(filename);
|
|
21
|
+
} else {
|
|
22
|
+
dirname = __dirname;
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
/**
|
|
12
26
|
* Loops over the detected shells and calls the setup function for each.
|
|
13
27
|
*/
|
|
@@ -19,6 +33,7 @@ export async function setupCi() {
|
|
|
19
33
|
ui.emptyLine();
|
|
20
34
|
|
|
21
35
|
const shimsDir = path.join(os.homedir(), ".safe-chain", "shims");
|
|
36
|
+
const binDir = path.join(os.homedir(), ".safe-chain", "bin");
|
|
22
37
|
// Create the shims directory if it doesn't exist
|
|
23
38
|
if (!fs.existsSync(shimsDir)) {
|
|
24
39
|
fs.mkdirSync(shimsDir, { recursive: true });
|
|
@@ -26,7 +41,7 @@ export async function setupCi() {
|
|
|
26
41
|
|
|
27
42
|
createShims(shimsDir);
|
|
28
43
|
ui.writeInformation(`Created shims in ${shimsDir}`);
|
|
29
|
-
modifyPathForCi(shimsDir);
|
|
44
|
+
modifyPathForCi(shimsDir, binDir);
|
|
30
45
|
ui.writeInformation(`Added shims directory to PATH for CI environments.`);
|
|
31
46
|
}
|
|
32
47
|
|
|
@@ -37,10 +52,8 @@ export async function setupCi() {
|
|
|
37
52
|
*/
|
|
38
53
|
function createUnixShims(shimsDir) {
|
|
39
54
|
// Read the template file
|
|
40
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
41
|
-
const __dirname = path.dirname(__filename);
|
|
42
55
|
const templatePath = path.resolve(
|
|
43
|
-
|
|
56
|
+
dirname,
|
|
44
57
|
"path-wrappers",
|
|
45
58
|
"templates",
|
|
46
59
|
"unix-wrapper.template.sh"
|
|
@@ -78,10 +91,8 @@ function createUnixShims(shimsDir) {
|
|
|
78
91
|
*/
|
|
79
92
|
function createWindowsShims(shimsDir) {
|
|
80
93
|
// Read the template file
|
|
81
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
82
|
-
const __dirname = path.dirname(__filename);
|
|
83
94
|
const templatePath = path.resolve(
|
|
84
|
-
|
|
95
|
+
dirname,
|
|
85
96
|
"path-wrappers",
|
|
86
97
|
"templates",
|
|
87
98
|
"windows-wrapper.template.cmd"
|
|
@@ -124,13 +135,18 @@ function createShims(shimsDir) {
|
|
|
124
135
|
|
|
125
136
|
/**
|
|
126
137
|
* @param {string} shimsDir
|
|
138
|
+
* @param {string} binDir
|
|
127
139
|
*
|
|
128
140
|
* @returns {void}
|
|
129
141
|
*/
|
|
130
|
-
function modifyPathForCi(shimsDir) {
|
|
142
|
+
function modifyPathForCi(shimsDir, binDir) {
|
|
131
143
|
if (process.env.GITHUB_PATH) {
|
|
132
144
|
// In GitHub Actions, append the shims directory to GITHUB_PATH
|
|
133
|
-
fs.appendFileSync(
|
|
145
|
+
fs.appendFileSync(
|
|
146
|
+
process.env.GITHUB_PATH,
|
|
147
|
+
shimsDir + os.EOL + binDir + os.EOL,
|
|
148
|
+
"utf-8"
|
|
149
|
+
);
|
|
134
150
|
ui.writeInformation(
|
|
135
151
|
`Added shims directory to GITHUB_PATH for GitHub Actions.`
|
|
136
152
|
);
|
|
@@ -141,6 +157,7 @@ function modifyPathForCi(shimsDir) {
|
|
|
141
157
|
// ##vso[task.prependpath]/path/to/add
|
|
142
158
|
// Logging this to stdout will cause the Azure Pipelines agent to pick it up
|
|
143
159
|
ui.writeInformation("##vso[task.prependpath]" + shimsDir);
|
|
160
|
+
ui.writeInformation("##vso[task.prependpath]" + binDir);
|
|
144
161
|
}
|
|
145
162
|
}
|
|
146
163
|
|
|
@@ -5,8 +5,22 @@ import { knownAikidoTools, getPackageManagerList } from "./helpers.js";
|
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import os from "os";
|
|
7
7
|
import path from "path";
|
|
8
|
-
import { fileURLToPath } from "url";
|
|
9
8
|
import { includePython } from "../config/cliArguments.js";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
|
|
11
|
+
/** @type {string} */
|
|
12
|
+
// This checks the current file's dirname in a way that's compatible with:
|
|
13
|
+
// - Modulejs (import.meta.url)
|
|
14
|
+
// - ES modules (__dirname)
|
|
15
|
+
// This is needed because safe-chain's npm package is built using ES modules,
|
|
16
|
+
// but building the binaries requires commonjs.
|
|
17
|
+
let dirname;
|
|
18
|
+
if (import.meta.url) {
|
|
19
|
+
const filename = fileURLToPath(import.meta.url);
|
|
20
|
+
dirname = path.dirname(filename);
|
|
21
|
+
} else {
|
|
22
|
+
dirname = __dirname;
|
|
23
|
+
}
|
|
10
24
|
|
|
11
25
|
/**
|
|
12
26
|
* Loops over the detected shells and calls the setup function for each.
|
|
@@ -103,10 +117,8 @@ function copyStartupFiles() {
|
|
|
103
117
|
}
|
|
104
118
|
|
|
105
119
|
// Use absolute path for source
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
const sourcePath = path.resolve(
|
|
109
|
-
__dirname,
|
|
120
|
+
const sourcePath = path.join(
|
|
121
|
+
dirname,
|
|
110
122
|
includePython() ? "startup-scripts/include-python" : "startup-scripts",
|
|
111
123
|
file
|
|
112
124
|
);
|
|
@@ -1,57 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
set original_cmd $argv[1]
|
|
3
|
-
|
|
4
|
-
# Fish equivalent of ANSI color codes: yellow background, black text for "Warning:"
|
|
5
|
-
set_color -b yellow black
|
|
6
|
-
printf "Warning:"
|
|
7
|
-
set_color normal
|
|
8
|
-
printf " safe-chain is not available to protect you from installing malware. %s will run without it.\n" $original_cmd
|
|
9
|
-
|
|
10
|
-
# Cyan text for the install command
|
|
11
|
-
printf "Install safe-chain by using "
|
|
12
|
-
set_color cyan
|
|
13
|
-
printf "npm install -g @aikidosec/safe-chain"
|
|
14
|
-
set_color normal
|
|
15
|
-
printf ".\n"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
function wrapSafeChainCommand
|
|
19
|
-
set original_cmd $argv[1]
|
|
20
|
-
set aikido_cmd $argv[2]
|
|
21
|
-
set cmd_args $argv[3..-1]
|
|
22
|
-
|
|
23
|
-
if type -q $aikido_cmd
|
|
24
|
-
# If the aikido command is available, just run it with the provided arguments
|
|
25
|
-
$aikido_cmd $cmd_args
|
|
26
|
-
else
|
|
27
|
-
# If the aikido command is not available, print a warning and run the original command
|
|
28
|
-
printSafeChainWarning $original_cmd
|
|
29
|
-
command $original_cmd $cmd_args
|
|
30
|
-
end
|
|
31
|
-
end
|
|
1
|
+
set -gx PATH $PATH $HOME/.safe-chain/bin
|
|
32
2
|
|
|
33
3
|
function npx
|
|
34
|
-
wrapSafeChainCommand "npx"
|
|
4
|
+
wrapSafeChainCommand "npx" $argv
|
|
35
5
|
end
|
|
36
6
|
|
|
37
7
|
function yarn
|
|
38
|
-
wrapSafeChainCommand "yarn"
|
|
8
|
+
wrapSafeChainCommand "yarn" $argv
|
|
39
9
|
end
|
|
40
10
|
|
|
41
11
|
function pnpm
|
|
42
|
-
wrapSafeChainCommand "pnpm"
|
|
12
|
+
wrapSafeChainCommand "pnpm" $argv
|
|
43
13
|
end
|
|
44
14
|
|
|
45
15
|
function pnpx
|
|
46
|
-
wrapSafeChainCommand "pnpx"
|
|
16
|
+
wrapSafeChainCommand "pnpx" $argv
|
|
47
17
|
end
|
|
48
18
|
|
|
49
19
|
function bun
|
|
50
|
-
wrapSafeChainCommand "bun"
|
|
20
|
+
wrapSafeChainCommand "bun" $argv
|
|
51
21
|
end
|
|
52
22
|
|
|
53
23
|
function bunx
|
|
54
|
-
wrapSafeChainCommand "bunx"
|
|
24
|
+
wrapSafeChainCommand "bunx" $argv
|
|
55
25
|
end
|
|
56
26
|
|
|
57
27
|
function npm
|
|
@@ -66,27 +36,59 @@ function npm
|
|
|
66
36
|
end
|
|
67
37
|
end
|
|
68
38
|
|
|
69
|
-
wrapSafeChainCommand "npm"
|
|
39
|
+
wrapSafeChainCommand "npm" $argv
|
|
70
40
|
end
|
|
71
41
|
|
|
42
|
+
|
|
72
43
|
function pip
|
|
73
|
-
wrapSafeChainCommand "pip"
|
|
44
|
+
wrapSafeChainCommand "pip" $argv
|
|
74
45
|
end
|
|
75
46
|
|
|
76
47
|
function pip3
|
|
77
|
-
wrapSafeChainCommand "pip3"
|
|
48
|
+
wrapSafeChainCommand "pip3" $argv
|
|
78
49
|
end
|
|
79
50
|
|
|
80
51
|
function uv
|
|
81
|
-
wrapSafeChainCommand "uv"
|
|
52
|
+
wrapSafeChainCommand "uv" $argv
|
|
82
53
|
end
|
|
83
54
|
|
|
84
55
|
# `python -m pip`, `python -m pip3`.
|
|
85
56
|
function python
|
|
86
|
-
wrapSafeChainCommand "python"
|
|
57
|
+
wrapSafeChainCommand "python" $argv
|
|
87
58
|
end
|
|
88
59
|
|
|
89
60
|
# `python3 -m pip`, `python3 -m pip3'.
|
|
90
61
|
function python3
|
|
91
|
-
wrapSafeChainCommand "python3"
|
|
62
|
+
wrapSafeChainCommand "python3" $argv
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
function printSafeChainWarning
|
|
66
|
+
set original_cmd $argv[1]
|
|
67
|
+
|
|
68
|
+
# Fish equivalent of ANSI color codes: yellow background, black text for "Warning:"
|
|
69
|
+
set_color -b yellow black
|
|
70
|
+
printf "Warning:"
|
|
71
|
+
set_color normal
|
|
72
|
+
printf " safe-chain is not available to protect you from installing malware. %s will run without it.\n" $original_cmd
|
|
73
|
+
|
|
74
|
+
# Cyan text for the install command
|
|
75
|
+
printf "Install safe-chain by using "
|
|
76
|
+
set_color cyan
|
|
77
|
+
printf "npm install -g @aikidosec/safe-chain"
|
|
78
|
+
set_color normal
|
|
79
|
+
printf ".\n"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
function wrapSafeChainCommand
|
|
83
|
+
set original_cmd $argv[1]
|
|
84
|
+
set cmd_args $argv[2..-1]
|
|
85
|
+
|
|
86
|
+
if type -q safe-chain
|
|
87
|
+
# If the safe-chain command is available, just run it with the provided arguments
|
|
88
|
+
safe-chain $original_cmd $cmd_args
|
|
89
|
+
else
|
|
90
|
+
# If the safe-chain command is not available, print a warning and run the original command
|
|
91
|
+
printSafeChainWarning $original_cmd
|
|
92
|
+
command $original_cmd $cmd_args
|
|
93
|
+
end
|
|
92
94
|
end
|
|
@@ -1,53 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
function printSafeChainWarning() {
|
|
3
|
-
# \033[43;30m is used to set the background color to yellow and text color to black
|
|
4
|
-
# \033[0m is used to reset the text formatting
|
|
5
|
-
printf "\033[43;30mWarning:\033[0m safe-chain is not available to protect you from installing malware. %s will run without it.\n" "$1"
|
|
6
|
-
# \033[36m is used to set the text color to cyan
|
|
7
|
-
printf "Install safe-chain by using \033[36mnpm install -g @aikidosec/safe-chain\033[0m.\n"
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function wrapSafeChainCommand() {
|
|
11
|
-
local original_cmd="$1"
|
|
12
|
-
local aikido_cmd="$2"
|
|
13
|
-
|
|
14
|
-
# Remove the first 2 arguments (original_cmd and aikido_cmd) from $@
|
|
15
|
-
# so that "$@" now contains only the arguments passed to the original command
|
|
16
|
-
shift 2
|
|
17
|
-
|
|
18
|
-
if command -v "$aikido_cmd" > /dev/null 2>&1; then
|
|
19
|
-
# If the aikido command is available, just run it with the provided arguments
|
|
20
|
-
"$aikido_cmd" "$@"
|
|
21
|
-
else
|
|
22
|
-
# If the aikido command is not available, print a warning and run the original command
|
|
23
|
-
printSafeChainWarning "$original_cmd"
|
|
24
|
-
|
|
25
|
-
command "$original_cmd" "$@"
|
|
26
|
-
fi
|
|
27
|
-
}
|
|
1
|
+
export PATH="$PATH:$HOME/.safe-chain/bin"
|
|
28
2
|
|
|
29
3
|
function npx() {
|
|
30
|
-
wrapSafeChainCommand "npx" "
|
|
4
|
+
wrapSafeChainCommand "npx" "$@"
|
|
31
5
|
}
|
|
32
6
|
|
|
33
7
|
function yarn() {
|
|
34
|
-
wrapSafeChainCommand "yarn" "
|
|
8
|
+
wrapSafeChainCommand "yarn" "$@"
|
|
35
9
|
}
|
|
36
10
|
|
|
37
11
|
function pnpm() {
|
|
38
|
-
wrapSafeChainCommand "pnpm" "
|
|
12
|
+
wrapSafeChainCommand "pnpm" "$@"
|
|
39
13
|
}
|
|
40
14
|
|
|
41
15
|
function pnpx() {
|
|
42
|
-
wrapSafeChainCommand "pnpx" "
|
|
16
|
+
wrapSafeChainCommand "pnpx" "$@"
|
|
43
17
|
}
|
|
44
18
|
|
|
45
19
|
function bun() {
|
|
46
|
-
wrapSafeChainCommand "bun" "
|
|
20
|
+
wrapSafeChainCommand "bun" "$@"
|
|
47
21
|
}
|
|
48
22
|
|
|
49
23
|
function bunx() {
|
|
50
|
-
wrapSafeChainCommand "bunx" "
|
|
24
|
+
wrapSafeChainCommand "bunx" "$@"
|
|
51
25
|
}
|
|
52
26
|
|
|
53
27
|
function npm() {
|
|
@@ -58,27 +32,50 @@ function npm() {
|
|
|
58
32
|
return
|
|
59
33
|
fi
|
|
60
34
|
|
|
61
|
-
wrapSafeChainCommand "npm" "
|
|
35
|
+
wrapSafeChainCommand "npm" "$@"
|
|
62
36
|
}
|
|
63
37
|
|
|
38
|
+
|
|
64
39
|
function pip() {
|
|
65
|
-
wrapSafeChainCommand "pip" "
|
|
40
|
+
wrapSafeChainCommand "pip" "$@"
|
|
66
41
|
}
|
|
67
42
|
|
|
68
43
|
function pip3() {
|
|
69
|
-
wrapSafeChainCommand "pip3" "
|
|
44
|
+
wrapSafeChainCommand "pip3" "$@"
|
|
70
45
|
}
|
|
71
46
|
|
|
72
47
|
function uv() {
|
|
73
|
-
wrapSafeChainCommand "uv" "
|
|
48
|
+
wrapSafeChainCommand "uv" "$@"
|
|
74
49
|
}
|
|
75
50
|
|
|
76
51
|
# `python -m pip`, `python -m pip3`.
|
|
77
52
|
function python() {
|
|
78
|
-
wrapSafeChainCommand "python" "
|
|
53
|
+
wrapSafeChainCommand "python" "$@"
|
|
79
54
|
}
|
|
80
55
|
|
|
81
56
|
# `python3 -m pip`, `python3 -m pip3'.
|
|
82
57
|
function python3() {
|
|
83
|
-
wrapSafeChainCommand "python3" "
|
|
58
|
+
wrapSafeChainCommand "python3" "$@"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function printSafeChainWarning() {
|
|
62
|
+
# \033[43;30m is used to set the background color to yellow and text color to black
|
|
63
|
+
# \033[0m is used to reset the text formatting
|
|
64
|
+
printf "\033[43;30mWarning:\033[0m safe-chain is not available to protect you from installing malware. %s will run without it.\n" "$1"
|
|
65
|
+
# \033[36m is used to set the text color to cyan
|
|
66
|
+
printf "Install safe-chain by using \033[36mnpm install -g @aikidosec/safe-chain\033[0m.\n"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function wrapSafeChainCommand() {
|
|
70
|
+
local original_cmd="$1"
|
|
71
|
+
|
|
72
|
+
if command -v safe-chain > /dev/null 2>&1; then
|
|
73
|
+
# If the aikido command is available, just run it with the provided arguments
|
|
74
|
+
safe-chain "$@"
|
|
75
|
+
else
|
|
76
|
+
# If the aikido command is not available, print a warning and run the original command
|
|
77
|
+
printSafeChainWarning "$original_cmd"
|
|
78
|
+
|
|
79
|
+
command "$original_cmd" "$@"
|
|
80
|
+
fi
|
|
84
81
|
}
|
|
@@ -1,3 +1,66 @@
|
|
|
1
|
+
# Use cross-platform path separator (: on Unix, ; on Windows)
|
|
2
|
+
$pathSeparator = if ($IsWindows) { ';' } else { ':' }
|
|
3
|
+
$safeChainBin = Join-Path $HOME '.safe-chain' 'bin'
|
|
4
|
+
$env:PATH = "$env:PATH$pathSeparator$safeChainBin"
|
|
5
|
+
|
|
6
|
+
function npx {
|
|
7
|
+
Invoke-WrappedCommand "npx" $args
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function yarn {
|
|
11
|
+
Invoke-WrappedCommand "yarn" $args
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function pnpm {
|
|
15
|
+
Invoke-WrappedCommand "pnpm" $args
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function pnpx {
|
|
19
|
+
Invoke-WrappedCommand "pnpx" $args
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function bun {
|
|
23
|
+
Invoke-WrappedCommand "bun" $args
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function bunx {
|
|
27
|
+
Invoke-WrappedCommand "bunx" $args
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function npm {
|
|
31
|
+
# If args is just -v or --version and nothing else, just run the npm version command
|
|
32
|
+
# This is because nvm uses this to check the version of npm
|
|
33
|
+
if (($args.Length -eq 1) -and (($args[0] -eq "-v") -or ($args[0] -eq "--version"))) {
|
|
34
|
+
Invoke-RealCommand "npm" $args
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Invoke-WrappedCommand "npm" $args
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function pip {
|
|
42
|
+
Invoke-WrappedCommand "pip" $args
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function pip3 {
|
|
46
|
+
Invoke-WrappedCommand "pip3" $args
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function uv {
|
|
50
|
+
Invoke-WrappedCommand "uv" $args
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# `python -m pip`, `python -m pip3`.
|
|
54
|
+
function python {
|
|
55
|
+
Invoke-WrappedCommand 'python' $args
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
# `python3 -m pip`, `python3 -m pip3'.
|
|
59
|
+
function python3 {
|
|
60
|
+
Invoke-WrappedCommand 'python3' $args
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
1
64
|
function Write-SafeChainWarning {
|
|
2
65
|
param([string]$Command)
|
|
3
66
|
|
|
@@ -39,73 +102,14 @@ function Invoke-RealCommand {
|
|
|
39
102
|
function Invoke-WrappedCommand {
|
|
40
103
|
param(
|
|
41
104
|
[string]$OriginalCmd,
|
|
42
|
-
[string]$AikidoCmd,
|
|
43
105
|
[string[]]$Arguments
|
|
44
106
|
)
|
|
45
107
|
|
|
46
|
-
if (Test-CommandAvailable
|
|
47
|
-
& $
|
|
108
|
+
if (Test-CommandAvailable "safe-chain") {
|
|
109
|
+
& safe-chain $OriginalCmd @Arguments
|
|
48
110
|
}
|
|
49
111
|
else {
|
|
50
112
|
Write-SafeChainWarning $OriginalCmd
|
|
51
113
|
Invoke-RealCommand $OriginalCmd $Arguments
|
|
52
114
|
}
|
|
53
115
|
}
|
|
54
|
-
|
|
55
|
-
function npx {
|
|
56
|
-
Invoke-WrappedCommand "npx" "aikido-npx" $args
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function yarn {
|
|
60
|
-
Invoke-WrappedCommand "yarn" "aikido-yarn" $args
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function pnpm {
|
|
64
|
-
Invoke-WrappedCommand "pnpm" "aikido-pnpm" $args
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function pnpx {
|
|
68
|
-
Invoke-WrappedCommand "pnpx" "aikido-pnpx" $args
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function bun {
|
|
72
|
-
Invoke-WrappedCommand "bun" "aikido-bun" $args
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function bunx {
|
|
76
|
-
Invoke-WrappedCommand "bunx" "aikido-bunx" $args
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function npm {
|
|
80
|
-
# If args is just -v or --version and nothing else, just run the npm version command
|
|
81
|
-
# This is because nvm uses this to check the version of npm
|
|
82
|
-
if (($args.Length -eq 1) -and (($args[0] -eq "-v") -or ($args[0] -eq "--version"))) {
|
|
83
|
-
Invoke-RealCommand "npm" $args
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
Invoke-WrappedCommand "npm" "aikido-npm" $args
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function pip {
|
|
91
|
-
Invoke-WrappedCommand "pip" "aikido-pip" $args
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function pip3 {
|
|
95
|
-
Invoke-WrappedCommand "pip3" "aikido-pip3" $args
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function uv {
|
|
99
|
-
Invoke-WrappedCommand "uv" "aikido-uv" $args
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
# `python -m pip`, `python -m pip3`.
|
|
103
|
-
function python {
|
|
104
|
-
Invoke-WrappedCommand 'python' 'aikido-python' $args
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
# `python3 -m pip`, `python3 -m pip3'.
|
|
108
|
-
function python3 {
|
|
109
|
-
Invoke-WrappedCommand 'python3' 'aikido-python3' $args
|
|
110
|
-
}
|
|
111
|
-
|
|
@@ -1,57 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
set original_cmd $argv[1]
|
|
3
|
-
|
|
4
|
-
# Fish equivalent of ANSI color codes: yellow background, black text for "Warning:"
|
|
5
|
-
set_color -b yellow black
|
|
6
|
-
printf "Warning:"
|
|
7
|
-
set_color normal
|
|
8
|
-
printf " safe-chain is not available to protect you from installing malware. %s will run without it.\n" $original_cmd
|
|
9
|
-
|
|
10
|
-
# Cyan text for the install command
|
|
11
|
-
printf "Install safe-chain by using "
|
|
12
|
-
set_color cyan
|
|
13
|
-
printf "npm install -g @aikidosec/safe-chain"
|
|
14
|
-
set_color normal
|
|
15
|
-
printf ".\n"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
function wrapSafeChainCommand
|
|
19
|
-
set original_cmd $argv[1]
|
|
20
|
-
set aikido_cmd $argv[2]
|
|
21
|
-
set cmd_args $argv[3..-1]
|
|
22
|
-
|
|
23
|
-
if type -q $aikido_cmd
|
|
24
|
-
# If the aikido command is available, just run it with the provided arguments
|
|
25
|
-
$aikido_cmd $cmd_args
|
|
26
|
-
else
|
|
27
|
-
# If the aikido command is not available, print a warning and run the original command
|
|
28
|
-
printSafeChainWarning $original_cmd
|
|
29
|
-
command $original_cmd $cmd_args
|
|
30
|
-
end
|
|
31
|
-
end
|
|
1
|
+
set -gx PATH $PATH $HOME/.safe-chain/bin
|
|
32
2
|
|
|
33
3
|
function npx
|
|
34
|
-
wrapSafeChainCommand "npx"
|
|
4
|
+
wrapSafeChainCommand "npx" $argv
|
|
35
5
|
end
|
|
36
6
|
|
|
37
7
|
function yarn
|
|
38
|
-
wrapSafeChainCommand "yarn"
|
|
8
|
+
wrapSafeChainCommand "yarn" $argv
|
|
39
9
|
end
|
|
40
10
|
|
|
41
11
|
function pnpm
|
|
42
|
-
wrapSafeChainCommand "pnpm"
|
|
12
|
+
wrapSafeChainCommand "pnpm" $argv
|
|
43
13
|
end
|
|
44
14
|
|
|
45
15
|
function pnpx
|
|
46
|
-
wrapSafeChainCommand "pnpx"
|
|
16
|
+
wrapSafeChainCommand "pnpx" $argv
|
|
47
17
|
end
|
|
48
18
|
|
|
49
19
|
function bun
|
|
50
|
-
wrapSafeChainCommand "bun"
|
|
20
|
+
wrapSafeChainCommand "bun" $argv
|
|
51
21
|
end
|
|
52
22
|
|
|
53
23
|
function bunx
|
|
54
|
-
wrapSafeChainCommand "bunx"
|
|
24
|
+
wrapSafeChainCommand "bunx" $argv
|
|
55
25
|
end
|
|
56
26
|
|
|
57
27
|
function npm
|
|
@@ -66,5 +36,36 @@ function npm
|
|
|
66
36
|
end
|
|
67
37
|
end
|
|
68
38
|
|
|
69
|
-
wrapSafeChainCommand "npm"
|
|
39
|
+
wrapSafeChainCommand "npm" $argv
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
function printSafeChainWarning
|
|
43
|
+
set original_cmd $argv[1]
|
|
44
|
+
|
|
45
|
+
# Fish equivalent of ANSI color codes: yellow background, black text for "Warning:"
|
|
46
|
+
set_color -b yellow black
|
|
47
|
+
printf "Warning:"
|
|
48
|
+
set_color normal
|
|
49
|
+
printf " safe-chain is not available to protect you from installing malware. %s will run without it.\n" $original_cmd
|
|
50
|
+
|
|
51
|
+
# Cyan text for the install command
|
|
52
|
+
printf "Install safe-chain by using "
|
|
53
|
+
set_color cyan
|
|
54
|
+
printf "npm install -g @aikidosec/safe-chain"
|
|
55
|
+
set_color normal
|
|
56
|
+
printf ".\n"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
function wrapSafeChainCommand
|
|
60
|
+
set original_cmd $argv[1]
|
|
61
|
+
set cmd_args $argv[2..-1]
|
|
62
|
+
|
|
63
|
+
if type -q safe-chain
|
|
64
|
+
# If the safe-chain command is available, just run it with the provided arguments
|
|
65
|
+
safe-chain $original_cmd $cmd_args
|
|
66
|
+
else
|
|
67
|
+
# If the safe-chain command is not available, print a warning and run the original command
|
|
68
|
+
printSafeChainWarning $original_cmd
|
|
69
|
+
command $original_cmd $cmd_args
|
|
70
|
+
end
|
|
70
71
|
end
|