@aikidosec/safe-chain 0.0.1-immutable-releases-beta
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/LICENSE +674 -0
- package/README.md +517 -0
- package/bin/aikido-bun.js +14 -0
- package/bin/aikido-bunx.js +14 -0
- package/bin/aikido-npm.js +14 -0
- package/bin/aikido-npx.js +14 -0
- package/bin/aikido-pip.js +17 -0
- package/bin/aikido-pip3.js +17 -0
- package/bin/aikido-pipx.js +16 -0
- package/bin/aikido-pnpm.js +14 -0
- package/bin/aikido-pnpx.js +14 -0
- package/bin/aikido-poetry.js +13 -0
- package/bin/aikido-python.js +19 -0
- package/bin/aikido-python3.js +19 -0
- package/bin/aikido-uv.js +16 -0
- package/bin/aikido-yarn.js +14 -0
- package/bin/safe-chain.js +130 -0
- package/docs/banner.svg +151 -0
- package/docs/safe-package-manager-demo.gif +0 -0
- package/docs/safe-package-manager-demo.png +0 -0
- package/docs/shell-integration.md +149 -0
- package/docs/troubleshooting.md +321 -0
- package/npm-shrinkwrap.json +4069 -0
- package/package.json +72 -0
- package/src/api/aikido.js +187 -0
- package/src/api/npmApi.js +71 -0
- package/src/config/cliArguments.js +161 -0
- package/src/config/configFile.js +327 -0
- package/src/config/environmentVariables.js +57 -0
- package/src/config/settings.js +247 -0
- package/src/environment/environment.js +14 -0
- package/src/environment/userInteraction.js +122 -0
- package/src/main.js +123 -0
- package/src/packagemanager/_shared/commandErrors.js +17 -0
- package/src/packagemanager/_shared/matchesCommand.js +18 -0
- package/src/packagemanager/bun/createBunPackageManager.js +48 -0
- package/src/packagemanager/currentPackageManager.js +79 -0
- package/src/packagemanager/npm/createPackageManager.js +72 -0
- package/src/packagemanager/npm/dependencyScanner/commandArgumentScanner.js +74 -0
- package/src/packagemanager/npm/dependencyScanner/nullScanner.js +9 -0
- package/src/packagemanager/npm/parsing/parsePackagesFromInstallArgs.js +144 -0
- package/src/packagemanager/npm/runNpmCommand.js +20 -0
- package/src/packagemanager/npm/utils/abbrevs-generated.js +359 -0
- package/src/packagemanager/npm/utils/cmd-list.js +174 -0
- package/src/packagemanager/npm/utils/npmCommands.js +34 -0
- package/src/packagemanager/npx/createPackageManager.js +15 -0
- package/src/packagemanager/npx/dependencyScanner/commandArgumentScanner.js +43 -0
- package/src/packagemanager/npx/parsing/parsePackagesFromArguments.js +130 -0
- package/src/packagemanager/npx/runNpxCommand.js +20 -0
- package/src/packagemanager/pip/createPackageManager.js +25 -0
- package/src/packagemanager/pip/pipSettings.js +6 -0
- package/src/packagemanager/pip/runPipCommand.js +209 -0
- package/src/packagemanager/pipx/createPipXPackageManager.js +18 -0
- package/src/packagemanager/pipx/runPipXCommand.js +60 -0
- package/src/packagemanager/pnpm/createPackageManager.js +57 -0
- package/src/packagemanager/pnpm/dependencyScanner/commandArgumentScanner.js +35 -0
- package/src/packagemanager/pnpm/parsing/parsePackagesFromArguments.js +109 -0
- package/src/packagemanager/pnpm/runPnpmCommand.js +32 -0
- package/src/packagemanager/poetry/createPoetryPackageManager.js +72 -0
- package/src/packagemanager/uv/createUvPackageManager.js +18 -0
- package/src/packagemanager/uv/runUvCommand.js +66 -0
- package/src/packagemanager/yarn/createPackageManager.js +41 -0
- package/src/packagemanager/yarn/dependencyScanner/commandArgumentScanner.js +35 -0
- package/src/packagemanager/yarn/parsing/parsePackagesFromArguments.js +128 -0
- package/src/packagemanager/yarn/runYarnCommand.js +36 -0
- package/src/registryProxy/certBundle.js +203 -0
- package/src/registryProxy/certUtils.js +178 -0
- package/src/registryProxy/getConnectTimeout.js +13 -0
- package/src/registryProxy/http-utils.js +80 -0
- package/src/registryProxy/interceptors/createInterceptorForEcoSystem.js +25 -0
- package/src/registryProxy/interceptors/interceptorBuilder.js +179 -0
- package/src/registryProxy/interceptors/minimumPackageAgeExclusions.js +33 -0
- package/src/registryProxy/interceptors/npm/modifyNpmInfo.js +180 -0
- package/src/registryProxy/interceptors/npm/npmInterceptor.js +101 -0
- package/src/registryProxy/interceptors/npm/parseNpmPackageUrl.js +60 -0
- package/src/registryProxy/interceptors/pip/modifyPipInfo.js +167 -0
- package/src/registryProxy/interceptors/pip/modifyPipJsonResponse.js +176 -0
- package/src/registryProxy/interceptors/pip/parsePipPackageUrl.js +162 -0
- package/src/registryProxy/interceptors/pip/pipInterceptor.js +122 -0
- package/src/registryProxy/interceptors/pip/pipMetadataResponseUtils.js +27 -0
- package/src/registryProxy/interceptors/pip/pipMetadataVersionUtils.js +131 -0
- package/src/registryProxy/interceptors/suppressedVersionsState.js +21 -0
- package/src/registryProxy/isImdsEndpoint.js +13 -0
- package/src/registryProxy/mitmRequestHandler.js +240 -0
- package/src/registryProxy/plainHttpProxy.js +95 -0
- package/src/registryProxy/registryProxy.js +255 -0
- package/src/registryProxy/tunnelRequestHandler.js +213 -0
- package/src/scanning/audit/index.js +129 -0
- package/src/scanning/index.js +82 -0
- package/src/scanning/malwareDatabase.js +131 -0
- package/src/scanning/newPackagesDatabaseBuilder.js +71 -0
- package/src/scanning/newPackagesDatabaseWarnings.js +17 -0
- package/src/scanning/newPackagesListCache.js +126 -0
- package/src/scanning/packageNameVariants.js +29 -0
- package/src/shell-integration/helpers.js +304 -0
- package/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh +22 -0
- package/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd +24 -0
- package/src/shell-integration/setup-ci.js +172 -0
- package/src/shell-integration/setup.js +129 -0
- package/src/shell-integration/shellDetection.js +39 -0
- package/src/shell-integration/startup-scripts/init-fish.fish +115 -0
- package/src/shell-integration/startup-scripts/init-posix.sh +96 -0
- package/src/shell-integration/startup-scripts/init-pwsh.ps1 +171 -0
- package/src/shell-integration/supported-shells/bash.js +152 -0
- package/src/shell-integration/supported-shells/fish.js +95 -0
- package/src/shell-integration/supported-shells/powershell.js +100 -0
- package/src/shell-integration/supported-shells/windowsPowershell.js +100 -0
- package/src/shell-integration/supported-shells/zsh.js +92 -0
- package/src/shell-integration/teardown.js +112 -0
- package/src/ultimate/ultimateTroubleshooting.js +111 -0
- package/src/utils/safeSpawn.js +153 -0
- package/tsconfig.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Aikido Safe Chain
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@aikidosec/safe-chain)
|
|
6
|
+
[](https://www.npmjs.com/package/@aikidosec/safe-chain)
|
|
7
|
+
|
|
8
|
+
- ✅ **Block malware on developer laptops and CI/CD**
|
|
9
|
+
- ✅ **Supports npm and PyPI** more package managers coming
|
|
10
|
+
- ✅ **Blocks packages newer than 48 hours** without breaking your build
|
|
11
|
+
- ✅ **Tokenless, free, no build data shared**
|
|
12
|
+
|
|
13
|
+
Aikido Safe Chain supports the following package managers:
|
|
14
|
+
|
|
15
|
+
- 📦 **npm**
|
|
16
|
+
- 📦 **npx**
|
|
17
|
+
- 📦 **yarn**
|
|
18
|
+
- 📦 **pnpm**
|
|
19
|
+
- 📦 **pnpx**
|
|
20
|
+
- 📦 **bun**
|
|
21
|
+
- 📦 **bunx**
|
|
22
|
+
- 📦 **pip**
|
|
23
|
+
- 📦 **pip3**
|
|
24
|
+
- 📦 **uv**
|
|
25
|
+
- 📦 **poetry**
|
|
26
|
+
- 📦 **pipx**
|
|
27
|
+
|
|
28
|
+
# Usage
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Installing the Aikido Safe Chain is easy with our one-line installer.
|
|
35
|
+
|
|
36
|
+
### Unix/Linux/macOS
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Windows (PowerShell)
|
|
43
|
+
|
|
44
|
+
```powershell
|
|
45
|
+
iex (iwr "https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.ps1" -UseBasicParsing)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Pinning to a specific version
|
|
49
|
+
|
|
50
|
+
To install a specific version instead of the latest, replace `latest` with the version number in the URL (available from version 1.3.2 onwards):
|
|
51
|
+
|
|
52
|
+
**Unix/Linux/macOS:**
|
|
53
|
+
|
|
54
|
+
```shell
|
|
55
|
+
curl -fsSL https://github.com/AikidoSec/safe-chain/releases/download/x.x.x/install-safe-chain.sh | sh
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Windows (PowerShell):**
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
iex (iwr "https://github.com/AikidoSec/safe-chain/releases/download/x.x.x/install-safe-chain.ps1" -UseBasicParsing)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
You can find all available versions on the [releases page](https://github.com/AikidoSec/safe-chain/releases).
|
|
65
|
+
|
|
66
|
+
### Verify the installation
|
|
67
|
+
|
|
68
|
+
1. **❗Restart your terminal** to start using the Aikido Safe Chain.
|
|
69
|
+
- This step is crucial as it ensures that the shell aliases for npm, npx, yarn, pnpm, pnpx, bun, bunx, pip, pip3, poetry, uv and pipx are loaded correctly. If you do not restart your terminal, the aliases will not be available.
|
|
70
|
+
|
|
71
|
+
2. **Verify the installation** by running the verification command:
|
|
72
|
+
|
|
73
|
+
```shell
|
|
74
|
+
npm safe-chain-verify
|
|
75
|
+
pnpm safe-chain-verify
|
|
76
|
+
pip safe-chain-verify
|
|
77
|
+
uv safe-chain-verify
|
|
78
|
+
|
|
79
|
+
# Any other supported package manager: {packagemanager} safe-chain-verify
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- The output should display "OK: Safe-chain works!" confirming that Aikido Safe Chain is properly installed and running.
|
|
83
|
+
|
|
84
|
+
3. **(Optional) Test malware blocking** by attempting to install a test package:
|
|
85
|
+
|
|
86
|
+
For JavaScript/Node.js:
|
|
87
|
+
|
|
88
|
+
```shell
|
|
89
|
+
npm install safe-chain-test
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
For Python:
|
|
93
|
+
|
|
94
|
+
```shell
|
|
95
|
+
pip3 install safe-chain-pi-test
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- The output should show that Aikido Safe Chain is blocking the installation of these test packages as they are flagged as malware.
|
|
99
|
+
|
|
100
|
+
When running `npm`, `npx`, `yarn`, `pnpm`, `pnpx`, `bun`, `bunx`, `pip`, `pip3`, `uv`, `poetry` and `pipx` commands, the Aikido Safe Chain will automatically check for malware in the packages you are trying to install. It also intercepts Python module invocations for pip when available (e.g., `python -m pip install ...`, `python3 -m pip download ...`). If any malware is detected, it will prompt you to exit the command.
|
|
101
|
+
|
|
102
|
+
You can check the installed version by running:
|
|
103
|
+
|
|
104
|
+
```shell
|
|
105
|
+
safe-chain --version
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## How it works
|
|
109
|
+
|
|
110
|
+
### Malware Blocking
|
|
111
|
+
|
|
112
|
+
The Aikido Safe Chain works by running a lightweight proxy server that intercepts package downloads from the npm registry and PyPI. When you run npm, npx, yarn, pnpm, pnpx, bun, bunx, pip, pip3, uv, poetry or pipx commands, all package downloads are routed through this local proxy, which verifies packages in real-time against **[Aikido Intel - Open Sources Threat Intelligence](https://intel.aikido.dev/?tab=malware)**. If malware is detected in any package (including deep dependencies), the proxy blocks the download before the malicious code reaches your machine.
|
|
113
|
+
|
|
114
|
+
### Minimum package age
|
|
115
|
+
|
|
116
|
+
Safe Chain applies minimum package age checks to supported ecosystems.
|
|
117
|
+
|
|
118
|
+
Current enforcement differs by ecosystem:
|
|
119
|
+
|
|
120
|
+
- npm-based package managers:
|
|
121
|
+
- during normal package resolution, Safe Chain suppresses versions that are newer than the configured minimum age from the package metadata returned by the registry
|
|
122
|
+
- for direct package download requests that bypass that metadata flow, Safe Chain can block the request itself using a cached list of newly released packages
|
|
123
|
+
- Python package managers:
|
|
124
|
+
- during package resolution, Safe Chain suppresses too-young files and releases from PyPI metadata responses
|
|
125
|
+
- for direct package download requests that bypass that metadata flow, Safe Chain can block the request itself using a cached list of newly released packages
|
|
126
|
+
|
|
127
|
+
By default, the minimum package age is 48 hours. This provides an additional security layer during the critical period when newly published packages are most vulnerable to containing undetected threats. You can configure this threshold or bypass this protection entirely - see the [Minimum Package Age Configuration](#minimum-package-age) section below.
|
|
128
|
+
|
|
129
|
+
### Shell Integration
|
|
130
|
+
|
|
131
|
+
The Aikido Safe Chain integrates with your shell to provide a seamless experience when using npm, npx, yarn, pnpm, pnpx, bun, bunx, and Python package managers (pip, uv, poetry, pipx). It sets up aliases for these commands so that they are wrapped by the Aikido Safe Chain commands, which manage the proxy server before executing the original commands. We currently support:
|
|
132
|
+
|
|
133
|
+
- ✅ **Bash**
|
|
134
|
+
- ✅ **Zsh**
|
|
135
|
+
- ✅ **Fish**
|
|
136
|
+
- ✅ **PowerShell**
|
|
137
|
+
- ✅ **PowerShell Core**
|
|
138
|
+
|
|
139
|
+
More information about the shell integration can be found in the [shell integration documentation](https://github.com/AikidoSec/safe-chain/blob/main/docs/shell-integration.md).
|
|
140
|
+
|
|
141
|
+
## Uninstallation
|
|
142
|
+
|
|
143
|
+
To uninstall the Aikido Safe Chain, use our one-line uninstaller:
|
|
144
|
+
|
|
145
|
+
### Unix/Linux/macOS
|
|
146
|
+
|
|
147
|
+
```shell
|
|
148
|
+
curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/uninstall-safe-chain.sh | sh
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Windows (PowerShell)
|
|
152
|
+
|
|
153
|
+
```powershell
|
|
154
|
+
iex (iwr "https://github.com/AikidoSec/safe-chain/releases/latest/download/uninstall-safe-chain.ps1" -UseBasicParsing)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**❗Restart your terminal** after uninstalling to ensure all aliases are removed.
|
|
158
|
+
|
|
159
|
+
# Configuration
|
|
160
|
+
|
|
161
|
+
## Logging
|
|
162
|
+
|
|
163
|
+
You can control the output from Aikido Safe Chain using the `--safe-chain-logging` flag or the `SAFE_CHAIN_LOGGING` environment variable.
|
|
164
|
+
|
|
165
|
+
### Configuration Options
|
|
166
|
+
|
|
167
|
+
You can set the logging level through multiple sources (in order of priority):
|
|
168
|
+
|
|
169
|
+
1. **CLI Argument** (highest priority):
|
|
170
|
+
- `--safe-chain-logging=silent` - Suppresses all Aikido Safe Chain output except when malware is blocked. The package manager output is written to stdout as normal, and Safe Chain only writes a short message if it has blocked malware and causes the process to exit.
|
|
171
|
+
|
|
172
|
+
```shell
|
|
173
|
+
npm install express --safe-chain-logging=silent
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
- `--safe-chain-logging=verbose` - Enables detailed diagnostic output from Aikido Safe Chain. Useful for troubleshooting issues or understanding what Safe Chain is doing behind the scenes.
|
|
177
|
+
|
|
178
|
+
```shell
|
|
179
|
+
npm install express --safe-chain-logging=verbose
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
2. **Environment Variable**:
|
|
183
|
+
|
|
184
|
+
```shell
|
|
185
|
+
export SAFE_CHAIN_LOGGING=verbose
|
|
186
|
+
npm install express
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Valid values: `silent`, `normal`, `verbose`
|
|
190
|
+
|
|
191
|
+
This is useful for setting a default logging level for all package manager commands in your terminal session or CI/CD environment.
|
|
192
|
+
|
|
193
|
+
## Minimum Package Age
|
|
194
|
+
|
|
195
|
+
You can configure how long packages must exist before Safe Chain allows their installation. By default, packages must be at least 48 hours old before they can be installed.
|
|
196
|
+
|
|
197
|
+
For npm-based package managers, this check currently has two enforcement modes:
|
|
198
|
+
|
|
199
|
+
- Safe Chain suppresses too-young versions from package metadata during normal dependency resolution.
|
|
200
|
+
- Safe Chain blocks direct package download requests when they are matched against the cached newly released packages list.
|
|
201
|
+
|
|
202
|
+
For Python package managers, this check currently has two enforcement modes:
|
|
203
|
+
|
|
204
|
+
- Safe Chain suppresses too-young files and releases from PyPI metadata during dependency resolution.
|
|
205
|
+
- Safe Chain blocks direct package download requests when they are matched against the cached newly released packages list.
|
|
206
|
+
|
|
207
|
+
### Configuration Options
|
|
208
|
+
|
|
209
|
+
You can set the minimum package age through multiple sources (in order of priority):
|
|
210
|
+
|
|
211
|
+
1. **CLI Argument** (highest priority):
|
|
212
|
+
|
|
213
|
+
```shell
|
|
214
|
+
npm install express --safe-chain-minimum-package-age-hours=48
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
2. **Environment Variable**:
|
|
218
|
+
|
|
219
|
+
```shell
|
|
220
|
+
export SAFE_CHAIN_MINIMUM_PACKAGE_AGE_HOURS=48
|
|
221
|
+
npm install express
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
3. **Config File** (`~/.safe-chain/config.json`):
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"minimumPackageAgeHours": 48
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Excluding Packages
|
|
233
|
+
|
|
234
|
+
Exclude trusted packages from minimum age filtering via environment variable or config file (both are merged). Use `@scope/*` to trust all packages from an organization:
|
|
235
|
+
|
|
236
|
+
```shell
|
|
237
|
+
export SAFE_CHAIN_MINIMUM_PACKAGE_AGE_EXCLUSIONS="@aikidosec/*"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"npm": {
|
|
243
|
+
"minimumPackageAgeExclusions": ["@aikidosec/*"]
|
|
244
|
+
},
|
|
245
|
+
"pip": {
|
|
246
|
+
"minimumPackageAgeExclusions": ["requests"]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Custom Registries
|
|
252
|
+
|
|
253
|
+
Configure Safe Chain to scan packages from custom or private registries.
|
|
254
|
+
|
|
255
|
+
Supported ecosystems:
|
|
256
|
+
|
|
257
|
+
- Node.js
|
|
258
|
+
- Python
|
|
259
|
+
|
|
260
|
+
### Configuration Options
|
|
261
|
+
|
|
262
|
+
You can set custom registries through environment variable or config file. Both sources are merged together.
|
|
263
|
+
|
|
264
|
+
1. **Environment Variable** (comma-separated):
|
|
265
|
+
|
|
266
|
+
```shell
|
|
267
|
+
export SAFE_CHAIN_NPM_CUSTOM_REGISTRIES="npm.company.com,registry.internal.net"
|
|
268
|
+
export SAFE_CHAIN_PIP_CUSTOM_REGISTRIES="pip.company.com,registry.internal.net"
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
2. **Config File** (`~/.safe-chain/config.json`):
|
|
272
|
+
|
|
273
|
+
```json
|
|
274
|
+
{
|
|
275
|
+
"npm": {
|
|
276
|
+
"customRegistries": ["npm.company.com", "registry.internal.net"]
|
|
277
|
+
},
|
|
278
|
+
"pip": {
|
|
279
|
+
"customRegistries": ["pip.company.com", "registry.internal.net"]
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Malware List Base URL
|
|
285
|
+
|
|
286
|
+
Configure Safe Chain to fetch malware databases and new packages lists from a custom mirror URL. This allows you to host your own copy of the Aikido malware database.
|
|
287
|
+
|
|
288
|
+
### Configuration Options
|
|
289
|
+
|
|
290
|
+
You can set the malware list base URL through multiple sources (in order of priority):
|
|
291
|
+
|
|
292
|
+
1. **CLI Argument** (highest priority):
|
|
293
|
+
|
|
294
|
+
```shell
|
|
295
|
+
npm install express --safe-chain-malware-list-base-url=https://your-mirror.com
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
2. **Environment Variable**:
|
|
299
|
+
|
|
300
|
+
```shell
|
|
301
|
+
export SAFE_CHAIN_MALWARE_LIST_BASE_URL=https://your-mirror.com
|
|
302
|
+
npm install express
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
3. **Config File** (`~/.safe-chain/config.json`):
|
|
306
|
+
|
|
307
|
+
```json
|
|
308
|
+
{
|
|
309
|
+
"malwareListBaseUrl": "https://your-mirror.com"
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
The base URL should point to a server that mirrors the structure of `https://malware-list.aikido.dev/`, including the following paths:
|
|
314
|
+
- `/malware_predictions.json` (JavaScript ecosystem malware database)
|
|
315
|
+
- `/malware_pypi.json` (Python ecosystem malware database)
|
|
316
|
+
- `/releases/npm.json` (JavaScript new packages list)
|
|
317
|
+
- `/releases/pypi.json` (Python new packages list)
|
|
318
|
+
|
|
319
|
+
# Usage in CI/CD
|
|
320
|
+
|
|
321
|
+
You can protect your CI/CD pipelines from malicious packages by integrating Aikido Safe Chain into your build process. This ensures that any packages installed during your automated builds are checked for malware before installation.
|
|
322
|
+
|
|
323
|
+
## Installation for CI/CD
|
|
324
|
+
|
|
325
|
+
Use the `--ci` flag to automatically configure Aikido Safe Chain for CI/CD environments. This sets up executable shims in the PATH instead of shell aliases.
|
|
326
|
+
|
|
327
|
+
### Unix/Linux/macOS (GitHub Actions, Azure Pipelines, etc.)
|
|
328
|
+
|
|
329
|
+
```shell
|
|
330
|
+
curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Windows (Azure Pipelines, etc.)
|
|
334
|
+
|
|
335
|
+
```powershell
|
|
336
|
+
iex "& { $(iwr 'https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.ps1' -UseBasicParsing) } -ci"
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Supported Platforms
|
|
340
|
+
|
|
341
|
+
- ✅ **GitHub Actions**
|
|
342
|
+
- ✅ **Azure Pipelines**
|
|
343
|
+
- ✅ **CircleCI**
|
|
344
|
+
- ✅ **Jenkins**
|
|
345
|
+
- ✅ **Bitbucket Pipelines**
|
|
346
|
+
- ✅ **GitLab Pipelines**
|
|
347
|
+
|
|
348
|
+
## GitHub Actions Example
|
|
349
|
+
|
|
350
|
+
```yaml
|
|
351
|
+
- name: Setup Node.js
|
|
352
|
+
uses: actions/setup-node@v4
|
|
353
|
+
with:
|
|
354
|
+
node-version: "22"
|
|
355
|
+
cache: "npm"
|
|
356
|
+
|
|
357
|
+
- name: Install safe-chain
|
|
358
|
+
run: curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci
|
|
359
|
+
|
|
360
|
+
- name: Install dependencies
|
|
361
|
+
run: npm ci
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Azure DevOps Example
|
|
365
|
+
|
|
366
|
+
```yaml
|
|
367
|
+
- task: NodeTool@0
|
|
368
|
+
inputs:
|
|
369
|
+
versionSpec: "22.x"
|
|
370
|
+
displayName: "Install Node.js"
|
|
371
|
+
|
|
372
|
+
- script: curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci
|
|
373
|
+
displayName: "Install safe-chain"
|
|
374
|
+
|
|
375
|
+
- script: npm ci
|
|
376
|
+
displayName: "Install dependencies"
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## CircleCI Example
|
|
380
|
+
|
|
381
|
+
```yaml
|
|
382
|
+
version: 2.1
|
|
383
|
+
jobs:
|
|
384
|
+
build:
|
|
385
|
+
docker:
|
|
386
|
+
- image: cimg/node:lts
|
|
387
|
+
steps:
|
|
388
|
+
- checkout
|
|
389
|
+
- run: |
|
|
390
|
+
curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci
|
|
391
|
+
- run: npm ci
|
|
392
|
+
workflows:
|
|
393
|
+
build_and_test:
|
|
394
|
+
jobs:
|
|
395
|
+
- build
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Jenkins Example
|
|
399
|
+
|
|
400
|
+
Note: This assumes Node.js and npm are installed on the Jenkins agent.
|
|
401
|
+
|
|
402
|
+
```groovy
|
|
403
|
+
pipeline {
|
|
404
|
+
agent any
|
|
405
|
+
|
|
406
|
+
environment {
|
|
407
|
+
// Jenkins does not automatically persist PATH updates from setup-ci,
|
|
408
|
+
// so add the shims + binary directory explicitly for all stages.
|
|
409
|
+
PATH = "${env.HOME}/.safe-chain/shims:${env.HOME}/.safe-chain/bin:${env.PATH}"
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
stages {
|
|
413
|
+
stage('Install safe-chain') {
|
|
414
|
+
steps {
|
|
415
|
+
sh '''
|
|
416
|
+
set -euo pipefail
|
|
417
|
+
|
|
418
|
+
# Install Safe Chain for CI
|
|
419
|
+
curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci
|
|
420
|
+
'''
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
stage('Install project dependencies etc...') {
|
|
425
|
+
steps {
|
|
426
|
+
sh '''
|
|
427
|
+
set -euo pipefail
|
|
428
|
+
npm ci
|
|
429
|
+
'''
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
## Bitbucket Pipelines Example
|
|
437
|
+
|
|
438
|
+
```yaml
|
|
439
|
+
image: node:22
|
|
440
|
+
|
|
441
|
+
steps:
|
|
442
|
+
- step:
|
|
443
|
+
name: Install
|
|
444
|
+
script:
|
|
445
|
+
- curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci
|
|
446
|
+
- export PATH=~/.safe-chain/shims:$PATH
|
|
447
|
+
- npm ci
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
After setup, all subsequent package manager commands in your CI pipeline will automatically be protected by Aikido Safe Chain's malware detection.
|
|
451
|
+
|
|
452
|
+
## GitLab Pipelines Example
|
|
453
|
+
|
|
454
|
+
To add safe-chain in GitLab pipelines, you need to install it in the image running the pipeline. This can be done by:
|
|
455
|
+
|
|
456
|
+
1. Define a dockerfile to run your build
|
|
457
|
+
|
|
458
|
+
```dockerfile
|
|
459
|
+
FROM node:lts
|
|
460
|
+
|
|
461
|
+
# Install safe-chain
|
|
462
|
+
RUN curl -fsSL https://github.com/AikidoSec/safe-chain/releases/latest/download/install-safe-chain.sh | sh -s -- --ci
|
|
463
|
+
|
|
464
|
+
# Add safe-chain to PATH
|
|
465
|
+
ENV PATH="/root/.safe-chain/shims:/root/.safe-chain/bin:${PATH}"
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
2. Build the Docker image in your CI pipeline
|
|
469
|
+
|
|
470
|
+
```yaml
|
|
471
|
+
build-image:
|
|
472
|
+
stage: build-image
|
|
473
|
+
image: docker:latest
|
|
474
|
+
services:
|
|
475
|
+
- docker:dind
|
|
476
|
+
script:
|
|
477
|
+
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
|
478
|
+
- docker build -t $CI_REGISTRY_IMAGE:latest .
|
|
479
|
+
- docker push $CI_REGISTRY_IMAGE:latest
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
3. Use the image in your pipeline:
|
|
483
|
+
```yaml
|
|
484
|
+
npm-ci:
|
|
485
|
+
stage: install
|
|
486
|
+
image: $CI_REGISTRY_IMAGE:latest
|
|
487
|
+
script:
|
|
488
|
+
- npm ci
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
The full pipeline for this example looks like this:
|
|
492
|
+
|
|
493
|
+
```yaml
|
|
494
|
+
stages:
|
|
495
|
+
- build-image
|
|
496
|
+
- install
|
|
497
|
+
|
|
498
|
+
build-image:
|
|
499
|
+
stage: build-image
|
|
500
|
+
image: docker:latest
|
|
501
|
+
services:
|
|
502
|
+
- docker:dind
|
|
503
|
+
script:
|
|
504
|
+
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
|
505
|
+
- docker build -t $CI_REGISTRY_IMAGE:latest .
|
|
506
|
+
- docker push $CI_REGISTRY_IMAGE:latest
|
|
507
|
+
|
|
508
|
+
npm-ci:
|
|
509
|
+
stage: install
|
|
510
|
+
image: $CI_REGISTRY_IMAGE:latest
|
|
511
|
+
script:
|
|
512
|
+
- npm ci
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
# Troubleshooting
|
|
516
|
+
|
|
517
|
+
Having issues? See the [Troubleshooting Guide](https://help.aikido.dev/code-scanning/aikido-malware-scanning/safe-chain-troubleshooting) for help with common problems.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
setEcoSystem(ECOSYSTEM_JS);
|
|
8
|
+
const packageManagerName = "bun";
|
|
9
|
+
initializePackageManager(packageManagerName);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
setEcoSystem(ECOSYSTEM_JS);
|
|
8
|
+
const packageManagerName = "bunx";
|
|
9
|
+
initializePackageManager(packageManagerName);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
setEcoSystem(ECOSYSTEM_JS);
|
|
8
|
+
const packageManagerName = "npm";
|
|
9
|
+
initializePackageManager(packageManagerName);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
setEcoSystem(ECOSYSTEM_JS);
|
|
8
|
+
const packageManagerName = "npx";
|
|
9
|
+
initializePackageManager(packageManagerName);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_PY } from "../src/config/settings.js";
|
|
6
|
+
import { PIP_PACKAGE_MANAGER, PIP_COMMAND } from "../src/packagemanager/pip/pipSettings.js";
|
|
7
|
+
|
|
8
|
+
// Set eco system
|
|
9
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
10
|
+
|
|
11
|
+
initializePackageManager(PIP_PACKAGE_MANAGER, { tool: PIP_COMMAND, args: process.argv.slice(2) });
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
// Pass through only user-supplied pip args
|
|
15
|
+
var exitCode = await main(process.argv.slice(2));
|
|
16
|
+
process.exit(exitCode);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_PY } from "../src/config/settings.js";
|
|
6
|
+
import { PIP_PACKAGE_MANAGER, PIP3_COMMAND } from "../src/packagemanager/pip/pipSettings.js";
|
|
7
|
+
|
|
8
|
+
// Set eco system
|
|
9
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
10
|
+
|
|
11
|
+
initializePackageManager(PIP_PACKAGE_MANAGER, { tool: PIP3_COMMAND, args: process.argv.slice(2) });
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
// Pass through only user-supplied pip args
|
|
15
|
+
var exitCode = await main(process.argv.slice(2));
|
|
16
|
+
process.exit(exitCode);
|
|
17
|
+
})();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_PY } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
// Set eco system
|
|
8
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
9
|
+
|
|
10
|
+
initializePackageManager("pipx");
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
// Pass through only user-supplied pipx args
|
|
14
|
+
var exitCode = await main(process.argv.slice(2));
|
|
15
|
+
process.exit(exitCode);
|
|
16
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
setEcoSystem(ECOSYSTEM_JS);
|
|
8
|
+
const packageManagerName = "pnpm";
|
|
9
|
+
initializePackageManager(packageManagerName);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_JS } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
setEcoSystem(ECOSYSTEM_JS);
|
|
8
|
+
const packageManagerName = "pnpx";
|
|
9
|
+
initializePackageManager(packageManagerName);
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
var exitCode = await main(process.argv.slice(2));
|
|
13
|
+
process.exit(exitCode);
|
|
14
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { main } from "../src/main.js";
|
|
4
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_PY } from "../src/config/settings.js";
|
|
6
|
+
|
|
7
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
8
|
+
initializePackageManager("poetry");
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
var exitCode = await main(process.argv.slice(2));
|
|
12
|
+
process.exit(exitCode);
|
|
13
|
+
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { initializePackageManager } from "../src/packagemanager/currentPackageManager.js";
|
|
4
|
+
import { PIP_PACKAGE_MANAGER, PYTHON_COMMAND } from "../src/packagemanager/pip/pipSettings.js";
|
|
5
|
+
import { setEcoSystem, ECOSYSTEM_PY } from "../src/config/settings.js";
|
|
6
|
+
import { main } from "../src/main.js";
|
|
7
|
+
|
|
8
|
+
// Set eco system
|
|
9
|
+
setEcoSystem(ECOSYSTEM_PY);
|
|
10
|
+
|
|
11
|
+
// Strip nodejs and wrapper script from args
|
|
12
|
+
let argv = process.argv.slice(2);
|
|
13
|
+
|
|
14
|
+
initializePackageManager(PIP_PACKAGE_MANAGER, { tool: PYTHON_COMMAND, args: argv });
|
|
15
|
+
|
|
16
|
+
(async () => {
|
|
17
|
+
var exitCode = await main(argv);
|
|
18
|
+
process.exit(exitCode);
|
|
19
|
+
})();
|