> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bun audit

> 检查已安装的包是否存在已知的安全漏洞

在包含 `bun.lock` 文件的项目中运行命令：

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun audit
```

Bun 会将已安装包及其版本列表发送到 NPM，并打印发现的任何漏洞报告。从默认注册表以外的注册表安装的包将被跳过。

如果未发现漏洞，命令会打印：

```
No vulnerabilities found
```

当检测到漏洞时，每个受影响的包会列出其严重程度、简要描述及安全通告链接。在报告结尾，Bun 会打印总结和更新提示：

```
3 vulnerabilities (1 high, 2 moderate)
To update all dependencies to the latest compatible versions:
  bun update
To update all dependencies to the latest versions (including breaking changes):
  bun update --latest
```

### 过滤选项

**`--audit-level=<low|moderate|high|critical>`** - 只显示该严重等级及以上的漏洞：

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun audit --audit-level=high
```

**`--prod`** - 只审计生产依赖（排除 devDependencies）：

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun audit --prod
```

**`--ignore <CVE>`** - 忽略指定的 CVE（可多次使用）：

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun audit --ignore CVE-2022-25883 --ignore CVE-2023-26136
```

### `--json`

使用 `--json` 参数打印来自注册表的原始 JSON 响应，而非格式化报告：

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun audit --json
```

### 退出码

如果未发现漏洞，`bun audit` 会以代码 `0` 退出；如果报告中存在任何漏洞，则以代码 `1` 退出。即使使用了 `--json` 参数，此行为依然有效。
