@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.
Files changed (112) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +517 -0
  3. package/bin/aikido-bun.js +14 -0
  4. package/bin/aikido-bunx.js +14 -0
  5. package/bin/aikido-npm.js +14 -0
  6. package/bin/aikido-npx.js +14 -0
  7. package/bin/aikido-pip.js +17 -0
  8. package/bin/aikido-pip3.js +17 -0
  9. package/bin/aikido-pipx.js +16 -0
  10. package/bin/aikido-pnpm.js +14 -0
  11. package/bin/aikido-pnpx.js +14 -0
  12. package/bin/aikido-poetry.js +13 -0
  13. package/bin/aikido-python.js +19 -0
  14. package/bin/aikido-python3.js +19 -0
  15. package/bin/aikido-uv.js +16 -0
  16. package/bin/aikido-yarn.js +14 -0
  17. package/bin/safe-chain.js +130 -0
  18. package/docs/banner.svg +151 -0
  19. package/docs/safe-package-manager-demo.gif +0 -0
  20. package/docs/safe-package-manager-demo.png +0 -0
  21. package/docs/shell-integration.md +149 -0
  22. package/docs/troubleshooting.md +321 -0
  23. package/npm-shrinkwrap.json +4069 -0
  24. package/package.json +72 -0
  25. package/src/api/aikido.js +187 -0
  26. package/src/api/npmApi.js +71 -0
  27. package/src/config/cliArguments.js +161 -0
  28. package/src/config/configFile.js +327 -0
  29. package/src/config/environmentVariables.js +57 -0
  30. package/src/config/settings.js +247 -0
  31. package/src/environment/environment.js +14 -0
  32. package/src/environment/userInteraction.js +122 -0
  33. package/src/main.js +123 -0
  34. package/src/packagemanager/_shared/commandErrors.js +17 -0
  35. package/src/packagemanager/_shared/matchesCommand.js +18 -0
  36. package/src/packagemanager/bun/createBunPackageManager.js +48 -0
  37. package/src/packagemanager/currentPackageManager.js +79 -0
  38. package/src/packagemanager/npm/createPackageManager.js +72 -0
  39. package/src/packagemanager/npm/dependencyScanner/commandArgumentScanner.js +74 -0
  40. package/src/packagemanager/npm/dependencyScanner/nullScanner.js +9 -0
  41. package/src/packagemanager/npm/parsing/parsePackagesFromInstallArgs.js +144 -0
  42. package/src/packagemanager/npm/runNpmCommand.js +20 -0
  43. package/src/packagemanager/npm/utils/abbrevs-generated.js +359 -0
  44. package/src/packagemanager/npm/utils/cmd-list.js +174 -0
  45. package/src/packagemanager/npm/utils/npmCommands.js +34 -0
  46. package/src/packagemanager/npx/createPackageManager.js +15 -0
  47. package/src/packagemanager/npx/dependencyScanner/commandArgumentScanner.js +43 -0
  48. package/src/packagemanager/npx/parsing/parsePackagesFromArguments.js +130 -0
  49. package/src/packagemanager/npx/runNpxCommand.js +20 -0
  50. package/src/packagemanager/pip/createPackageManager.js +25 -0
  51. package/src/packagemanager/pip/pipSettings.js +6 -0
  52. package/src/packagemanager/pip/runPipCommand.js +209 -0
  53. package/src/packagemanager/pipx/createPipXPackageManager.js +18 -0
  54. package/src/packagemanager/pipx/runPipXCommand.js +60 -0
  55. package/src/packagemanager/pnpm/createPackageManager.js +57 -0
  56. package/src/packagemanager/pnpm/dependencyScanner/commandArgumentScanner.js +35 -0
  57. package/src/packagemanager/pnpm/parsing/parsePackagesFromArguments.js +109 -0
  58. package/src/packagemanager/pnpm/runPnpmCommand.js +32 -0
  59. package/src/packagemanager/poetry/createPoetryPackageManager.js +72 -0
  60. package/src/packagemanager/uv/createUvPackageManager.js +18 -0
  61. package/src/packagemanager/uv/runUvCommand.js +66 -0
  62. package/src/packagemanager/yarn/createPackageManager.js +41 -0
  63. package/src/packagemanager/yarn/dependencyScanner/commandArgumentScanner.js +35 -0
  64. package/src/packagemanager/yarn/parsing/parsePackagesFromArguments.js +128 -0
  65. package/src/packagemanager/yarn/runYarnCommand.js +36 -0
  66. package/src/registryProxy/certBundle.js +203 -0
  67. package/src/registryProxy/certUtils.js +178 -0
  68. package/src/registryProxy/getConnectTimeout.js +13 -0
  69. package/src/registryProxy/http-utils.js +80 -0
  70. package/src/registryProxy/interceptors/createInterceptorForEcoSystem.js +25 -0
  71. package/src/registryProxy/interceptors/interceptorBuilder.js +179 -0
  72. package/src/registryProxy/interceptors/minimumPackageAgeExclusions.js +33 -0
  73. package/src/registryProxy/interceptors/npm/modifyNpmInfo.js +180 -0
  74. package/src/registryProxy/interceptors/npm/npmInterceptor.js +101 -0
  75. package/src/registryProxy/interceptors/npm/parseNpmPackageUrl.js +60 -0
  76. package/src/registryProxy/interceptors/pip/modifyPipInfo.js +167 -0
  77. package/src/registryProxy/interceptors/pip/modifyPipJsonResponse.js +176 -0
  78. package/src/registryProxy/interceptors/pip/parsePipPackageUrl.js +162 -0
  79. package/src/registryProxy/interceptors/pip/pipInterceptor.js +122 -0
  80. package/src/registryProxy/interceptors/pip/pipMetadataResponseUtils.js +27 -0
  81. package/src/registryProxy/interceptors/pip/pipMetadataVersionUtils.js +131 -0
  82. package/src/registryProxy/interceptors/suppressedVersionsState.js +21 -0
  83. package/src/registryProxy/isImdsEndpoint.js +13 -0
  84. package/src/registryProxy/mitmRequestHandler.js +240 -0
  85. package/src/registryProxy/plainHttpProxy.js +95 -0
  86. package/src/registryProxy/registryProxy.js +255 -0
  87. package/src/registryProxy/tunnelRequestHandler.js +213 -0
  88. package/src/scanning/audit/index.js +129 -0
  89. package/src/scanning/index.js +82 -0
  90. package/src/scanning/malwareDatabase.js +131 -0
  91. package/src/scanning/newPackagesDatabaseBuilder.js +71 -0
  92. package/src/scanning/newPackagesDatabaseWarnings.js +17 -0
  93. package/src/scanning/newPackagesListCache.js +126 -0
  94. package/src/scanning/packageNameVariants.js +29 -0
  95. package/src/shell-integration/helpers.js +304 -0
  96. package/src/shell-integration/path-wrappers/templates/unix-wrapper.template.sh +22 -0
  97. package/src/shell-integration/path-wrappers/templates/windows-wrapper.template.cmd +24 -0
  98. package/src/shell-integration/setup-ci.js +172 -0
  99. package/src/shell-integration/setup.js +129 -0
  100. package/src/shell-integration/shellDetection.js +39 -0
  101. package/src/shell-integration/startup-scripts/init-fish.fish +115 -0
  102. package/src/shell-integration/startup-scripts/init-posix.sh +96 -0
  103. package/src/shell-integration/startup-scripts/init-pwsh.ps1 +171 -0
  104. package/src/shell-integration/supported-shells/bash.js +152 -0
  105. package/src/shell-integration/supported-shells/fish.js +95 -0
  106. package/src/shell-integration/supported-shells/powershell.js +100 -0
  107. package/src/shell-integration/supported-shells/windowsPowershell.js +100 -0
  108. package/src/shell-integration/supported-shells/zsh.js +92 -0
  109. package/src/shell-integration/teardown.js +112 -0
  110. package/src/ultimate/ultimateTroubleshooting.js +111 -0
  111. package/src/utils/safeSpawn.js +153 -0
  112. package/tsconfig.json +21 -0
@@ -0,0 +1,321 @@
1
+ # Troubleshooting
2
+
3
+ This guide helps you diagnose and resolve common issues with Aikido Safe Chain.
4
+
5
+ ## Verification & Diagnostics
6
+
7
+ ### Check Installation
8
+
9
+ ```bash
10
+ # Check version
11
+ safe-chain --version
12
+ ```
13
+
14
+ ### Verify Shell Integration
15
+
16
+ Run the verification command for your package manager:
17
+
18
+ ```bash
19
+ npm safe-chain-verify
20
+ pnpm safe-chain-verify
21
+ pip safe-chain-verify
22
+ uv safe-chain-verify
23
+
24
+ # Any other supported package manager: {packagemanager} safe-chain-verify
25
+ ```
26
+
27
+ Expected output: `OK: Safe-chain works!`
28
+
29
+ ### Test Malware Blocking
30
+
31
+ Verify that malware detection is working:
32
+
33
+ **For JavaScript/Node.js:**
34
+
35
+ ```bash
36
+ npm install safe-chain-test
37
+ ```
38
+
39
+ **For Python:**
40
+
41
+ ```bash
42
+ pip3 install safe-chain-pi-test
43
+ ```
44
+
45
+ These test packages are flagged as malware and should be blocked by Safe Chain.
46
+
47
+ **If the test package installs successfully instead of being blocked**, see [Malware Not Being Blocked](#malware-not-being-blocked) below.
48
+
49
+ ### Logging Options
50
+
51
+ Use logging flags or environment variables to get more information:
52
+
53
+ ```bash
54
+ # Verbose mode - detailed diagnostic output for troubleshooting
55
+ npm install express --safe-chain-logging=verbose
56
+
57
+ # Or set it globally for all commands in your session
58
+ export SAFE_CHAIN_LOGGING=verbose
59
+ npm install express
60
+
61
+ # Silent mode - suppress all output except malware blocking
62
+ npm install express --safe-chain-logging=silent
63
+ ```
64
+
65
+ ## Common Issues
66
+
67
+ ### Malware Not Being Blocked
68
+
69
+ **Symptom:** Test malware packages (like `safe-chain-test`) install successfully when they should be blocked
70
+
71
+ **Most Common Cause:** The package is cached in your package manager's local store
72
+
73
+ Safe-chain blocks malicious packages by intercepting network requests to package registries using its proxy.
74
+
75
+ When a package is already cached locally, the package manager skips downloading it from the registry, which bypasses the proxy.
76
+
77
+ **Resolution Steps:**
78
+
79
+ 1. **Clear your package manager's cache:**
80
+
81
+ ```bash
82
+ # For npm
83
+ npm cache clean --force
84
+
85
+ # For pnpm
86
+ pnpm store prune
87
+
88
+ # For yarn (classic)
89
+ yarn cache clean
90
+
91
+ # For yarn (berry/v2+)
92
+ yarn cache clean --all
93
+
94
+ # For bun
95
+ bun pm cache rm
96
+ ```
97
+
98
+ > **⚠️ Warning:** Cache clearing is safe but will remove all cached packages. Subsequent installations will need to re-download packages. In CI/CD environments or monorepos, this may affect build times.
99
+
100
+ 2. **Clean local installation artifacts:**
101
+
102
+ ```bash
103
+ # Remove node_modules if you want a completely fresh install
104
+ rm -rf node_modules
105
+ ```
106
+
107
+ 3. **Re-test malware blocking:**
108
+
109
+ ```bash
110
+ npm install safe-chain-test # Should be blocked
111
+ ```
112
+
113
+ ### Shell Aliases Not Working After Installation
114
+
115
+ **Symptom:** Running `npm` shows regular npm instead of safe-chain wrapped version
116
+
117
+ **First step:** Restart your terminal (most common fix)
118
+
119
+ **Verify it's working:**
120
+
121
+ ```bash
122
+ type npm
123
+ ```
124
+
125
+ Should show: `npm is a function`
126
+
127
+ **If still not working:**
128
+
129
+ Check that your startup file sources safe-chain scripts from `~/.safe-chain/scripts/`:
130
+
131
+ - Bash: `~/.bashrc`
132
+ - Zsh: `~/.zshrc`
133
+ - Fish: `~/.config/fish/config.fish`
134
+ - PowerShell: `$PROFILE`
135
+
136
+ ### "Command Not Found: safe-chain"
137
+
138
+ **Symptom:** Binary not found in PATH
139
+
140
+ **First step:** Restart your terminal
141
+
142
+ **Check PATH:**
143
+
144
+ ```bash
145
+ echo $PATH
146
+ ```
147
+
148
+ Should include `~/.safe-chain/bin`
149
+
150
+ **If persists:** Re-run the installation script
151
+
152
+ ### PowerShell Execution Policy Blocks Scripts (Windows)
153
+
154
+ **Symptom:** When opening PowerShell, you see an error like:
155
+
156
+ ```
157
+ . : File C:\Users\<username>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because
158
+ running scripts is disabled on this system.
159
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
160
+ FullyQualifiedErrorId : UnauthorizedAccess
161
+ ```
162
+
163
+ **Cause:** Windows PowerShell's default execution policy (`Restricted`) blocks all script execution, including safe-chain's initialization script that's sourced from your PowerShell profile.
164
+
165
+ **Resolution:**
166
+
167
+ 1. **Set the execution policy to allow local scripts:**
168
+
169
+ Open PowerShell as Administrator and run:
170
+
171
+ ```powershell
172
+ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
173
+ ```
174
+
175
+ This allows:
176
+ - Local scripts (like safe-chain's) to run without signing
177
+ - Downloaded scripts to run only if signed by a trusted publisher
178
+
179
+ 2. **Restart PowerShell** and verify the error is resolved.
180
+
181
+ > **Note:** `RemoteSigned` is Microsoft's recommended execution policy for client computers. It provides a good balance between security and usability.
182
+
183
+ ### Shell Aliases Persist After Uninstallation
184
+
185
+ **Symptom:** safe-chain commands still active after running uninstall script
186
+
187
+ **Steps:**
188
+
189
+ 1. Run `safe-chain teardown` (if binary still exists)
190
+ 2. Restart your terminal
191
+ 3. If still present, manually edit shell config files:
192
+ - Bash: `~/.bashrc`
193
+ - Zsh: `~/.zshrc`
194
+ - Fish: `~/.config/fish/config.fish`
195
+ - PowerShell: `$PROFILE`
196
+ 4. Remove lines that source scripts from `~/.safe-chain/scripts/`
197
+ 5. Restart terminal again
198
+
199
+ ## Manual Verification Steps
200
+
201
+ ### Check Installation Status
202
+
203
+ ```bash
204
+ # Check installation location (helps identify if installed via npm or as standalone binary)
205
+ which safe-chain
206
+
207
+ # Verify binary exists
208
+ ls ~/.safe-chain/bin/safe-chain
209
+
210
+ # Check version
211
+ safe-chain --version
212
+
213
+ # Test shell integration
214
+ type npm
215
+ type pip
216
+ ```
217
+
218
+ **Expected `which` output:**
219
+
220
+ - Standalone binary (correct): `~/.safe-chain/bin/safe-chain` or `/Users/<username>/.safe-chain/bin/safe-chain`
221
+ - npm global (outdated): path containing `node_modules` or nvm version paths
222
+
223
+ If `which` shows an npm installation, see [Check for Conflicting Installations](#check-for-conflicting-installations).
224
+
225
+ ### Check Shell Integration
226
+
227
+ ```bash
228
+ # Which shell you're using
229
+ echo $SHELL
230
+
231
+ # Check if startup file sources safe-chain
232
+ # For Bash:
233
+ grep safe-chain ~/.bashrc
234
+
235
+ # For Zsh:
236
+ grep safe-chain ~/.zshrc
237
+
238
+ # For Fish:
239
+ grep safe-chain ~/.config/fish/config.fish
240
+
241
+ # Verify scripts exist
242
+ ls ~/.safe-chain/scripts/
243
+ ```
244
+
245
+ ### Check for Conflicting Installations
246
+
247
+ > **Note:** The install/uninstall scripts automatically detect and remove conflicting installations, but you can manually check:
248
+
249
+ ```bash
250
+ # Check npm global
251
+ npm list -g @aikidosec/safe-chain
252
+
253
+ # Check Volta
254
+ volta list safe-chain
255
+
256
+ # Check nvm (all versions)
257
+ for version in $(nvm list | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+'); do
258
+ nvm exec "$version" npm list -g @aikidosec/safe-chain 2>/dev/null && echo "Found in $version"
259
+ done
260
+ ```
261
+
262
+ ## Manual Cleanup
263
+
264
+ > **Note:** The install and uninstall scripts automatically handle these cleanup steps. Use these manual commands only if automatic cleanup fails.
265
+
266
+ ### Remove npm Global Installation
267
+
268
+ ```bash
269
+ npm uninstall -g @aikidosec/safe-chain
270
+ ```
271
+
272
+ ### Remove Volta Installation
273
+
274
+ ```bash
275
+ volta uninstall @aikidosec/safe-chain
276
+ ```
277
+
278
+ ### Remove nvm Installations (All Versions)
279
+
280
+ ```bash
281
+ # Automated approach
282
+ for version in $(nvm list | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+'); do
283
+ nvm exec "$version" npm uninstall -g @aikidosec/safe-chain
284
+ done
285
+
286
+ # Or manual per version
287
+ nvm use <version>
288
+ npm uninstall -g @aikidosec/safe-chain
289
+ ```
290
+
291
+ ### Clean Shell Configuration Files
292
+
293
+ Manually remove safe-chain entries from:
294
+
295
+ - Bash: `~/.bashrc`
296
+ - Zsh: `~/.zshrc`
297
+ - Fish: `~/.config/fish/config.fish`
298
+ - PowerShell: `$PROFILE`
299
+
300
+ Look for and remove:
301
+
302
+ - Lines sourcing from `~/.safe-chain/scripts/`
303
+ - Any safe-chain related function definitions
304
+
305
+ ### Remove Installation Directory
306
+
307
+ ```bash
308
+ rm -rf ~/.safe-chain
309
+ ```
310
+
311
+ ### Report Issues
312
+
313
+ If you encounter problems:
314
+
315
+ 1. Visit [GitHub Issues](https://github.com/AikidoSec/safe-chain/issues)
316
+ 2. Include:
317
+ - Operating system and version
318
+ - Shell type and version
319
+ - `safe-chain --version` output
320
+ - Output from verification commands
321
+ - Verbose logs of the failing command (add the `--safe-chain-logging=verbose` argument)