FlyAI Env Guardian
Automated environment variable protection for development teams. Scans codebases for exposed secrets, validates .env file hygiene, and prevents accidental credential leaks before they reach version control.
When to use
Activate this skill when:
- - A developer is about to commit changes that may contain secrets or API keys
- Setting up a new project and need to establish .env security patterns
- Auditing an existing codebase for exposed credentials
- Configuring CI/CD pipelines that handle sensitive environment variables
- Reviewing pull requests for potential secret exposure
Threat Model
High Risk Patterns
| Pattern | Example | Risk Level |
|---|
| Hardcoded API keys | const KEY = sk-proj-abc123 | Critical |
| Database URLs with passwords |
postgres://user:pass@host/db | Critical |
| AWS credentials in code | AWS
SECRETACCESS_KEY = ... | Critical |
| JWT secrets | JWT_SECRET = mysecret | High |
| Private keys | BEGIN RSA PRIVATE KEY | Critical |
| OAuth tokens | github
pat..., ghp
..., gho... | High |
Medium Risk Patterns
| Pattern | Example | Risk Level |
|---|
| Internal URLs | http://internal-api.corp:8080 | Medium |
| IP addresses with ports |
192.168.1.100:3306 | Medium |
| Email addresses in config | admin@company.com | Low |
Scanning Process
- 1. Pre-commit scan: Check staged files for secret patterns using regex matching
- File extension filter: Focus on source code files (.ts, .js, .py, .go, .rs, .java, .env*)
- Entropy analysis: Flag high-entropy strings (potential random tokens) in non-test files
- Known pattern matching: Check against 40+ known secret formats (AWS, GCP, Azure, Stripe, Twilio, etc.)
- .gitignore validation: Ensure .env files are properly ignored
- History scan: Optional deep scan of git history for previously committed secrets
Remediation Actions
When secrets are found:
Immediate
- - Block the commit with a clear error message
- Show exactly which file and line contains the secret
- Suggest moving the value to .env and using process.env
Follow-up
- - If a secret was already committed, recommend rotating the credential immediately
- Generate a .env.example file with placeholder values
- Add missing entries to .gitignore
- Set up git-secrets or pre-commit hooks for ongoing protection
Environment File Standards
Required Structure
- - .env: Local development values (never committed)
- .env.example: Template with placeholder values (committed)
- .env.test: Test environment values (committed, no real secrets)
- .env.production: Production values (never committed, managed by CI/CD)
Naming Conventions
- - Use UPPERSNAKECASE for all variable names
- Prefix with service name: DATABASEURL, REDISHOST, STRIPESECRETKEY
- Document each variable with inline comments
- Group related variables with section headers
CI/CD Integration
GitHub Actions
- - Validate that no .env files are included in the build artifact
- Check that all required env vars are set in the workflow
- Scan PR diffs for new secret introductions
Docker
- - Never use ENV for secrets in Dockerfiles
- Use Docker secrets or mount .env at runtime
- Scan built images for embedded credentials
Configuration
The skill respects a .envguardian.json config file:
- - customPatterns: Additional regex patterns to scan for
- ignoreFiles: Paths to exclude from scanning
- severityThreshold: Minimum severity to report (low, medium, high, critical)
- autoFix: Whether to automatically add .gitignore entries
FlyAI 环境守护者
为开发团队提供自动化环境变量保护。扫描代码库中暴露的密钥,验证.env文件规范性,防止意外凭据泄露到达版本控制系统。
使用场景
在以下情况激活此技能:
- - 开发者即将提交可能包含密钥或API密钥的更改时
- 搭建新项目并需要建立.env安全模式时
- 审计现有代码库中暴露的凭据时
- 配置处理敏感环境变量的CI/CD流水线时
- 审查拉取请求中潜在的密钥暴露时
威胁模型
高风险模式
| 模式 | 示例 | 风险等级 |
|---|
| 硬编码API密钥 | const KEY = sk-proj-abc123 | 严重 |
| 含密码的数据库URL |
postgres://user:pass@host/db | 严重 |
| 代码中的AWS凭据 | AWS
SECRETACCESS_KEY = ... | 严重 |
| JWT密钥 | JWT_SECRET = mysecret | 高 |
| 私钥 | BEGIN RSA PRIVATE KEY | 严重 |
| OAuth令牌 | github
pat..., ghp
..., gho... | 高 |
中风险模式
| 模式 | 示例 | 风险等级 |
|---|
| 内部URL | http://internal-api.corp:8080 | 中 |
| 带端口的IP地址 |
192.168.1.100:3306 | 中 |
| 配置中的邮箱地址 | admin@company.com | 低 |
扫描流程
- 1. 预提交扫描:使用正则匹配检查暂存文件中的密钥模式
- 文件扩展名过滤:聚焦源代码文件(.ts、.js、.py、.go、.rs、.java、.env*)
- 熵分析:标记非测试文件中的高熵字符串(潜在随机令牌)
- 已知模式匹配:检查40+种已知密钥格式(AWS、GCP、Azure、Stripe、Twilio等)
- .gitignore验证:确保.env文件被正确忽略
- 历史扫描:可选深度扫描git历史中先前提交的密钥
修复措施
发现密钥时:
立即处理
- - 使用清晰错误信息阻止提交
- 精确显示包含密钥的文件和行号
- 建议将值移至.env并使用process.env
后续处理
- - 如果密钥已被提交,建议立即轮换凭据
- 生成包含占位值的.env.example文件
- 向.gitignore添加缺失条目
- 设置git-secrets或预提交钩子以持续保护
环境文件标准
必需结构
- - .env:本地开发值(永不提交)
- .env.example:含占位值的模板(提交)
- .env.test:测试环境值(提交,不含真实密钥)
- .env.production:生产环境值(永不提交,由CI/CD管理)
命名规范
- - 所有变量名使用大写蛇形命名法
- 使用服务名称前缀:DATABASEURL、REDISHOST、STRIPESECRETKEY
- 使用行内注释记录每个变量
- 使用章节标题对相关变量进行分组
CI/CD集成
GitHub Actions
- - 验证构建产物中不包含.env文件
- 检查工作流中是否设置了所有必需的环境变量
- 扫描PR差异中新增的密钥引入
Docker
- - 绝不在Dockerfile中使用ENV存储密钥
- 使用Docker密钥或在运行时挂载.env
- 扫描构建镜像中嵌入的凭据
配置
该技能遵循.envguardian.json配置文件:
- - customPatterns:额外扫描的正则模式
- ignoreFiles:排除扫描的路径
- severityThreshold:最低报告严重级别(低、中、高、严重)
- autoFix:是否自动添加.gitignore条目