bhargavmahanta/envGuard
GitHub: bhargavmahanta/envGuard
EnvGuard 是一款用于扫描环境变量、Docker 及 CI/CD 配置中安全风险与卫生问题的 linting 工具。
Stars: 3 | Forks: 0
# EnvGuard
[](https://www.npmjs.com/package/@bhargavmahanta/envguard)
[](https://github.com/bhargavmahanta/envGuard/actions/workflows/test.yml)


EnvGuard 帮助开发者在不安全的环境变量值、高风险的运行时默认设置、Docker/Compose 风险以及 CI/CD 配置问题进入生产环境之前将其捕获。它是 Gitleaks 和 TruffleHog 等深度密钥历史扫描工具的补充,而不是替代品。
## 快速开始
无需全局安装即可运行 CLI:
```
npx @bhargavmahanta/envguard scan .
```
在 TypeScript 或 JavaScript 中使用 SDK:
```
import { scan } from "@bhargavmahanta/envguard";
const result = await scan({ target: ".", failOn: "high" });
console.log(result.passed, result.findings);
```
在构建系统和代码代理中使用确定性输出:
```
envguard scan . --agent
```
## 功能
- 扫描 `.env`、配置、Docker、Compose 和 GitHub Actions 文件
- 扫描 GitLab CI 和 CircleCI 配置
- 检查 `.env` 卫生状况以及 `.env.example` / `.env.schema` 漂移
- 检测高度相似的密钥、弱密钥、不安全的运行时设置以及通配符 CORS
- 检测 Docker 和 CI/CD 安全问题
- 默认在终端、JSON、Markdown、SARIF 和 GitHub annotation 报告中对密钥进行掩码处理
- 支持本地 CLI 使用、pre-commit 钩子和 GitHub Actions
- 仅扫描暂存或已更改的文件,以实现高效的开发者工作流
- 使用内置的可重用 GitHub Action 包装器
- 通过 `envguard.config.yml` 和 `.envguardignore` 配置行为
## 安装
```
npx @bhargavmahanta/envguard scan .
```
或者全局安装:
```
npm install -g @bhargavmahanta/envguard
```
作为项目依赖安装以供 SDK 或构建脚本使用:
```
npm install --save-dev @bhargavmahanta/envguard
```
## CLI 命令
```
envguard scan .
envguard scan . --ci --fail-on high
envguard scan . --format json --output report.json
envguard scan . --format markdown --output report.md
envguard scan --staged
envguard scan --changed origin/main
envguard scan . --format github
envguard baseline audit
envguard init
envguard rules
envguard doctor --json
envguard scan . --agent
```
在 Windows PowerShell 中,如果脚本执行阻止了生成的 `envguard.ps1` shim,请使用 `.cmd` shim:
```
envguard.cmd scan .
npx --package @bhargavmahanta/envguard envguard.cmd scan .
```
## 示例输出
```
[HIGH] Database URL contains a password (database-url-password)
File: .env:3
Preview: DATABASE_URL=postgres://admin:********@localhost:5432/app
Risk: 100/100 | Confidence: high
Fix: Move database credentials to a secret manager or untracked local env file.
```
## 支持的检测项
- AWS 密钥、GitHub token、Stripe 密钥、Slack token、Google API 密钥
- 私钥、JWT token、bearer token、带密码的数据库 URL
- 弱 JWT/session/API 密钥和占位符值
- `DEBUG=true`、开发运行时、禁用 SSL/TLS 验证
- 通配符 CORS 以及带有凭据的通配符 CORS
- `.env` 重复键、空值、格式错误的行、无效键以及 schema 漂移
- 复制 `.env`、使用 `latest`、以 root 身份运行、缺少 `.dockerignore` 或使用远程 `ADD` 的 Dockerfile
- Compose 特权容器、开放数据库端口、host networking、不安全的卷、内联密钥以及 `latest` 标签
- GitHub Actions 密钥打印、`pull_request_target`、浮动 actions、过宽的权限
- GitLab CI 和 CircleCI 密钥打印以及风险默认设置
## 配置
创建初始文件:
```
envguard init
```
`envguard.config.yml` 示例:
```
severity:
fail_on: high
entropy:
enabled: true
threshold: 4.2
output:
mask: true
rules:
disabled: []
packs:
- node
- python
- docker
- github-actions
- ci
custom: []
allow: []
scan:
max_file_mb: 2
timeout_seconds: 0
include_gitignored: false
```
`.envguardignore` 示例:
```
node_modules/
dist/
docs/fixtures/
```
## 报告
EnvGuard 支持:
```
terminal
json
markdown
sarif
github
```
## 示例漏洞项目
尝试对内置的模拟漏洞项目运行 EnvGuard:
```
npm install
npm run build
node dist/cli.js scan examples/vulnerable-project
```
## 局限性
EnvGuard 使用基于模式和启发式的检测。它可能会产生误报或漏掉某些密钥。它不会验证、传输或使用检测到的凭据。
## 文档
- [规则目录](https://github.com/bhargavmahanta/envGuard/blob/main/docs/rules.md)
- [EnvGuard 对比](https://github.com/bhargavmahanta/envGuard/blob/main/docs/comparison.md)
- [修复指南](https://github.com/bhargavmahanta/envGuard/blob/main/docs/remediation.md)
- [GitHub Actions 设置](https://github.com/bhargavmahanta/envGuard/blob/main/docs/ci.md)
- [Pre-commit 设置](https://github.com/bhargavmahanta/envGuard/blob/main/docs/pre-commit.md)
- [集成示例](https://github.com/bhargavmahanta/envGuard/blob/main/docs/examples.md)
- [报告](https://github.com/bhargavmahanta/envGuard/blob/main/docs/reporting.md)
- [公共 API 表面](https://github.com/bhargavmahanta/envGuard/blob/main/docs/public-api.md)
- [SDK 指南](https://github.com/bhargavmahanta/envGuard/blob/main/docs/sdk.md)
- [代理集成](https://github.com/bhargavmahanta/envGuard/blob/main/docs/agent-integration.md)
- [未来 MCP 架构](https://github.com/bhargavmahanta/envGuard/blob/main/docs/mcp-architecture.md)
- [发布流程](https://github.com/bhargavmahanta/envGuard/blob/main/docs/releasing.md)
- [V1.0 发布说明](https://github.com/bhargavmahanta/envGuard/blob/main/docs/release-notes-v1.md)
- [V1.0 就绪状态](https://github.com/bhargavmahanta/envGuard/blob/main/docs/v1-readiness.md)
- [兼容性](https://github.com/bhargavmahanta/envGuard/blob/main/docs/compatibility.md)
- [设计说明](https://github.com/bhargavmahanta/envGuard/blob/main/docs/design.md)
- [路线图](https://github.com/bhargavmahanta/envGuard/blob/main/docs/roadmap.md)
## 许可证
MIT
## 免责声明
EnvGuard 是一款防御性安全工具。请仅扫描您拥有或获得授权测试的代码仓库。
标签:DevSecOps, GNU通用公共许可证, MITM代理, Node.js, 上游代理, 代码质量检查, 安全合规, 数据可视化, 文档结构分析, 网络代理, 聊天机器人, 自动化攻击, 配置安全