@aikidosec/safe-chain 1.2.4 β 1.3.1
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 +7 -43
- package/bin/safe-chain.js +0 -10
- package/package.json +1 -1
- package/src/config/cliArguments.js +18 -18
- package/src/shell-integration/setup-ci.js +1 -7
- package/src/shell-integration/setup.js +1 -2
- package/src/shell-integration/startup-scripts/init-fish.fish +27 -0
- package/src/shell-integration/startup-scripts/init-posix.sh +27 -0
- package/src/shell-integration/startup-scripts/init-pwsh.ps1 +30 -1
- package/src/shell-integration/startup-scripts/include-python/init-fish.fish +0 -98
- package/src/shell-integration/startup-scripts/include-python/init-posix.sh +0 -85
- package/src/shell-integration/startup-scripts/include-python/init-pwsh.ps1 +0 -119
package/README.md
CHANGED
|
@@ -19,10 +19,10 @@ Aikido Safe Chain supports the following package managers:
|
|
|
19
19
|
- π¦ **pnpx**
|
|
20
20
|
- π¦ **bun**
|
|
21
21
|
- π¦ **bunx**
|
|
22
|
-
- π¦ **pip**
|
|
23
|
-
- π¦ **pip3**
|
|
24
|
-
- π¦ **uv**
|
|
25
|
-
- π¦ **poetry**
|
|
22
|
+
- π¦ **pip**
|
|
23
|
+
- π¦ **pip3**
|
|
24
|
+
- π¦ **uv**
|
|
25
|
+
- π¦ **poetry**
|
|
26
26
|
|
|
27
27
|
# Usage
|
|
28
28
|
|
|
@@ -34,32 +34,16 @@ Installing the Aikido Safe Chain is easy with our one-line installer.
|
|
|
34
34
|
|
|
35
35
|
### Unix/Linux/macOS
|
|
36
36
|
|
|
37
|
-
**Default installation (JavaScript packages only):**
|
|
38
|
-
|
|
39
37
|
```shell
|
|
40
38
|
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh
|
|
41
39
|
```
|
|
42
40
|
|
|
43
|
-
**Include Python support (pip/pip3/uv):**
|
|
44
|
-
|
|
45
|
-
```shell
|
|
46
|
-
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --include-python
|
|
47
|
-
```
|
|
48
|
-
|
|
49
41
|
### Windows (PowerShell)
|
|
50
42
|
|
|
51
|
-
**Default installation (JavaScript packages only):**
|
|
52
|
-
|
|
53
43
|
```powershell
|
|
54
44
|
iex (iwr "https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1" -UseBasicParsing)
|
|
55
45
|
```
|
|
56
46
|
|
|
57
|
-
**Include Python support (pip/pip3/uv):**
|
|
58
|
-
|
|
59
|
-
```powershell
|
|
60
|
-
iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -includepython"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
47
|
### Verify the installation
|
|
64
48
|
|
|
65
49
|
1. **βRestart your terminal** to start using the Aikido Safe Chain.
|
|
@@ -74,7 +58,7 @@ iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/inst
|
|
|
74
58
|
npm install safe-chain-test
|
|
75
59
|
```
|
|
76
60
|
|
|
77
|
-
For Python
|
|
61
|
+
For Python:
|
|
78
62
|
|
|
79
63
|
```shell
|
|
80
64
|
pip3 install safe-chain-pi-test
|
|
@@ -193,32 +177,16 @@ Use the `--ci` flag to automatically configure Aikido Safe Chain for CI/CD envir
|
|
|
193
177
|
|
|
194
178
|
### Unix/Linux/macOS (GitHub Actions, Azure Pipelines, etc.)
|
|
195
179
|
|
|
196
|
-
**JavaScript only:**
|
|
197
|
-
|
|
198
180
|
```shell
|
|
199
181
|
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci
|
|
200
182
|
```
|
|
201
183
|
|
|
202
|
-
**With Python support:**
|
|
203
|
-
|
|
204
|
-
```shell
|
|
205
|
-
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci --include-python
|
|
206
|
-
```
|
|
207
|
-
|
|
208
184
|
### Windows (Azure Pipelines, etc.)
|
|
209
185
|
|
|
210
|
-
**JavaScript only:**
|
|
211
|
-
|
|
212
186
|
```powershell
|
|
213
187
|
iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -ci"
|
|
214
188
|
```
|
|
215
189
|
|
|
216
|
-
**With Python support:**
|
|
217
|
-
|
|
218
|
-
```powershell
|
|
219
|
-
iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -ci -includepython"
|
|
220
|
-
```
|
|
221
|
-
|
|
222
190
|
## Supported Platforms
|
|
223
191
|
|
|
224
192
|
- β
**GitHub Actions**
|
|
@@ -234,14 +202,12 @@ iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/inst
|
|
|
234
202
|
cache: "npm"
|
|
235
203
|
|
|
236
204
|
- name: Install safe-chain
|
|
237
|
-
run: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci
|
|
205
|
+
run: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci
|
|
238
206
|
|
|
239
207
|
- name: Install dependencies
|
|
240
208
|
run: npm ci
|
|
241
209
|
```
|
|
242
210
|
|
|
243
|
-
> **Note:** Remove `--include-python` if you don't need Python (pip/pip3/uv/poetry) support.
|
|
244
|
-
|
|
245
211
|
## Azure DevOps Example
|
|
246
212
|
|
|
247
213
|
```yaml
|
|
@@ -250,13 +216,11 @@ iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/inst
|
|
|
250
216
|
versionSpec: "22.x"
|
|
251
217
|
displayName: "Install Node.js"
|
|
252
218
|
|
|
253
|
-
- script: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci
|
|
219
|
+
- script: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci
|
|
254
220
|
displayName: "Install safe-chain"
|
|
255
221
|
|
|
256
222
|
- script: npm ci
|
|
257
223
|
displayName: "Install dependencies"
|
|
258
224
|
```
|
|
259
225
|
|
|
260
|
-
> **Note:** Remove `--include-python` if you don't need Python (pip/pip3/uv/poetry) support.
|
|
261
|
-
|
|
262
226
|
After setup, all subsequent package manager commands in your CI pipeline will automatically be protected by Aikido Safe Chain's malware detection.
|
package/bin/safe-chain.js
CHANGED
|
@@ -95,11 +95,6 @@ function writeHelp() {
|
|
|
95
95
|
"safe-chain setup"
|
|
96
96
|
)}: This will setup your shell to wrap safe-chain around npm, npx, yarn, pnpm, pnpx, bun, bunx, pip and pip3.`
|
|
97
97
|
);
|
|
98
|
-
ui.writeInformation(
|
|
99
|
-
` ${chalk.yellow(
|
|
100
|
-
"--include-python"
|
|
101
|
-
)}: Experimental: include Python package managers (pip, pip3) in the setup.`
|
|
102
|
-
);
|
|
103
98
|
ui.writeInformation(
|
|
104
99
|
`- ${chalk.cyan(
|
|
105
100
|
"safe-chain teardown"
|
|
@@ -110,11 +105,6 @@ function writeHelp() {
|
|
|
110
105
|
"safe-chain setup-ci"
|
|
111
106
|
)}: This will setup safe-chain for CI environments by creating shims and modifying the PATH.`
|
|
112
107
|
);
|
|
113
|
-
ui.writeInformation(
|
|
114
|
-
` ${chalk.yellow(
|
|
115
|
-
"--include-python"
|
|
116
|
-
)}: Experimental: include Python package managers (pip, pip3) in the setup.`
|
|
117
|
-
);
|
|
118
108
|
ui.writeInformation(
|
|
119
109
|
`- ${chalk.cyan("safe-chain --version")} (or ${chalk.cyan(
|
|
120
110
|
"-v"
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { ui } from "../environment/userInteraction.js";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* @type {{loggingLevel: string | undefined, skipMinimumPackageAge: boolean | undefined, minimumPackageAgeHours: string | undefined
|
|
4
|
+
* @type {{loggingLevel: string | undefined, skipMinimumPackageAge: boolean | undefined, minimumPackageAgeHours: string | undefined}}
|
|
3
5
|
*/
|
|
4
6
|
const state = {
|
|
5
7
|
loggingLevel: undefined,
|
|
6
8
|
skipMinimumPackageAge: undefined,
|
|
7
9
|
minimumPackageAgeHours: undefined,
|
|
8
|
-
includePython: false,
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
const SAFE_CHAIN_ARG_PREFIX = "--safe-chain-";
|
|
@@ -34,8 +35,7 @@ export function initializeCliArguments(args) {
|
|
|
34
35
|
setLoggingLevel(safeChainArgs);
|
|
35
36
|
setSkipMinimumPackageAge(safeChainArgs);
|
|
36
37
|
setMinimumPackageAgeHours(safeChainArgs);
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
checkDeprecatedPythonFlag(args);
|
|
39
39
|
return remainingArgs;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -109,20 +109,6 @@ export function getMinimumPackageAgeHours() {
|
|
|
109
109
|
return state.minimumPackageAgeHours;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
/**
|
|
113
|
-
* @param {string[]} args
|
|
114
|
-
*/
|
|
115
|
-
function setIncludePython(args) {
|
|
116
|
-
// This flag doesn't have the --safe-chain- prefix because
|
|
117
|
-
// it is only used for the safe-chain command itself and
|
|
118
|
-
// not when wrapped around package manager commands.
|
|
119
|
-
state.includePython = hasFlagArg(args, "--include-python");
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function includePython() {
|
|
123
|
-
return state.includePython;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
112
|
/**
|
|
127
113
|
* @param {string[]} args
|
|
128
114
|
* @param {string} flagName
|
|
@@ -136,3 +122,17 @@ function hasFlagArg(args, flagName) {
|
|
|
136
122
|
}
|
|
137
123
|
return false;
|
|
138
124
|
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Emits a deprecation warning for legacy --include-python flag
|
|
128
|
+
*
|
|
129
|
+
* @param {string[]} args
|
|
130
|
+
* @returns {void}
|
|
131
|
+
*/
|
|
132
|
+
export function checkDeprecatedPythonFlag(args) {
|
|
133
|
+
if (hasFlagArg(args, "--include-python")) {
|
|
134
|
+
ui.writeWarning(
|
|
135
|
+
"--include-python is deprecated and ignored. Python tooling is included by default."
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -5,8 +5,6 @@ import fs from "fs";
|
|
|
5
5
|
import os from "os";
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
|
-
import { includePython } from "../config/cliArguments.js";
|
|
9
|
-
import { ECOSYSTEM_PY } from "../config/settings.js";
|
|
10
8
|
|
|
11
9
|
/** @type {string} */
|
|
12
10
|
// This checks the current file's dirname in a way that's compatible with:
|
|
@@ -162,9 +160,5 @@ function modifyPathForCi(shimsDir, binDir) {
|
|
|
162
160
|
}
|
|
163
161
|
|
|
164
162
|
function getToolsToSetup() {
|
|
165
|
-
|
|
166
|
-
return knownAikidoTools;
|
|
167
|
-
} else {
|
|
168
|
-
return knownAikidoTools.filter((tool) => tool.ecoSystem !== ECOSYSTEM_PY);
|
|
169
|
-
}
|
|
163
|
+
return knownAikidoTools;
|
|
170
164
|
}
|
|
@@ -4,7 +4,6 @@ import { detectShells } from "./shellDetection.js";
|
|
|
4
4
|
import { knownAikidoTools, getPackageManagerList, getScriptsDir } from "./helpers.js";
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import path from "path";
|
|
7
|
-
import { includePython } from "../config/cliArguments.js";
|
|
8
7
|
import { fileURLToPath } from "url";
|
|
9
8
|
|
|
10
9
|
/** @type {string} */
|
|
@@ -118,7 +117,7 @@ function copyStartupFiles() {
|
|
|
118
117
|
// Use absolute path for source
|
|
119
118
|
const sourcePath = path.join(
|
|
120
119
|
dirname,
|
|
121
|
-
|
|
120
|
+
"startup-scripts",
|
|
122
121
|
file
|
|
123
122
|
);
|
|
124
123
|
fs.copyFileSync(sourcePath, targetPath);
|
|
@@ -39,6 +39,33 @@ function npm
|
|
|
39
39
|
wrapSafeChainCommand "npm" $argv
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
|
|
43
|
+
function pip
|
|
44
|
+
wrapSafeChainCommand "pip" $argv
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
function pip3
|
|
48
|
+
wrapSafeChainCommand "pip3" $argv
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
function uv
|
|
52
|
+
wrapSafeChainCommand "uv" $argv
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
function poetry
|
|
56
|
+
wrapSafeChainCommand "poetry" $argv
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# `python -m pip`, `python -m pip3`.
|
|
60
|
+
function python
|
|
61
|
+
wrapSafeChainCommand "python" $argv
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# `python3 -m pip`, `python3 -m pip3'.
|
|
65
|
+
function python3
|
|
66
|
+
wrapSafeChainCommand "python3" $argv
|
|
67
|
+
end
|
|
68
|
+
|
|
42
69
|
function printSafeChainWarning
|
|
43
70
|
set original_cmd $argv[1]
|
|
44
71
|
|
|
@@ -35,6 +35,33 @@ function npm() {
|
|
|
35
35
|
wrapSafeChainCommand "npm" "$@"
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
|
|
39
|
+
function pip() {
|
|
40
|
+
wrapSafeChainCommand "pip" "$@"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function pip3() {
|
|
44
|
+
wrapSafeChainCommand "pip3" "$@"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function uv() {
|
|
48
|
+
wrapSafeChainCommand "uv" "$@"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function poetry() {
|
|
52
|
+
wrapSafeChainCommand "poetry" "$@"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# `python -m pip`, `python -m pip3`.
|
|
56
|
+
function python() {
|
|
57
|
+
wrapSafeChainCommand "python" "$@"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# `python3 -m pip`, `python3 -m pip3'.
|
|
61
|
+
function python3() {
|
|
62
|
+
wrapSafeChainCommand "python3" "$@"
|
|
63
|
+
}
|
|
64
|
+
|
|
38
65
|
function printSafeChainWarning() {
|
|
39
66
|
# \033[43;30m is used to set the background color to yellow and text color to black
|
|
40
67
|
# \033[0m is used to reset the text formatting
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Use cross-platform path separator (: on Unix, ; on Windows)
|
|
2
|
-
$
|
|
2
|
+
# $IsWindows is only available in PowerShell Core 6.0+. If it doesn't exist, assume Windows PowerShell
|
|
3
|
+
$isWindowsPlatform = if (Test-Path variable:IsWindows) { $IsWindows } else { $true }
|
|
4
|
+
$pathSeparator = if ($isWindowsPlatform) { ';' } else { ':' }
|
|
3
5
|
$safeChainBin = Join-Path (Join-Path $HOME '.safe-chain') 'bin'
|
|
4
6
|
$env:PATH = "$env:PATH$pathSeparator$safeChainBin"
|
|
5
7
|
|
|
@@ -38,6 +40,33 @@ function npm {
|
|
|
38
40
|
Invoke-WrappedCommand "npm" $args
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
function pip {
|
|
44
|
+
Invoke-WrappedCommand "pip" $args
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function pip3 {
|
|
48
|
+
Invoke-WrappedCommand "pip3" $args
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function uv {
|
|
52
|
+
Invoke-WrappedCommand "uv" $args
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function poetry {
|
|
56
|
+
Invoke-WrappedCommand "poetry" $args
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# `python -m pip`, `python -m pip3`.
|
|
60
|
+
function python {
|
|
61
|
+
Invoke-WrappedCommand 'python' $args
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# `python3 -m pip`, `python3 -m pip3'.
|
|
65
|
+
function python3 {
|
|
66
|
+
Invoke-WrappedCommand 'python3' $args
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
41
70
|
function Write-SafeChainWarning {
|
|
42
71
|
param([string]$Command)
|
|
43
72
|
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
set -gx PATH $PATH $HOME/.safe-chain/bin
|
|
2
|
-
|
|
3
|
-
function npx
|
|
4
|
-
wrapSafeChainCommand "npx" $argv
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
function yarn
|
|
8
|
-
wrapSafeChainCommand "yarn" $argv
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
function pnpm
|
|
12
|
-
wrapSafeChainCommand "pnpm" $argv
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
function pnpx
|
|
16
|
-
wrapSafeChainCommand "pnpx" $argv
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
function bun
|
|
20
|
-
wrapSafeChainCommand "bun" $argv
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
function bunx
|
|
24
|
-
wrapSafeChainCommand "bunx" $argv
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
function npm
|
|
28
|
-
# If args is just -v or --version and nothing else, just run the `npm -v` command
|
|
29
|
-
# This is because nvm uses this to check the version of npm
|
|
30
|
-
set argc (count $argv)
|
|
31
|
-
if test $argc -eq 1
|
|
32
|
-
switch $argv[1]
|
|
33
|
-
case "-v" "--version"
|
|
34
|
-
command npm $argv
|
|
35
|
-
return
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
wrapSafeChainCommand "npm" $argv
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function pip
|
|
44
|
-
wrapSafeChainCommand "pip" $argv
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
function pip3
|
|
48
|
-
wrapSafeChainCommand "pip3" $argv
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
function uv
|
|
52
|
-
wrapSafeChainCommand "uv" $argv
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
function poetry
|
|
56
|
-
wrapSafeChainCommand "poetry" $argv
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# `python -m pip`, `python -m pip3`.
|
|
60
|
-
function python
|
|
61
|
-
wrapSafeChainCommand "python" $argv
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# `python3 -m pip`, `python3 -m pip3'.
|
|
65
|
-
function python3
|
|
66
|
-
wrapSafeChainCommand "python3" $argv
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
function printSafeChainWarning
|
|
70
|
-
set original_cmd $argv[1]
|
|
71
|
-
|
|
72
|
-
# Fish equivalent of ANSI color codes: yellow background, black text for "Warning:"
|
|
73
|
-
set_color -b yellow black
|
|
74
|
-
printf "Warning:"
|
|
75
|
-
set_color normal
|
|
76
|
-
printf " safe-chain is not available to protect you from installing malware. %s will run without it.\n" $original_cmd
|
|
77
|
-
|
|
78
|
-
# Cyan text for the install command
|
|
79
|
-
printf "Install safe-chain by using "
|
|
80
|
-
set_color cyan
|
|
81
|
-
printf "npm install -g @aikidosec/safe-chain"
|
|
82
|
-
set_color normal
|
|
83
|
-
printf ".\n"
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
function wrapSafeChainCommand
|
|
87
|
-
set original_cmd $argv[1]
|
|
88
|
-
set cmd_args $argv[2..-1]
|
|
89
|
-
|
|
90
|
-
if type -q safe-chain
|
|
91
|
-
# If the safe-chain command is available, just run it with the provided arguments
|
|
92
|
-
safe-chain $original_cmd $cmd_args
|
|
93
|
-
else
|
|
94
|
-
# If the safe-chain command is not available, print a warning and run the original command
|
|
95
|
-
printSafeChainWarning $original_cmd
|
|
96
|
-
command $original_cmd $cmd_args
|
|
97
|
-
end
|
|
98
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
export PATH="$PATH:$HOME/.safe-chain/bin"
|
|
2
|
-
|
|
3
|
-
function npx() {
|
|
4
|
-
wrapSafeChainCommand "npx" "$@"
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function yarn() {
|
|
8
|
-
wrapSafeChainCommand "yarn" "$@"
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function pnpm() {
|
|
12
|
-
wrapSafeChainCommand "pnpm" "$@"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function pnpx() {
|
|
16
|
-
wrapSafeChainCommand "pnpx" "$@"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function bun() {
|
|
20
|
-
wrapSafeChainCommand "bun" "$@"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function bunx() {
|
|
24
|
-
wrapSafeChainCommand "bunx" "$@"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function npm() {
|
|
28
|
-
if [[ "$1" == "-v" || "$1" == "--version" ]] && [[ $# -eq 1 ]]; then
|
|
29
|
-
# If args is just -v or --version and nothing else, just run the npm version command
|
|
30
|
-
# This is because nvm uses this to check the version of npm
|
|
31
|
-
command npm "$@"
|
|
32
|
-
return
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
wrapSafeChainCommand "npm" "$@"
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
function pip() {
|
|
40
|
-
wrapSafeChainCommand "pip" "$@"
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function pip3() {
|
|
44
|
-
wrapSafeChainCommand "pip3" "$@"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function uv() {
|
|
48
|
-
wrapSafeChainCommand "uv" "$@"
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function poetry() {
|
|
52
|
-
wrapSafeChainCommand "poetry" "$@"
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
# `python -m pip`, `python -m pip3`.
|
|
56
|
-
function python() {
|
|
57
|
-
wrapSafeChainCommand "python" "$@"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
# `python3 -m pip`, `python3 -m pip3'.
|
|
61
|
-
function python3() {
|
|
62
|
-
wrapSafeChainCommand "python3" "$@"
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function printSafeChainWarning() {
|
|
66
|
-
# \033[43;30m is used to set the background color to yellow and text color to black
|
|
67
|
-
# \033[0m is used to reset the text formatting
|
|
68
|
-
printf "\033[43;30mWarning:\033[0m safe-chain is not available to protect you from installing malware. %s will run without it.\n" "$1"
|
|
69
|
-
# \033[36m is used to set the text color to cyan
|
|
70
|
-
printf "Install safe-chain by using \033[36mnpm install -g @aikidosec/safe-chain\033[0m.\n"
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function wrapSafeChainCommand() {
|
|
74
|
-
local original_cmd="$1"
|
|
75
|
-
|
|
76
|
-
if command -v safe-chain > /dev/null 2>&1; then
|
|
77
|
-
# If the aikido command is available, just run it with the provided arguments
|
|
78
|
-
safe-chain "$@"
|
|
79
|
-
else
|
|
80
|
-
# If the aikido command is not available, print a warning and run the original command
|
|
81
|
-
printSafeChainWarning "$original_cmd"
|
|
82
|
-
|
|
83
|
-
command "$original_cmd" "$@"
|
|
84
|
-
fi
|
|
85
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# Use cross-platform path separator (: on Unix, ; on Windows)
|
|
2
|
-
$pathSeparator = if ($IsWindows) { ';' } else { ':' }
|
|
3
|
-
$safeChainBin = Join-Path (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
|
-
function poetry {
|
|
54
|
-
Invoke-WrappedCommand "poetry" $args
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# `python -m pip`, `python -m pip3`.
|
|
58
|
-
function python {
|
|
59
|
-
Invoke-WrappedCommand 'python' $args
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
# `python3 -m pip`, `python3 -m pip3'.
|
|
63
|
-
function python3 {
|
|
64
|
-
Invoke-WrappedCommand 'python3' $args
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function Write-SafeChainWarning {
|
|
69
|
-
param([string]$Command)
|
|
70
|
-
|
|
71
|
-
# PowerShell equivalent of ANSI color codes: yellow background, black text for "Warning:"
|
|
72
|
-
Write-Host "Warning:" -BackgroundColor Yellow -ForegroundColor Black -NoNewline
|
|
73
|
-
Write-Host " safe-chain is not available to protect you from installing malware. $Command will run without it."
|
|
74
|
-
|
|
75
|
-
# Cyan text for the install command
|
|
76
|
-
Write-Host "Install safe-chain by using " -NoNewline
|
|
77
|
-
Write-Host "npm install -g @aikidosec/safe-chain" -ForegroundColor Cyan -NoNewline
|
|
78
|
-
Write-Host "."
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function Test-CommandAvailable {
|
|
82
|
-
param([string]$Command)
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
Get-Command $Command -ErrorAction Stop | Out-Null
|
|
86
|
-
return $true
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return $false
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function Invoke-RealCommand {
|
|
94
|
-
param(
|
|
95
|
-
[string]$Command,
|
|
96
|
-
[string[]]$Arguments
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# Find the real executable to avoid calling our wrapped functions
|
|
100
|
-
$realCommand = Get-Command -Name $Command -CommandType Application | Select-Object -First 1
|
|
101
|
-
if ($realCommand) {
|
|
102
|
-
& $realCommand.Source @Arguments
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function Invoke-WrappedCommand {
|
|
107
|
-
param(
|
|
108
|
-
[string]$OriginalCmd,
|
|
109
|
-
[string[]]$Arguments
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
if (Test-CommandAvailable "safe-chain") {
|
|
113
|
-
& safe-chain $OriginalCmd @Arguments
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
Write-SafeChainWarning $OriginalCmd
|
|
117
|
-
Invoke-RealCommand $OriginalCmd $Arguments
|
|
118
|
-
}
|
|
119
|
-
}
|