Vibe Security Rules — Next.js + Supabase + Stripe

    by 高潮辉

    1

    Left to themselves, they also write Supabase policies like `USING (true)`, bury service_role keys in client code, and leave storage buckets public.

    Free

    1 useSecurity scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Vibe Security Rules — Next.js + Supabase + Stripe

    Example session with this skill installed

    Review my new orders table migration and the Stripe webhook handler for security issues. Enable RLS and make sure I'm not leaking anything.

    • Read your context and instructions
    • Compiled the vibe security rules

    I have reviewed your orders migration and the Stripe webhook handler. I found two critical issues: the RLS policy was set to USING (true) for authenticated users, which would allow any user to see all orders, and the webhook was parsing the JSON body without signature verification.

    Security Audit & Fixes

    ComponentIssue FoundFix Applied
    migrations/orders.sqlInsecure RLS PolicyRestricted access to auth.uid() = user_id
    app/api/webhook/route.tsMissing Sig VerificationAdded stripe.webhooks.constructEvent with raw body
    app/api/webhook/route.tsTrusted Client DataRemoved reliance on req.json().price; now fetching from DB

    Updated Migration

    -- migrations/20231027_create_orders.sql
    alter table public.orders enable row level security;
    
    create policy "Users can view own orders"
      on public.orders for select
      to authenticated
      using (auth.uid() = user_id);
    
    create policy "Users can insert own orders"
      on public.orders for insert
      to authenticated
      with check (auth.uid() = user_id);
    

    Secured Webhook Handler

    import { stripe } from "@/lib/stripe";
    import { headers } from "next/headers";
    
    export async function POST(req: Request) {
      const body = await req.text();
      const signature = headers().get("stripe-signature") as string;
      let event;
    
      try {
        event = stripe.webhooks.constructEvent(
          body,
          signature,
          process.env.STRIPE_WEBHOOK_SECRET!
        );
      } catch (err) {
        return new Response("Invalid signature", { status: 400 });
      }
    
      if (event.type === "checkout.session.completed") {
        const session = event.data.object;
        // Ownership check: use metadata or lookup user by session
        await fulfillOrder(session.metadata.userId, session.id);
      }
    
      return new Response("Webhook processed", { status: 200 });
    }
    

    Next steps

    1. Add STRIPE_WEBHOOK_SECRET to your .env.local file if not already present.
    2. Run supabase db push to apply the updated RLS policies.
    3. Test the webhook using the Stripe CLI to ensure signature verification passes.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    AI coding agents write working code fast. Left to themselves, they also write Supabase policies like USING (true), bury service_role keys in client code, and leave storage buckets public.

    Vibe Security Rules is a small, opinionated rule set for apps built with Cursor, Windsurf, Claude Code, or any other AI coding tool. It covers the Next.js + Supabase + Stripe stack — the stack AI-built SaaS apps most often ship with.

    The pack has twelve rules, each one covering a mistake real AI-built apps have shipped:

    1. Row Level Security is mandatory — RLS on every table, policies scoped to the owner or tenant, never USING (true).
    2. Server secrets stay server-side — no service_role key (or any secret key) in client code or NEXT_PUBLIC_ variables.
    3. Storage is private by default — buckets are not public unless there is a stated reason.
    4. Paid-API routes are capped — auth, rate limits, input caps, and a usage ceiling on anything that calls a paid API.
    5. Webhooks verify signatures — Stripe (and every other provider) events are trusted only after their signature is verified.
    6. Every route checks who's calling — identity, role, and price come from the server, never from fields the client sends.
    7. Secrets stay out of git — .env ignored, .env.example holds placeholders only, committed keys get rotated.
    8. Errors don't leak — generic messages to clients, no stack traces, no tokens in logs.
    9. Sessions are revalidated server-side — sensitive actions re-check the session on the server instead of trusting what the client claims.
    10. Views and SECURITY DEFINER functions don't bypass RLS — views and SECURITY DEFINER functions are written so they can't silently bypass row-level security.
    11. Uploads are validated by content — uploaded files are checked by their actual content and type, not just by filename or extension.
    12. Dependencies are checked — third-party packages are screened for known vulnerabilities and supply-chain risks before they ship.

    Every rule comes with a bad/good code example, so both you and the agent can see exactly what changed and why.

    Also included in the package:

    • references/self-check.md — the 10-minute pre-launch self-check: twelve quick tests you run on your own app before you ship.
    • references/cursor-rules.mdc — the same rules as a drop-in Cursor / Windsurf rules file, for always-on protection.
    • references/claude-code-rules.md — the same rules as a drop-in CLAUDE.md template for Claude Code projects.
    • EVALS.md — the verification test suite (evals) that checks the rules hold against real examples.
    • RUNBOOK.md — the eval runbook: how to run the verification suite and read the results.
    • CHANGELOG.md — what changed in each version of the pack.

    Honest limits: prompt rules guard the code your agent writes next. They can't verify the policies you already shipped — that needs a real review of your live app. That's what the human check below is for.

    Free and open: the same pack lives on GitHub — use it, fork it, adapt it to your stack:

    Maintained by CapsAGI — security checkups for AI-built apps.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.

    Optimized for Supabase and Next.js. Cannot verify dashboard-only settings or historical git commits. Requires manual secret rotation if keys were previously exposed.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    1 use

    Times used to date

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed today

    • Free with an Agensi account

    Permissions

    Network Access
    Read Files
    Environment Variables
    Listed15 days ago
    Updatedtoday

    What's inside

    Creator

    高潮辉

    高潮辉

    Frequently Asked Questions

    This skill acts as a security guardrail for your AI agent, preventing it from generating common but dangerous mistakes like `USING (true)` RLS policies, leaking service-role keys into frontend components, or creating unmetered AI endpoints that could lead to unexpected API bills.

    The skill is purpose-built for the Next.js App Router, Supabase (Auth, Postgres, Storage), and Stripe ecosystem, and it includes pre-configured logic for popular AI providers like OpenAI and Anthropic.

    Simply add this skill to your AI agent's environment; you can then use 'Audit Mode' to scan existing migrations and route handlers for vulnerabilities or 'Build Mode' to ensure all new code follows strict security protocols from the start.

    The skill enforces owner-scoped access for all data and storage buckets, validates Stripe webhook signatures to prevent fraud, and implements mandatory rate limiting on server-side routes to protect your metered API usage.

    While this skill hardens your code and configuration files, it cannot scan your Supabase dashboard settings or scrub secrets that were already committed to your Git history prior to installation.

    New in Data & Databases

    Free