Skip to content

Protect against malicious code installed via npm, yarn, pnpm, npx, and pnpx with Aikido Safe Chain. Free to use, no tokens required.

License

Notifications You must be signed in to change notification settings

galargh/safe-chain

Β 
Β 

Repository files navigation

Aikido Safe Chain

Aikido Safe Chain

NPM Version NPM Downloads

  • βœ… Block malware on developer laptops and CI/CD
  • βœ… Supports npm and PyPI more package managers coming
  • βœ… Blocks packages newer than 24 hours without breaking your build
  • βœ… Tokenless, free, no build data shared

Aikido Safe Chain supports the following package managers:

  • πŸ“¦ npm
  • πŸ“¦ npx
  • πŸ“¦ yarn
  • πŸ“¦ pnpm
  • πŸ“¦ pnpx
  • πŸ“¦ bun
  • πŸ“¦ bunx
  • πŸ“¦ pip (beta)
  • πŸ“¦ pip3 (beta)
  • πŸ“¦ uv (beta)
  • πŸ“¦ poetry (beta)

Usage

Installation

Installing the Aikido Safe Chain is easy with our one-line installer.

⚠️ Already installed via npm? See the migration guide to switch to the binary version.

Unix/Linux/macOS

Default installation (JavaScript packages only):

curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh

Include Python support (pip/pip3/uv):

curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --include-python

Windows (PowerShell)

Default installation (JavaScript packages only):

iex (iwr "https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1" -UseBasicParsing)

Include Python support (pip/pip3/uv):

iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -includepython"

Verify the installation

  1. ❗Restart your terminal to start using the Aikido Safe Chain.

    • This step is crucial as it ensures that the shell aliases for npm, npx, yarn, pnpm, pnpx, bun, bunx, and pip/pip3 are loaded correctly. If you do not restart your terminal, the aliases will not be available.
  2. Verify the installation by running one of the following commands:

    For JavaScript/Node.js:

    npm install safe-chain-test

    For Python (if you enabled Python support):

    pip3 install safe-chain-pi-test
    • The output should show that Aikido Safe Chain is blocking the installation of these test packages as they are flagged as malware.

When running npm, npx, yarn, pnpm, pnpx, bun, bunx, uv, pip, pip3 or poetry 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.

You can check the installed version by running:

safe-chain --version

How it works

Malware Blocking

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, uv, pip, pip3 or poetry commands, all package downloads are routed through this local proxy, which verifies packages in real-time against Aikido Intel - Open Sources Threat Intelligence. If malware is detected in any package (including deep dependencies), the proxy blocks the download before the malicious code reaches your machine.

Minimum package age (npm only)

For npm packages, Safe Chain temporarily suppresses packages published within the last 24 hours (by default) until they have been validated against malware. 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 section below.

⚠️ This feature only applies to npm-based package managers (npm, npx, yarn, pnpm, pnpx, bun, bunx) and does not apply to Python package managers (uv, pip, pip3, poetry).

Shell Integration

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 (uv, pip). 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:

  • βœ… Bash
  • βœ… Zsh
  • βœ… Fish
  • βœ… PowerShell
  • βœ… PowerShell Core

More information about the shell integration can be found in the shell integration documentation.

Uninstallation

To uninstall the Aikido Safe Chain, you can run the following command:

  1. Remove all aliases from your shell by running:
    safe-chain teardown
  2. Uninstall the Aikido Safe Chain package using npm:
    npm uninstall -g @aikidosec/safe-chain
  3. ❗Restart your terminal to remove the aliases.

Configuration

Logging

You can control the output from Aikido Safe Chain using the --safe-chain-logging flag:

  • --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.

    Example usage:

    npm install express --safe-chain-logging=silent
  • --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.

    Example usage:

    npm install express --safe-chain-logging=verbose

Minimum Package Age

You can configure how long packages must exist before Safe Chain allows their installation. By default, packages must be at least 24 hours old before they can be installed through npm-based package managers.

Configuration Options

You can set the minimum package age through multiple sources (in order of priority):

  1. CLI Argument (highest priority):

    npm install express --safe-chain-minimum-package-age-hours=48
  2. Environment Variable:

    export SAFE_CHAIN_MINIMUM_PACKAGE_AGE_HOURS=48
    npm install express
  3. Config File (~/.aikido/config.json):

    {
      "minimumPackageAgeHours": 48
    }

Usage in CI/CD

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.

Installation for CI/CD

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.

Unix/Linux/macOS (GitHub Actions, Azure Pipelines, etc.)

JavaScript only:

curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci

With Python support:

curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci --include-python

Windows (Azure Pipelines, etc.)

JavaScript only:

iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -ci"

With Python support:

iex "& { $(iwr 'https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.ps1' -UseBasicParsing) } -ci -includepython"

Supported Platforms

  • βœ… GitHub Actions
  • βœ… Azure Pipelines

GitHub Actions Example

- name: Setup Node.js
  uses: actions/setup-node@v4
  with:
    node-version: "22"
    cache: "npm"

- name: Install safe-chain
  run: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci --include-python

- name: Install dependencies
  run: npm ci

Note: Remove --include-python if you don't need Python (pip/pip3/uv/poetry) support.

Azure DevOps Example

- task: NodeTool@0
  inputs:
    versionSpec: "22.x"
  displayName: "Install Node.js"

- script: curl -fsSL https://raw.githubusercontent.com/AikidoSec/safe-chain/main/install-scripts/install-safe-chain.sh | sh -s -- --ci --include-python
  displayName: "Install safe-chain"

- script: npm ci
  displayName: "Install dependencies"

Note: Remove --include-python if you don't need Python (pip/pip3/uv/poetry) support.

After setup, all subsequent package manager commands in your CI pipeline will automatically be protected by Aikido Safe Chain's malware detection.

About

Protect against malicious code installed via npm, yarn, pnpm, npx, and pnpx with Aikido Safe Chain. Free to use, no tokens required.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 94.2%
  • Shell 2.9%
  • PowerShell 2.3%
  • Other 0.6%