DataDog/supply-chain-firewall
À propos
Supply Chain Firewall (SCFW) is a tool for preventing the installation of malicious npm and PyPI packages :fire:
Sécurité et confidentialitéProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalSupply Chain Firewall
[!NOTE] The Python version of SCFW is deprecated and is maintained only for security updates. It remains available on the
v3branch.
Supply Chain Firewall (SCFW) is a command-line tool for preventing the installation of malicious npm and PyPI packages. It is intended primarily for use by engineers to protect their development workstations from compromise in a supply-chain attack.
Given a command for a supported package manager, Supply Chain Firewall collects all package targets that would be installed by the command and evaluates them against known-malicious and compromised open source packages.
Interested in SCFW for your business use-case? Enroll as a design partner.
Operation modes
Local
In local mode, SCFW identifies malicious packages using the open-source malicious-software-packages-dataset and OSV.dev API. Local mode is useful for experimenting, single-developer mode.
Datadog Code Security
SCFW can use Datadog Code Security as a backend, allowing you to define custom ALLOW or BLOCK policies that apply to all of your SCFW deployment from Datadog. The outcomes of completed runs of the scfw CLI are also reported into Code Security, providing valuable observability into how package managers and third-party code are used across your fleet. Datadog only sees package metadata (ecosystem, name, version, artifact source) and the commands being run: no package source code is ever reported to Datadog by Supply Chain Firewall.
Features:
- Datadog Security Research's threat intelligence feed, in addition to public ones.
- Centralized policy management allowing to manage in which situations to allow or block a package installation across a fleet of developer endpoints.
- Centralized logging, so you can be alerted when a developer attempts to install a malicious package that gets blocked.
Getting started
Installation
Supply Chain Firewall is distributed as a single Go binary with no runtime dependencies.
Github release
Download the binary for your operating system and architecture from the latest GitHub release. Before running these commands, replace the value of scfw_expected_checksum with the SHA-256 checksum published for that binary on the release page:
# Replace this placeholder with the checksum from the release page.
$ scfw_expected_checksum="<expected-sha256-checksum>"
# Detect the operating system used in the release artifact name.
$ case "$(uname -s)" in
Darwin) scfw_os=darwin ;;
Linux) scfw_os=linux ;;
*) echo "Unsupported operating system: $(uname -s)" >&2; exit 1 ;;
esac
# Detect the CPU architecture used in the release artifact name.
$ case "$(uname -m)" in
x86_64) scfw_arch=amd64 ;;
arm64|aarch64) scfw_arch=arm64 ;;
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac
# Download the binary for the detected platform.
$ scfw_binary="scfw-${scfw_os}-${scfw_arch}"
$ curl -fLO "https://github.com/DataDog/supply-chain-firewall/releases/latest/download/${scfw_binary}"
# Calculate the downloaded binary's checksum.
$ scfw_actual_checksum=$(sha256sum "${scfw_binary}" | awk '{print $1}')
# Stop if the downloaded binary does not match the published checksum.
$ if [ "${scfw_actual_checksum}" != "${scfw_expected_checksum}" ]; then
echo "Checksum verification failed" >&2
exit 1
fi
# Install the verified binary in a directory on PATH.
$ chmod +x "${scfw_binary}"
$ sudo install "${scfw_binary}" /usr/local/bin/scfw
Through go install
If Go 1.26 or later is installed, install SCFW with go install:
$ go install github.com/DataDog/supply-chain-firewall/scfw@latest
This installs the scfw binary to $(go env GOPATH)/bin; be sure that directory is on your PATH.
To check whether the installation succeeded, run the following command and verify that you see output similar to the following.
$ scfw --help
Supply Chain Firewall, a tool for preventing the installation of malicious software packages.
Usage:
scfw [command]
Available Commands:
configure Configure the environment for using Supply Chain Firewall.
run Run a package manager command through Supply Chain Firewall.
...
Post-installation steps
To get the most out of Supply Chain Firewall, run the scfw configure command after installation to configure the environment. Via this command, users can also ensure that all commands for supported package managers are passively run through scfw.
# --dd-* parameters are optional
$ scfw configure \
--alias-npm \
--alias-pip \
--alias-poetry \
--dd-api-key=<your-api-key> \
--dd-app-key=<your-app-key> \
--dd-site=<your-dd-site>
When passing these values via shell variables, e.g. in scripts, prefer this = form: --dd-api-key=$DD_API_KEY --dd-app-key=$DD_APP_KEY --dd-site=$DD_SITE.
This does two things:
- Adds shell aliases to your
.bashrc,.bash_profile,.zshrc, and.zprofile(whichever already exist) so thatnpm/npx,pip/pip3,poetry,uv/uvx,yarn, and/orpnpmtransparently run throughscfw. Restart your shell (or source the relevant rc file) for the aliases to take effect. - Optionally, if provided, stores your Datadog API key and application key securely in your system's keychain, so credentials don't need to be kept in plaintext or supplied on every command.
scfw configure is idempotent and may be re-run at any time to change your configuration. Alias options are additive, so aliases configured by an earlier invocation remain in place unless their corresponding --remove-alias-* option is passed. The command manages its own clearly indicated block of your shell rc files and never touches anything else you've added.
Available configure options:
| Flag | Description |
|---|---|
--alias-npm |
Add shell aliases to run npm and npx commands through scfw. |
--remove-alias-npm |
Remove the npm and npx shell aliases managed by scfw. |
--alias-pip |
Add shell aliases to run all pip/pip3 commands through scfw. |
--remove-alias-pip |
Remove the pip/pip3 shell aliases managed by scfw. |
--alias-uv |
Add shell aliases to run uv and uvx commands through scfw. Requires proxy mode for package operations. |
--remove-alias-uv |
Remove the uv and uvx shell aliases managed by scfw. |
--alias-yarn |
Add a shell alias to run yarn commands through scfw. Requires proxy mode for package operations. |
--remove-alias-yarn |
Remove the yarn shell alias managed by scfw. |
--alias-pnpm |
Add shell aliases to run pnpm, pnpx, pn, and pnx commands through scfw. Requires proxy mode for package operations. |
--remove-alias-pnpm |
Remove the pnpm, pnpx, pn, and pnx shell aliases managed by scfw. |
--alias-bun |
Add shell aliases to run bun and bunx commands through scfw. Requires proxy mode. |
--remove-alias-bun |
Remove the bun and bunx shell aliases managed by scfw. |
--alias-poetry |
Add a shell alias to run all poetry commands through scfw. |
--remove-alias-poetry |
Remove the poetry shell alias managed by scfw. |
--scfw-home |
Directory Supply Chain Firewall can use as a local cache. |
--remove |
Remove all Supply Chain Firewall managed configuration. |
--dd-api-key |
Datadog API key used for policy evaluation and reporting. |
--dd-app-key |
Datadog application key used for policy evaluation and reporting. |
--dd-site |
Datadog site parameter used for policy evaluation and reporting (default: datadoghq.com). |
When inspecting package manager commands, Datadog credentials and the Datadog site parameter may alternatively be provided via environment variables DD_API_KEY, DD_APP_KEY, and DD_SITE, respectively. This is particularly useful in CI environments where secrets are injected per job. Environment variables always take precedence over stored credentials sourced from the system keychain.
Compatibility and limitations
| Package manager | Supported versions | Inspected subcommands |
|---|---|---|
| npm | >= 7.0 | install (including aliases); in proxy mode every command except scripts |
| npx (proxy mode) | >= 7.0 | every invocation |
| pip | >= 22.2 | install |
| poetry | >= 2.0 | add, install, sync, update |
| uv (proxy mode) | 0.13.4 tested | pip install, pip sync, pip compile, add, remove, sync, lock, export, tree, build, tool install, tool upgrade, tool run/uvx, version updates, venv --seed |
| yarn (proxy mode) | 1.22+, 4.x | bare yarn, install, add, upgrade/up, upgrade-interactive, create, global add, dlx, workspaces focus |
| pnpm (proxy mode) | 10.x, 11.x, 12.x | install, add, update, remove, dedupe, fetch, import, deploy, dlx/pnpx, create, -r/--filter workspace installs |
| bun (proxy mode) | 1.2+ (1.x) | all commands, including bunx/bun x, create, and auto-install during bun run/bun <file> |
With SCFW_PROXY_ENABLED=1, npm Git dependencies are evaluated whether npm fetches them over HTTPS, SSH, or a local path: SCFW reads the name and version from the checked-out package.json before npm uses the checkout or runs its prepare script, and reports the repository URL and commit as the source. Git HTTPS traffic uses a separate temporary proxy and CA that honor the user's Git proxy settings. A dependency selected from a repository subdirectory (#path:) is evaluated by the repository's root package.json. Git dependencies of Yarn, pnpm, and the Python package managers are not evaluated.
Enable npm interception with SCFW_PROXY_ENABLED=1, then use scfw run -- npm install react or configure --alias-npm, which also covers npx. In proxy mode every npm command is proxied except npm run, npm test, npm start, npm stop and npm restart, which execute directly without SCFW proxy setup. Package commands that a script runs itself are not evaluated, so run those through scfw run -- or the shell aliases. Unusual options before the command, such as --prefix web run build, keep a script proxied. npx and npm exec always run through the SCFW proxy, because they may download the package they run; the executed tool's own network traffic passes through the proxy as well. Without proxy mode only npm install is inspected, and npm ci, npm update, npm exec and the other package-fetching commands refuse to run.
Enable uv interception with SCFW_PROXY_ENABLED=1, then use scfw run -- uv pip install requests or configure --alias-uv. Unrelated uv commands pass through unchanged. Proxy mode evaluates distributions requested over HTTP(S); packages already available in uv's cache, local paths, and Git source contents are not evaluated. Git HTTPS traffic still traverses the proxy and trusts its invocation CA.
uv run always executes directly without SCFW proxy setup, including scripts and --with dependencies. Its arguments, environment, and standard input pass through unchanged; SCFW does not evaluate its package downloads or intercept its application traffic.
Enable Yarn interception with SCFW_PROXY_ENABLED=1, then use scfw run -- yarn add react or configure --alias-yarn. Yarn Classic 1.22+ and Yarn 4 are supported, including a global Yarn that hands off to a project's yarnPath release; Yarn 2 and 3 are rejected. Other Yarn commands, such as yarn run and package scripts, execute directly without SCFW proxy setup. SCFW preserves existing upstream proxies, registries, credentials, and CA settings and never writes .yarnrc, .yarnrc.yml, or .npmrc files. Yarn 4 networkSettings entries that set a per-host proxy, CA, or client certificate, and Yarn 4 client certificates, are rejected before Yarn starts, because they would bypass or break process-only routing; configure a top-level httpsProxy/httpsCaFilePath or YARN_HTTPS_PROXY instead. Packages already in Yarn's cache, Git dependencies Yarn clones, and corepack's own Yarn download are not evaluated.
Yarn archive dependencies are evaluated from the package.json inside the downloaded archive before Yarn uses them: direct .tgz/.tar.gz URL dependencies and lockfile resolved URLs, github: dependencies (Yarn 4 downloads github.com/<owner>/<repo>/archive/<commit>.tar.gz, Yarn Classic the codeload tarball), and the redirect targets of those downloads, with the downloaded URL reported as the source.
Enable pnpm interception with SCFW_PROXY_ENABLED=1, then use scfw run -- pnpm add react or configure --alias-pnpm, which also covers pnpx, pn, and pnx. pnpm 10, 11, and 12 are supported; SCFW follows a project's packageManager pin to the version pnpm will switch to and rejects other versions. pnpm run, exec, test, package scripts, and other commands that do not fetch packages execute directly without SCFW proxy setup, including the dependency install pnpm 11 and 12 perform before a script when node_modules is missing. SCFW preserves existing upstream proxies, registries, credentials, and CA settings and never writes .npmrc, pnpm-workspace.yaml, config.yaml, or .pnpmfile.cjs files. Client certificates, local-address, and pnprServer settings are rejected before pnpm starts, because they cannot be routed through the proxy. On pnpm 10, an updateConfig hook in a project's .pnpmfile.cjs can override SCFW's proxy settings. Packages already in pnpm's store or metadata cache, Git dependencies, network requests made by lifecycle scripts, and corepack's own pnpm download are not evaluated.
Enable Bun interception with SCFW_PROXY_ENABLED=1, then use scfw run -- bun add react or configure --alias-bun, which also covers bunx. Bun 1.2 and later 1.x releases are supported. Every Bun command runs through the proxy, because any of them can download packages, so HTTPS requests made by scripts also pass through SCFW, which evaluates only package tarballs and forwards everything else. SCFW points Bun at itself with the proxy environment variables and NODE_EXTRA_CA_CERTS, and adds --cafile after the subcommand of package commands such as install, add, and update, and, from Bun 1.4, of bunx and bun x; it never writes bunfig.toml, .npmrc, or lockfiles. Upstream proxies come from HTTPS_PROXY/HTTP_PROXY/NO_PROXY, as for Bun itself, and registries and CA settings from the environment, bunfig.toml, and .npmrc. Packages already in Bun's cache or bunx's temporary-directory cache, Git dependencies, and github: tarballs are not evaluated. Tools spawned by scripts that do not read NODE_EXTRA_CA_CERTS or GIT_SSL_CAINFO, and requests that pin certificates or use client certificates, may fail TLS verification. On Bun 1.4, a ca or cafile in the global ~/.bunfig.toml or the user-level .npmrc replaces SCFW's CA for bunx, bun x, and bun create; project-level settings do not. SCFW passes its CA to bunx and bun x with --cafile, but bun create takes no --cafile, so SCFW refuses bun create on Bun 1.4 before Bun starts whenever any bunfig.toml (global, project, or --config) or .npmrc configures ca or cafile, which is stricter than needed for project-level settings.
Opaque archive inspection follows each manager's format selection: uv uses the original or registry-advertised source extension; pip uses its installed version's filename, MIME, and signature rules. Pip inspection retains raw download bytes, while uv inspection decodes HTTP content encodings. Uncertain or unsupported package archive interpretations, including conflicting redirect names, are rejected.
The uv adapter preserves existing HTTP/HTTPS upstream proxies, index authentication, and custom TLS settings. Overrides apply only to the child process. If uv.toml configures a proxy, SCFW uses a temporary merged configuration that is removed with the invocation CA. Existing configuration files are untouched; uv itself continues managing its cache, virtual environments, and project files.
Proxied script operations such as uv lock --script retain inline PEP 723 index and trust settings. Scripts declaring inline http-proxy or https-proxy settings are rejected before uv starts, because those settings override process-only routing; configure upstream proxies in the environment or uv.toml instead. For these proxied script operations, remote scripts, stdin scripts, and scripts larger than 16 MiB are unsupported. CGI proxy environments and pip's legacy --isolated configuration-discovery behavior are outside the supported scope.
For upstream TLS, SCFW uses Go's system trust store by default. Explicit custom CA sources (--cert, SSL_CERT_FILE, SSL_CERT_DIR) replace defaults, even when a configured file/directory is missing or empty; empty environment-variable values are ignored. Native-TLS flags and settings are passed to uv unchanged. SCFW does not replicate uv's bundled root store. String and structured allow-insecure-host entries retain their host, scheme, and port scope. Git receives a separate temporary proxy and CA so its certificate settings do not widen uv registry trust.
Supply Chain Firewall may only know how to inspect some of the "installish" subcommands for its supported package managers. These are shown in the above table. Any other subcommands are always allowed to run.
Note that scfw will refuse to run inspected subcommands on an unsupported version of a supported package manager. In order to get the most out of scfw, please verify that you are running a supported version of your package manager and upgrade accordingly before using this tool.
Uninstalling Supply Chain Firewall
Before uninstalling, be sure to run scfw configure --remove to remove any Supply Chain Firewall-managed configuration you may have previously added to your environment.
$ scfw configure --remove
Then remove the scfw binary, e.g. by deleting it from $(go env GOPATH)/bin if it was installed via go install.
Usage
To inspect a package manager command with Supply Chain Firewall, prepend scfw run -- to the command you intend to run:
$ scfw run -- npm install react
added 1 package in 226ms
$ scfw run -- pip install some-evil-package
Package some-evil-package-1.0.0:
- Datadog Security Research has determined that package some-evil-package-1.0.0 is malicious.
The command was blocked. No changes have been made.
Note that, once shell aliases have been configured via scfw configure --alias-npm/--alias-pip/--alias-poetry/--alias-uv/--alias-yarn/--alias-pnpm, the explicit scfw run -- prefix is no longer needed: commands for these package managers run through scfw automatically.
Set SCFW_PROXY_ENABLED=1 to evaluate pip and Poetry packages as they are downloaded through an invocation-scoped proxy. For example, SCFW_PROXY_ENABLED=1 scfw run -- poetry install inspects downloads made by Poetry, including during add, update, and lock. Existing HTTP/HTTPS proxy URLs, native macOS proxy settings, and configured TLS trust are preserved for outbound connections.
scfw run supports the following options:
| Flag | Description |
|---|---|
--executable |
Package manager executable to use for running commands (default: environmentally determined). |
--error-on-block |
Treat blocked commands as errors, i.e. exit non-zero (useful for scripting and CI). |
--allow-on-warning |
Non-interactively allow commands with only warning-level findings, instead of prompting. |
--block-on-warning |
Non-interactively block commands with only warning-level findings, instead of prompting. |
The SCFW_ON_WARNING environment variable (allow or block) has the same effect as --allow-on-warning/--block-on-warning and takes precedence over them when set, which is useful for enforcing a consistent policy across a CI environment without changing every invocation. In a non-interactive context (no attached terminal), a warning-level result is blocked by default unless one of these mechanisms is used, so a warning can never be silently ignored.
Development
We welcome contributions to Supply Chain Firewall. Refer to the CONTRIBUTING guide for instructions on setting up for development.
Authors
Maintainers
Explorer des projets similaires
Chargement…