@aikidosec/safe-chain 1.0.13 → 1.0.14

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # Aikido Safe Chain
2
2
 
3
+ The Aikido Safe Chain **prevents developers from installing malware** on their workstations through npm, npx, or yarn.
4
+
3
5
  The Aikido Safe Chain wraps around the [npm cli](https://github.com/npm/cli), [npx](https://github.com/npm/cli/blob/latest/docs/content/commands/npx.md), and [yarn](https://yarnpkg.com/) to provide extra checks before installing new packages. This tool will detect when a package contains malware and prompt you to exit, preventing npm, npx, or yarn from downloading or running the malware.
4
6
 
5
7
  ![demo](https://aikido-production-staticfiles-public.s3.eu-west-1.amazonaws.com/safe-pkg.gif)
@@ -9,6 +11,9 @@ Aikido Safe Chain works on Node.js version 18 and above and supports the followi
9
11
  - ✅ **npm**
10
12
  - ✅ **npx**
11
13
  - ✅ **yarn**
14
+ - 🚧 **pnpm** Coming soon
15
+
16
+ # Usage
12
17
 
13
18
  ## Installation
14
19
 
@@ -29,35 +34,22 @@ Installing the Aikido Safe Chain is easy. You just need 3 simple steps:
29
34
  npm install eslint-js
30
35
  ```
31
36
  - The output should show that Aikido Safe Chain is blocking the installation of this package as it is flagged as malware.
32
- ![Output of vulneralbe package](./docs/vulnerable-package-message.png)
33
37
 
34
38
  When running `npm`, `npx`, or `yarn` commands, the Aikido Safe Chain will automatically check for malware in the packages you are trying to install. If any malware is detected, it will prompt you to exit the command.
35
39
 
36
- ## Shell Integration
37
-
38
- The Aikido Safe Chain integrates with your shell to provide a seamless experience when using npm, npx, and yarn commands. It sets up aliases for these commands so that they are replaced with the Aikido Safe Chain commands, which perform malware checks before executing the original commands.
40
+ ## How it works
39
41
 
40
- More information about the shell integration can be found in the [shell integration documentation](docs/shell-integration.md).
42
+ The Aikido Safe Chain works by intercepting the npm, npx, and yarn commands and verifying the packages against **[Aikido Intel - Open Sources Threat Intelligence](https://intel.aikido.dev/?tab=malware)**.
41
43
 
42
- Shell integration is supported for the following shells:
44
+ The Aikido Safe Chain integrates with your shell to provide a seamless experience when using npm, npx, and yarn commands. It sets up aliases for these commands so that they are wrapped by the Aikido Safe Chain commands, which perform malware checks before executing the original commands. We currently support:
43
45
 
44
46
  - ✅ **Bash**
45
47
  - ✅ **Zsh**
46
48
  - ✅ **Fish**
47
- - ✅ **Powershell**
49
+ - ✅ **PowerShell**
48
50
  - ✅ **PowerShell Core**
49
51
 
50
- ### Disabling Shell Integration
51
-
52
- To disable the Aikido Safe Chain integration, run:
53
-
54
- ```shell
55
- safe-chain teardown
56
- ```
57
-
58
- This removes the aliases for **npm**, **npx**, and **yarn** from your shell startup files, restoring the original commands.
59
-
60
- ❗ After removing the shell integration, **the shell needs to restart in order to load the alias**.
52
+ More information about the shell integration can be found in the [shell integration documentation](docs/shell-integration.md).
61
53
 
62
54
  ## Uninstallation
63
55
 
@@ -71,4 +63,8 @@ To uninstall the Aikido Safe Chain, you can run the following command:
71
63
  ```shell
72
64
  npm uninstall -g @aikidosec/safe-chain
73
65
  ```
74
- 3. **Restart your terminal** to remove the aliases.
66
+ 3. **❗Restart your terminal** to remove the aliases.
67
+
68
+ # Usage in CI/CD
69
+
70
+ 🚧 Support for CI/CD environments is coming soon...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikidosec/safe-chain",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "scripts": {
5
5
  "test": "node --test --experimental-test-module-mocks **/*.spec.js",
6
6
  "test:watch": "node --test --watch --experimental-test-module-mocks **/*.spec.js",
@@ -6,6 +6,7 @@ import {
6
6
  readDatabaseFromLocalCache,
7
7
  writeDatabaseToLocalCache,
8
8
  } from "../config/configFile.js";
9
+ import { ui } from "../environment/userInteraction.js";
9
10
 
10
11
  export async function openMalwareDatabase() {
11
12
  const malwareDatabase = await getMalwareDatabase();
@@ -37,18 +38,27 @@ async function getMalwareDatabase() {
37
38
  const { malwareDatabase: cachedDatabase, version: cachedVersion } =
38
39
  readDatabaseFromLocalCache();
39
40
 
40
- if (cachedDatabase) {
41
- const currentVersion = await fetchMalwareDatabaseVersion();
41
+ try {
42
+ if (cachedDatabase) {
43
+ const currentVersion = await fetchMalwareDatabaseVersion();
44
+ if (cachedVersion === currentVersion) {
45
+ return cachedDatabase;
46
+ }
47
+ }
48
+
49
+ const { malwareDatabase, version } = await fetchMalwareDatabase();
50
+ writeDatabaseToLocalCache(malwareDatabase, version);
42
51
 
43
- if (cachedVersion === currentVersion) {
52
+ return malwareDatabase;
53
+ } catch (error) {
54
+ if (cachedDatabase) {
55
+ ui.writeWarning(
56
+ "Failed to fetch the latest malware database. Using cached version."
57
+ );
44
58
  return cachedDatabase;
45
59
  }
60
+ throw error;
46
61
  }
47
-
48
- const { malwareDatabase, version } = await fetchMalwareDatabase();
49
- writeDatabaseToLocalCache(malwareDatabase, version);
50
-
51
- return malwareDatabase;
52
62
  }
53
63
 
54
64
  function isMalwareStatus(status) {
Binary file