基于 Go 的 CLI 工具,可扫描代码库以评估上线就绪状态,在生产部署之前检测缺失配置、安全卫生问题、密钥泄露和集成缺口。
Preflight.sh 是一个命令行工具,可扫描你的代码库以检查上线就绪情况。它能在你部署到生产环境之前,识别出缺失的配置、集成问题、安全隐患、SEO 元数据缺口以及其他常见错误。
别在生产环境里出丑。只需运行这条命令。
brew install preflightsh/preflight/preflight
npm install -g @preflightsh/preflight
go install github.com/preflightsh/preflight@latest
docker pull ghcr.io/preflightsh/preflight
curl -fsSL https://preflight.sh/install.sh | sh
从 GitHub Releases 下载最新版本。
从 v0.23.0 起,每个归档文件都附带签名的构建来源证明。要验证下载内容是否由本仓库的发布工作流构建:
gh attestation verify preflight_<version>_<os>_<arch>.tar.gz --repo preflightsh/preflight
# Initialize in your project directory
cd your-project
preflight init
# (asks before replacing an existing preflight.yml; --force skips the question)
# In a script or CI job, where nobody can answer, pass --yes to accept the
# detected defaults. Without it, init stops and writes nothing when its input
# ends before the questions do.
# Run all checks
preflight scan
# Scan a specific directory
preflight scan /path/to/project
# Run with verbose output (shows which files matched each check)
preflight scan --verbose
preflight scan -v # short form
# Run in CI mode with JSON output
preflight scan --ci --format json
# Run only specific checks, or skip some, for fast iteration
# (one-off; unlike `preflight ignore` it doesn't change preflight.yml)
preflight scan --only seo_meta,og_twitter
preflight scan --skip vulnerability,secrets
# Silence a check
preflight ignore sitemap
# Unsilence a check
preflight unignore sitemap
# List all check IDs
preflight checks
本仓库包含一个兼容 skills.sh 的 agent skill,位于 skills/preflight/SKILL.md。它为编码 agent 提供了一套可重复的 Preflight 工作流:检查 preflight.yml、运行 CI 安全的扫描、对发现的问题进行分类、避免不安全的忽略、重新运行验证,并报告剩余的发布风险。
从本仓库列出该 skill:
# With Bun
bunx --yes skills add preflightsh/preflight --list
# Or with npm
npx --yes skills add preflightsh/preflight --list
仅安装 Preflight 技能:
# With Bun
bunx --yes skills add preflightsh/preflight --skill preflight
# Or with npm
npx --yes skills add preflightsh/preflight --skill preflight
Preflight 无需账户即可在命令行中完全使用。位于 app.preflight.sh 的可选仪表板会为你的扫描添加托管历史记录,并针对每个发现提供 AI 生成的修复建议。你的代码永远不会离开你的机器:扫描在本地运行,除非你发布,否则不会发送任何内容。仪表板持有者令牌仅限于签发它们的来源,且经过身份验证的重定向不能跨来源或降级 HTTPS。
security_headers、ssl、www_redirect、email_auth、debug_statements、error_pages、image_optimization、legal_pages 以及 Web 标准文件检查。debug_statements 和 image_optimization 最多包含五条发现(文件与行号,或文件与大小)。seoMeta 布局路径和环境文件名会被移除,URL 凭据、查询字符串和片段也会被移除。secrets、vulnerability、env_parity、health_endpoint、stripe、index_now、每项服务检查以及任何“Check failed:”错误。preflight.yml:项目名称、技术栈、URL 来源、服务声明以及启用了哪些检查。IndexNow 密钥、Stripe webhook URL、密钥允许列表、环境文件名、健康路径、布局路径和忽略列表会被丢弃。建议、文件内容、审计工具输出和机密值永远不会被发送。
创建一个免费账户,然后连接 CLI:
preflight auth login # opens your browser to authorize this CLI
preflight auth status # show who you're logged in as
preflight auth logout # remove stored credentials
使用 --publish 将扫描结果发布到你的仪表板。它会打印一个用于查看本次运行的链接。发布是尽力而为的:如果你处于离线状态或未登录,扫描仍会运行并正常退出。
preflight scan --publish
在仪表板上,你可以看到每次运行的通过/警告/失败明细、检查结果列表,以及按项目划分的历史记录,从而了解各次部署之间发生了哪些变化。
你也可以在终端中使用 preflight history 读取该历史记录:
preflight history # recent runs across your projects
preflight history --here # only the current project's runs
preflight history <run-id> # one run's full check results
preflight history --here --format json # machine-readable, for agents
需要 preflight auth login。--here 会通过 git remote 将运行匹配到当前仓库,这与发布时使用的键相同。从仓库子目录扫描的应用(monorepo 中的一个应用)也会以该子目录作为键,因此 apps/web 和 apps/api 会发布到不同的 dashboard 项目。history --format json 携带与 scan JSON 相同的 schema_version 和 cli_version 字段。
在 CI 或没有浏览器的其他机器上,改用 token 登录:preflight auth login --token - 从 stdin 读取 token,或者设置 PREFLIGHT_TOKEN 并运行 preflight auth login。无论哪种方式,token 都会像浏览器登录一样被检查和存储;后续命令读取存储的凭据,而不是该变量。
打开已发布运行中任何失败或警告的检查项,即可生成针对你检测到的技术栈量身定制的分步修复方案,包含可直接复制的命令和代码。
| 检查项 | 描述 |
|---|---|
| ENV 一致性 | 比较 .env 和 .env.example 以查找缺失的变量(可选启用;preflight init 会开启) |
| 健康端点 | 验证站点可访问;依次尝试 /health、/healthz、/api/health、/_health 和 /status,然后回退到根路径 |
| 漏洞扫描 | 使用包管理器的审计工具(bundle-audit、npm audit 等)检查依赖漏洞 |
| SEO 元数据 | 检查 title、description 和 Open Graph 标签 |
| OG 与 Twitter Cards | 验证 og:image、twitter:card 和社交分享元数据 |
| 规范 URL | 验证 canonical 链接标签是否存在 |
| Viewport | 检查移动端是否有正确的 viewport meta 标签 |
| Lang 属性 | 验证 html lang 属性以确保可访问性 |
| 结构化数据 | 检查 JSON-LD Schema.org 标记 |
| 安全响应头 | 在生产和预发布环境验证 HSTS、CSP、X-Content-Type-Options 和 Referrer-Policy;弱 CSP(例如 'unsafe-inline' 脚本)属于建议,而非失败(可选启用;当你提供生产 URL 时 preflight init 会开启) |
| SSL 证书 | 检查 SSL 有效性并在过期前发出警告;本地 URL 会跳过 |
| WWW 重定向 | 验证 www/非 www 重定向到规范 URL |
| 邮件认证 | 检查邮件发送域名的 SPF/DMARC 记录,若未设置则检查生产 URL 的域名(可选启用) |
| 密钥扫描 | 在代码中查找泄露的 API 密钥和凭据(可选启用;preflight init 会开启) |
| 调试语句 | 检测代码中遗留的 console.log、var_dump、debugger;位于开发守卫之后的语句(在代码中,或在 Twig、ERB、Blade、Django 和 Go 模板中,包括同行 && 和三元表达式)不会被报告 |
| 错误页面 | 检查自定义 404/500 错误页面 |
| 图片优化 | 查找影响加载时间的大图片(>500KB) |
| 法律页面 | 检查已部署站点上的隐私政策和服务条款页面,当主机被阻止或宕机时回退到源代码 |
| Favicon 与图标 | 检查 favicon、apple-touch-icon(.png、.webp、.svg)和 web manifest,包括布局 <link> 标签中声明的图标以及 Next.js icons 元数据;缺少 favicon 属于警告 |
| robots.txt | 验证 robots.txt 存在且有内容 |
| sitemap.xml | 检查 sitemap 文件或生成器,包括 Next.js Pages Router、Astro 和 SvelteKit 端点 |
| llms.txt | 检查 LLM 爬虫指引文件 |
| ads.txt | 为广告支持的站点验证 ads.txt(可选启用) |
| humans.txt | 检查 humans.txt 以表彰团队(可选启用) |
| IndexNow | 验证 IndexNow 密钥文件;当站点可访问时,由已部署的 /{key}.txt 决定(可选启用) |
| LICENSE | 检查许可证文件(可选启用,适用于开源项目) |
Cookie 同意工具(CookieConsent、Cookiebot、OneTrust 等)作为服务进行检查,而不是作为独立检查项。
Preflight 会自动检测并验证以下服务的配置:
支付
错误跟踪与监控
电子邮件与新闻简报
分析
身份验证
聊天
通知
基础设施
存储与 CDN
搜索
SEO
AI / LLM
Preflight 使用项目根目录中的 preflight.yml 文件:
projectName: my-app
stack: rails # rails, next, react, vite, laravel, etc.
urls:
staging: "https://staging.example.com"
production: "https://example.com"
services:
stripe:
declared: true
sentry:
declared: true
checks:
envParity:
enabled: true
envFile: ".env"
exampleFile: ".env.example"
healthEndpoint:
enabled: true
path: "/health" # optional; with enabled: true only this path is checked