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

# bun audit

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

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

```bash terminal icon="terminal" theme={null}
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={null}
bun audit --audit-level=high
```

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

```bash terminal icon="terminal" theme={null}
bun audit --prod
```

**`--ignore <CVE>`** - 忽略特定的 CVE（重复该标志可忽略多个）：

```bash terminal icon="terminal" theme={null}
bun audit --ignore CVE-2022-25883 --ignore CVE-2023-26136
```

### `--json`

使用 `--json` 标志打印来自注册表的原始 JSON 响应，而不是格式化报告：

```bash terminal icon="terminal" theme={null}
bun audit --json
```

### 退出码

`bun audit` 在未发现漏洞时退出码为 `0`，如果报告列出任何漏洞则退出码为 `1`（包括传递 `--json` 时）。
