DataDog/supply-chain-firewall

GitHub: DataDog/supply-chain-firewall

一款阻止安装恶意 npm 和 PyPI 包的供应链防火墙命令行工具。

Stars: 264 | Forks: 19

# 供应链防火墙 ![测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/59cca9d06a071940.svg) ![代码质量](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/8a0f3daea7071941.svg)

Supply-Chain Firewall

Supply-Chain Firewall 是一个命令行工具,用于防止安装恶意的 npm 和 PyPI 包。它主要供工程师使用,以保护其开发工作站免受供应链攻击的危害。 ![scfw demo usage](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/ee9505493f071945.gif) 给定一个受支持的软件包管理器的命令,Supply-Chain Firewall 会收集该命令将要安装的所有软件包目标,并根据公开的开源恶意软件和漏洞数据源对其进行验证。如果任何验证器返回关键发现,该命令会自动被阻止运行,这通常表示目标软件包是恶意的。在验证器对某个目标报告警告的情况下,这些警告会连同继续安装操作的确认提示一起展示给用户。 Supply-Chain Firewall 包含以下默认数据源的验证器: - Datadog Security Research 的公开 [恶意软件包数据集](https://github.com/DataDog/malicious-software-packages-dataset) - [OSV.dev](https://osv.dev) 公告,包括恶意软件包和漏洞 - 软件包注册表元数据,当软件包创建时间非常接近时发出警告 - 用户提供的特定软件包的自定义发现列表 有关每个默认验证器及其支持的配置选项的文档可以在[此处](https://github.com/DataDog/supply-chain-firewall/tree/main/docs/verifiers.md)找到。 用户也可以为替代数据源实现自己的自定义验证器。实现自定义验证器的模板可以在 `examples/verifier.py` 中找到。更多细节也可以在 API 文档中找到。 Supply-Chain Firewall 的主要目标是阻止在其数据源范围内 100% 的已知恶意软件包安装。 ### 查看新的 Datadog 代理 [集成](https://docs.datadoghq.com/integrations/supply-chain-firewall/) 和云安全 SIEM [内容包](https://app.datadoghq.com/security/siem/content-packs?query=%22Supply-Chain%20Firewall%22)。 ## 入门 ### 安装 安装 Supply-Chain Firewall 的推荐方式是通过 [`pipx`](https://pipx.pypa.io/): ``` $ pipx install scfw ``` 这会将 `scfw` 命令行程序安装到系统中的隔离 Python 环境,并将其提供给其他 Python 环境(包括通过 `venv` 或 `virtualenv` 创建的临时环境)。安装后请务必运行 `pipx ensurepath` 以正确配置 `PATH`。 也可以直接通过 `pip install scfw` 将 Supply-Chain Firewall 安装到当前活动的 Python 环境中。 要检查安装是否成功,请运行以下命令并确认看到类似以下的输出。 ``` $ scfw --version 2.6.1 ``` ### 安装后步骤 为了充分发挥 Supply-Chain Firewall 的作用,建议在安装后运行 `scfw configure` 命令。该脚本会引导你配置环境,使受支持软件包管理器的所有命令都通过 `scfw` 被动运行,同时启用 Datadog 日志记录(详见下文)。 ``` $ scfw configure ... ``` 请参阅 `configure` 命令[文档](https://github.com/DataDog/supply-chain-firewall/tree/main/docs/subcommands.md#scfw-configure)了解详细信息和命令行选项。 ### 兼容性与限制 | 软件包管理器 | 支持的版本 | 检查的子命令 | | :---: | :---: | :---: | | npm | >= 7.0 | `install`(包括别名) | | pip | >= 22.2 | `install` | | poetry | >= 1.7 | `add`、`install`、`sync`、`update` | Supply-Chain Firewall 可能仅知道如何检查受支持软件包管理器的部分“安装类”子命令。表中列出了这些子命令。其他子命令始终允许运行。 默认情况下,`scfw` 会拒绝运行受支持软件包管理器的不受支持版本的检查子命令。这与其阻止 100% 已知恶意软件包安装的目标一致。为了充分利用 `scfw`,请确认你正在运行受支持的软件包管理器版本,并在使用该工具前进行相应升级。 目前,Supply-Chain Firewall 仅在 macOS 系统上得到完全支持,尽管它应该也能在常见的 Linux 发行版上按预期运行。目前不支持 Windows 系统。 ### 卸载 Supply-Chain Firewall 可以通过 `pip(x) uninstall scfw` 卸载 Supply-Chain Firewall。在执行此操作之前,请务必运行 `scfw configure --remove` 以删除可能已添加到环境中的任何 Supply-Chain Firewall 管理的配置。 ``` $ scfw configure --remove ... ``` ## 使用 ``` $ scfw --help usage: scfw [-h] [-v] [--log-level LEVEL] {audit,configure,run} ... A tool for preventing the installation of malicious npm and PyPI packages. positional arguments: {audit,configure,run} options: -h, --help show this help message and exit -v, --version show program's version number and exit --log-level LEVEL Desired logging level (default: WARNING, options: DEBUG, INFO, WARNING, ERROR) ``` ### 检查软件包管理器命令 要使用 Supply-Chain Firewall 检查软件包管理器命令,只需在要运行的命令前添加 `scfw run`: ``` $ scfw run npm install react added 1 package in 226ms $ scfw run pip install -r requirements.txt Package urllib3-2.6.2: - An OSV.dev advisory exists for package urllib3-2.6.2: * [High] https://osv.dev/vulnerability/GHSA-38jv-5279-wg99 [?] Proceed with installation? (y/N): The installation request was aborted. No changes have been made. ``` 请参阅 `run` 命令[文档](https://github.com/DataDog/supply-chain-firewall/tree/main/docs/subcommands.md#scfw-run)了解详细信息和命令行选项。 ### 审计已安装的软件包 Supply-Chain Firewall 也可以使用其验证器来审计已安装的软件包: ``` $ scfw audit npm No issues found. $ scfw audit --executable venv/bin/python pip Package pip-23.0.1: - An OSV.dev advisory exists for package pip-23.0.1: * [Medium] https://osv.dev/vulnerability/GHSA-mq26-g339-26xf - An OSV.dev advisory exists for package pip-23.0.1: * [Low] https://osv.dev/vulnerability/PYSEC-2023-228 Package setuptools-65.5.0: - An OSV.dev advisory exists for package setuptools-65.5.0: * [High] https://osv.dev/vulnerability/GHSA-cx63-2mw6-8hw5 - An OSV.dev advisory exists for package setuptools-65.5.0: * [High] https://osv.dev/vulnerability/GHSA-5rjg-fvgr-3xxf - An OSV.dev advisory exists for package setuptools-65.5.0: * [High] https://osv.dev/vulnerability/GHSA-r9hx-vwmv-q579 - An OSV.dev advisory exists for package setuptools-65.5.0: * https://osv.dev/vulnerability/PYSEC-2022-43012 ``` 请参阅 `audit` 命令[文档](https://github.com/DataDog/supply-chain-firewall/tree/main/docs/subcommands.md#scfw-audit)了解详细信息和命令行选项。 ## Datadog 日志管理集成 Supply-Chain Firewall 可以选择将阻止和成功安装的日志发送到 Datadog。 ![scfw datadog log](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/c95ad3d43c071948.png) 日志可以通过 HTTP API(需要 API 密钥)或本地 Datadog 代理进程转发到 Datadog。有关如何启用和配置这些日志记录器的文档可以在[此处](https://github.com/DataDog/supply-chain-firewall/blob/main/docs/loggers.md)找到。 Supply-Chain Firewall 可以维护一个本地 JSON Lines 日志文件,记录所有已完成的 `run` 和 `audit` 执行。强烈建议[启用](https://github.com/DataDog/supply-chain-firewall/blob/main/docs/loggers.md#local-file-logger)此日志记录器,因为拥有已执行软件包管理器命令、其结果和随时间推移的安装软件包的中心化记录在事件响应场景中非常有用。启用文件日志后,用户可以单独[配置](https://docs.datadoghq.com/agent/logs/?tab=tailfiles#custom-log-collection)本地 Datadog 代理以跟踪此文件并从而无需额外开销即可摄取 SCFW 日志。 Supply-Chain Firewall 还可以集成用户提供的日志记录器。实现自定义日志记录器的模板可以在 `examples/logger.py` 中找到。详细信息请参考 API 文档。 ## 开发 我们欢迎社区对 Supply-Chain Firewall 进行贡献。有关构建 API 文档和设置开发环境的说明,请参考[贡献指南](https://github.com/DataDog/supply-chain-firewall/blob/main/CONTRIBUTING.md)。 ## 维护者 - [Ian Kretz](https://github.com/ikretz) - [Tesnim Hamdouni](https://github.com/tesnim5hamdouni) - [Sebastian Obregoso](https://www.linkedin.com/in/sebastianobregoso/)
标签:Datadog, DevSecOps, npm, OSV, PyPI, Vercel, 上游代理, 供应链攻击防护, 包管理, 安装防护, 开发工作站防护, 恶意包检测, 恶意软件, 数据来源, 软件供应链, 逆向工具