FixVibe

// docs / security guides / cursor checklist

Cursor security checklist: 25 items before ship

Building with Cursor? Cursor's autocomplete and Agent features are exceptionally powerful — and create predictable security blind spots. This checklist targets Cursor-specific patterns: service-role key inlining, generated multi-file edits merged without review, Agent-mode terminal commands, and project rules (.cursor/rules) as your first security guardrail. 25 items across secrets, database, auth, headers, deployment, and Cursor-specific gotchas.

PRE = pre-deploy (audit your source). DEPLOY = at deploy time. POST = post-deploy verification.

秘密和 API 密钥(5 项)

Cursor 的自动完成功能是在秘密很常见的开源代码上进行训练的。该模型会自由地建议它们,尤其是在身份验证尝试失败之后。

  1. PRE — Write security rules into your project rules. Add a rule in .cursor/rules (Cursor docs): "Never inline SUPABASE_SERVICE_ROLE_KEY, sk_live_*, or any server secret into client-side code. Always use server-only imports." Cursor applies project rules as context for Agent and chat.
  2. PRE — Audit Composer-generated files. 当Cursor 的 Composer 创建整个文件(尤其是身份验证处理程序)时,逐行检查它。 Composer 有时会内联应仅用于服务器的环境变量。在组件导入中查找 NEXT_PUBLIC_ 或对服务键的直接引用。
  3. PRE — Reject auto-imports of service clients into client components. 如果 Composer 将 import { supabase } from '@/lib/supabase/service' 导入到 React 文件中,请立即删除它并通过 API 端点进行路由。仅服务器导入已明确标记 - 不要跳过它们。
  4. PRE — Scan Agent-mode commits. 代理模式运行终端命令,可以直接提交。审核git log --oneline -20 和git diff HEAD~5 以确保在代理运行期间没有提交看似秘密的字符串。
  5. POST — Run Secrets in JavaScript Bundles. 对已部署的URL 进行被动扫描。如果服务密钥出现在 JS 捆绑包中,请立即轮换它 — Cursor 的自动完成功能可能会内联它。

数据库访问控制(4项)

Composer 通常会生成有效的授权代码,但会跳过RLS——“它有效”的时刻让人们看不到缺失的策略执行。

  1. PRE — Make Cursor generate migrations with RLS. In your project rules: "Every CREATE TABLE public.* migration must include ALTER TABLE ... ENABLE ROW LEVEL SECURITY and a policy per command scoped to auth.uid()." Then ask Cursor to generate the migration.
  2. PRE — Review Composer-generated policies. Composer 有时会在不检查auth.uid() 的情况下编写策略。像 allow select on public.items 这样没有 using 子句的策略是非常危险的。需要 user_id 匹配。
  3. DEPLOY — Confirm RLS and policies are live. Open Supabase Studio and check that every table's RLS toggle is on and that each table has policies. A table with RLS on and no policies denies everything; one with USING (true) allows everyone.
  4. POST — Run a FixVibe scan on the deployed app. Check the Supabase Row-Level Security result: it shows any table an anonymous visitor can read with your public key.

身份验证和会话(4 项)

Cursor 快速生成身份验证流程,但经常错过保持令牌安全的微妙服务器端验证。

  1. PRE — Ensure all auth routes use getUser(). 在API 路线中搜索getSession() 并替换为await supabase.auth.getUser()。 getSession() 读取未经验证的cookie; getUser() 使用Supabase 后端进行验证。
  2. PRE — Check Composer auth handlers for token expiry. Magic-link 令牌需要服务器强制expires_at。默认Supabase 为 1 小时 — 不要要求Cursor 在没有真正原因的情况下覆盖它。
  3. PRE — Audit the sign-in redirect guard. 登录后的 next 查询参数重定向必须经过验证:必须以 / 开头,不能以// 开头。作曲家有时会跳过这一点。如果缺少,请手动添加。
  4. POST — Test logout server-side state destruction. 登录、注销、检查 cookie(DevTools → 应用程序 → Cookies)。必须立即清除会话 cookie。如果它持续存在,则注销处理程序不会破坏状态。

HTTP 安全标头和CSP(3 项)

Cursor默认情况下很少生成中间件。如果您不明确询问,CSP 和 HSTS 通常不存在。

  1. PRE — Demand CSP in your project rules. Add: "Generate a src/middleware.ts with Content-Security-Policy. Use nonce for script-src, no unsafe-inline." Then ask Cursor to generate it. Without this hint, middleware is skipped.
  2. PRE — Verify src/middleware.ts exists. 对于src/ 目录布局,Next.js 仅拾取src/middleware.ts。根级别middleware.ts 会被默默忽略。如果CSP 未登陆,请检查文件是否位于正确的位置。
  3. POST — Run HTTP Security Headers. 被动扫描报告缺少 CSP、HSTS、X-Frame-Options、X-Content-Type-Options。打开报告并按照适用于您的部署平台的修复指南进行操作。

部署卫生(5 项)

Cursor 应用程序通常会落在 Vercel 上,它具有良好的默认值,但需要对 build/deploy 边界进行显式强化。

  1. DEPLOY — Check Vercel env-var scoping. 设置 → 环境变量 → 每个秘密的范围应仅限于Production。切勿与预览版或开发版共享sk_live_*。
  2. DEPLOY — Disable build-log secret echo. 如果您的vercel.json 或GitHub 操作工作流程具有echo $SECRET,请将其删除。构建日志公开存档;日志中的秘密被泄露。
  3. DEPLOY — Use Vercel's managed secrets, not inline workflow vars. Vercel 的设置 → 环境变量静态加密。 GitHub Actions 的秘密总比没有好,但它是为CI 而设计的,而不是部署平台集成。
  4. POST — Verify CSP nonce on the deployed preview. 在浏览器中打开Vercel预览链接,打开DevTools→网络→根HTML响应。 CSP 标头必须存在,并包含 'strict-dynamic' 以及每个请求的唯一随机数。
  5. POST — Rotate any key that ever shipped, even to Preview. 如果某个密钥到达生产捆绑包的时间哪怕只有 10 分钟,它就会遭到泄露。立即旋转。

Cursor特定陷阱(4 项)

Cursor 工作流程特有的模式会带来安全风险:

  1. Agent mode auto-fixes propagate old patterns. 如果您要求代理“修复身份验证错误”,它可能会多次重新生成相同的身份验证文件,每次都内联相同的服务密钥(如果它位于代码库上下文中)。先清洁原件,然后请代理商修复。
  2. Cursor Index leaks intent. Cursor 的 @codebase 索引非常强大,但如果您的 .cursor 目录曾经暴露(错误配置的 S3、git 历史记录),则索引会暴露您的架构和秘密模式。将.cursor 保留在本地。
  3. Composer mode loses context between files. Composer 生成的每个文件都是新鲜的。如果您要求它生成客户端文件,然后生成 API 路由,它们可能会使用不同的 Supabase 客户端配置。检查两者并确保它们符合您的架构。
  4. Autocomplete bias toward "working" over "secure". Cursor 建议传递当前上下文的最快代码。如果您的测试有NEXT_PUBLIC_SERVICE_KEY,自动完成功能会记住它并重新建议它。在与模型共享代码之前清理测试装置。

后续步骤

一旦锁定了 Cursor 特定模式,请对照 general vibe coding security checklist(51 项)和 step-by-step hardening 进行交叉检查。如果您正在混合工具,另请参阅Claude Code checklist。

// scan your app

别再读了,去找你应用里的漏洞。

Drop in a URL — FixVibe runs every passive check from this guide plus the rest of its 230+ passive checks, usually in under a minute. Free, no install, no card.

  • Free 层 — 每月 3 次扫描,无卡。
  • 针对任何 URL 进行被动扫描 — 无需域验证。
  • 针对 Cursor、Claude Code、Lovable、Bolt、v0、Replit 进行了调整。
  • Coding-agent prompts for code/config findings, plus operator steps for DNS/provider fixes.
Cursor security checklist: 25 items before ship · FixVibe