← Lock It DownArrows or space · F for fullscreen · Print to saveTalks

CLAUDE CODE BUILD NIGHT · PART 9

Lock It
Down

Tonight, we harden every door. Every night stands on its own.

Ship AI · TalksLock It Down01/21

Who's hosting

How you do anything is how you do everything.

Santos Hernandez
Santos HernandezFounder, Ship AI
$25k+/moggbucks, built with agents
$0 to $12MARR at ZBD
EU firstMiCAR approval
THE COMMUNITY

Ship AI

Free workshops and talks in Phoenix.

shipai.club
THE STUDIO

Ship AI Studio

AI built into your business, in two weeks.

shipaistudio.com

Ship AI · TalksLock It Down02/21

Join the room

SHIP AI DISCORD

Scan it now.
Prompts later.

Open the Discord invite

Ship AI · TalksLock It Down03/21

Our partner

Ship AIWorkuityAI Exchange

Building Phoenix's AI community, together. Workuity hosts tonight, and we present Founder Weekend side by side.

Ship AI · TalksLock It Down04/21

THE IDEA

Every route is a front door.
Lock each one.

Ship AI · TalksLock It Down05/21

Hidden is not secure

HIDDEN

"Nobody knows that URL."

LOCKED

Checked on every request.
Limited, signed, logged.

Ship AI · TalksLock It Down06/21

Tonight

01

Map

02

Limit

03

Lock

04

Review

Ship AI · TalksLock It Down07/21

Tonight's checklist

SECURITY.md
Threats

A scripted AI bill. A forged webhook. A leaked key.

Controls

Every route: who, check, limit.

Data

Row level security. Masked emails. Encrypted tokens.

Done when

The 21st search gets a 429

Forged webhooks get a 400

User A can't see user B

Ship AI · TalksLock It Down08/21

Map every door

claude · ~/whats-for-dinner

✓ 9 routes, 3 cost money, 1 has no auth check

claudeWho should be able to call /api/leads?

youAnyone, but insert only.

✓ Wrote SECURITY.md: 6 threats, 8 routes

Copy · write SECURITY.md
Map every route, what it costs and who may call it, interview me, then write SECURITY.md. No secrets, no code changes. Wait for my OK.

Full prompt

Copy this entire prompt into Claude Code.

Read SPEC.md, WORKFLOW.md and GROWTH.md, then the code under app/api, app/actions and lib. We're hardening What's for Dinner before more people use it.

1. List every route and server action: what it does, who may call it, what it reads or writes, and what it costs (AI calls, emails).
2. Interview me one question at a time about anything the code doesn't tell you, and wait for each answer.
3. Write SECURITY.md with these sections: Rules, Threats (worst first), Controls per route (a table: route, who, auth check, rate limit, notes), Data (which columns hold personal data and who may read them), Secrets (names only, and where each one lives), Review, Done when.

Never open, print or paste the contents of any .env file or any secret value. Refer to secrets by name only. Don't change any code. Stop and wait for my OK.

Ship AI · TalksLock It Down09/21

Limit what costs money

claude · ~/whats-for-dinner

✓ Better Auth limiter · database storage

✓ lib/ratelimit.ts · 20 searches an hour per user

200 ×20 · 429 ×5

claudeThe UI shows "Try again in 12 minutes."

Copy · rate limits in the app
Turn on Better Auth's limiter with database storage, wait while I set up Upstash, then limit the AI and signup routes per user and prove it with 25 calls.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md, section Controls per route. Check the current docs first: better-auth.com/docs/concepts/rate-limit and upstash.com/docs/redis/sdks/ratelimit-ts/gettingstarted. Stop after each step.

1. Better Auth: turn on rateLimit with storage: "database", because in-memory counters don't hold across serverless instances. Keep its stricter sign-in default and add customRules for sign-up and password reset. Two catches from the docs: the limiter is off in development by default, and server-side auth.api calls skip it. Check that sign-in goes through the Better Auth client or the /api/auth routes, not auth.api inside a server action. Read the IP address section, then check Vercel's docs for which client IP header Vercel sets, and configure ipAddressHeaders to match. Database storage needs a migration: show it to me before applying it.
2. Tell me to create an Upstash Redis database myself and add UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN to .env.local and to the Vercel project. Wait until I tell you it's done.
3. Run npm install @upstash/ratelimit @upstash/redis. In lib/ratelimit.ts create sliding-window limiters: 20 dinner searches an hour per user id, 10 fridge photos an hour per user id, 5 guide signups an hour per IP.
4. Call them at the top of /api/dinners, the photo route and the leads route, before any AI call or database write. Return 429 with a Retry-After header and a friendly message the UI shows.
5. Write a small script that calls /api/dinners 25 times as my test user on localhost and prints the status codes: 20 should pass and the 21st onward get a 429. Then prove the sign-in limit, 4 attempts in 10 seconds with the 4th getting a 429, on a Vercel preview, or locally with rateLimit enabled: true set temporarily, then remove it. Everyone on this Wi-Fi shares one IP, so test per-user limits and don't hammer per-IP limits on a shared app. Run it and stop.

better-auth.com/docs/concepts/rate-limit

Ship AI · TalksLock It Down10/21

Rules at the edge

Vercel · Firewall
CUSTOM RULESPOST /api/dinners · per IP · 429
*.env, */.git*, *.bak · Deny
/admin · not on my list · Deny

Every rule starts as Log.

01

Claude writes FIREWALL.md

Each rule's conditions, action and undo.

02

You publish it

In the dashboard, after 10 minutes on Log.

03

Cron stays open

Exclude the cron routes from deny rules.

Copy · Firewall rules and IP lists
Write FIREWALL.md: an IP rate limit on the AI routes, a deny rule, an /admin allow list, cron excluded, all starting as Log. I publish them, then you update SECURITY.md.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md. We're adding rules in the Vercel Firewall, which I set up myself in the dashboard. Read vercel.com/docs/vercel-firewall/vercel-waf first, including rate limiting, custom rules and IP blocking, and check the plan limits for our plan.

1. Write FIREWALL.md with each rule I should add: name, If conditions, Then action, and how to undo it. Include:
   - A rate limit on POST requests to /api/dinners and the photo route, keyed by IP. Hobby allows one rate limit rule, so put both paths in it.
   - A deny rule for paths ending in .env or .bak, or containing /.git (so /.git/config is caught too).
   - An allow list for /admin: deny any request to /admin from an IP that isn't on my list. We build the admin console in a later part.
   - Where to block one abusive IP or CIDR range under IP Blocking.
   - Exclude /api/cron and /api/at-risk (the at-risk email cron from Part 7) from every deny or challenge rule, so Vercel Cron still runs.
   - Note that everyone on one Wi-Fi shares an IP, so a per-IP limit tested from a room trips for everyone at once.
2. Every rule starts with the Log action. Tell me how to watch it in the Firewall overview for 10 minutes before switching it to 429 or Deny.
3. Tell me to add the rules, review the changes and publish them. Wait until I tell you it's done.
4. Add an Edge rules section to SECURITY.md listing what's live. Never ask me for a Vercel token, and never put my IP addresses in a committed file.

vercel.com/docs/vercel-firewall/vercel-waf

Ship AI · TalksLock It Down11/21

Verify every webhook

claude · ~/whats-for-dinner

unsigned request → 400

repeated svix-id → 200, skipped

✓ cron secret · timingSafeEqual

claudeThe approve route checks the plan owner before resumeHook.

Copy · signed webhooks and secret checks
Verify Resend webhooks on the raw body, reject stale requests, skip repeats with a 200, compare the cron secret in constant time, and check the approval route before resumeHook.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md. We're receiving Resend webhooks for bounces and complaints, so we stop emailing those addresses. Read resend.com/docs/webhooks/verify-webhooks-requests first. Stop after each step.

1. Tell me to create the webhook in Resend pointing at /api/webhooks/resend, and to add its signing secret as RESEND_WEBHOOK_SECRET to .env.local and to the Vercel project as a Secret. Wait until I tell you it's done.
2. Build the route: read the raw body as text before any JSON parsing, verify it with resend.webhooks.verify using the svix-id, svix-timestamp and svix-signature headers, and return 400 on any failure without saying why.
3. Replays: check whether the verifier already rejects old timestamps. If it doesn't, reject anything more than 5 minutes old with a 400. Store each svix-id with a unique constraint. A verified request whose svix-id is already stored returns 200 and does nothing: Resend retries any delivery that doesn't get a 2xx, so a 400 here would make it keep retrying. Show me the migration before applying it.
4. On bounce and complaint events (check Resend's event names), mark that address suppressed, and make every send check it first.
5. Change the cron routes' CRON_SECRET check to crypto.timingSafeEqual, comparing lengths first.
6. Read the Workflow SDK hooks docs in node_modules/workflow/docs. A hook token is not authorization, so confirm the plan approval route takes the user from the Better Auth session and checks they own the plan before calling resumeHook.
7. Send one unsigned request with curl and show me the 400. Then replay one signed test event from the Resend dashboard and show me the repeat gets a 200 with no second suppression or row. Stop.

resend.com/docs/webhooks/verify-webhooks-requests

Ship AI · TalksLock It Down12/21

Rows only their owner sees

claude · ~/whats-for-dinner

claudeThe app connects as the owner role. It bypasses RLS.

Proposed: app_user, 3 policies, FORCE on 3 tables

youRun it on the branch.

user A → user B's dinners: 0 rows

Copy · row level security on Neon
Propose a least-privilege app role, forced RLS policies and per-request set_config, wait while I create the role on a Neon branch, then prove user A can't see user B.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md, section Data. Then read neon.com/docs/guides/rls-query-execution and the Postgres row security docs. Propose everything first; don't apply anything until I say so. Stop after each step.

1. Check which role the app connects as today. Neon's owner role has BYPASSRLS, so policies would be ignored. Propose a login role app_user with no BYPASSRLS that owns no tables, and list exactly the grants it needs: what Better Auth's tables need, SELECT, INSERT, UPDATE and DELETE on dinners, favorites and plans, and INSERT only on leads. Migrations keep using the owner role.
2. Write the migration: ENABLE and FORCE ROW LEVEL SECURITY on dinners, favorites and plans, with policies that match user_id to current_setting('app.user_id', true). Show it to me. Don't run it.
3. Check which Neon driver the app uses. set_config(..., true) only lasts for one transaction, so the HTTP neon() function's single queries won't carry it. Use Pool over WebSockets for these queries, or sql.transaction([...]) with the set_config as the first query. Then write lib/db-as-user.ts: every user-facing query runs in a transaction that first calls set_config('app.user_id', userId, true), with the id taken from the Better Auth session, never from the request body. List the cron jobs, workflow steps and the admin console (Part 11) that read across users. They use lib/db-privileged.ts: one server-only connection (import "server-only") that client code can never import. Add every caller to SECURITY.md.
4. Tell me to create a Neon branch, create the app_user role and its password myself, and put its connection string in .env.local as DATABASE_URL_APP. Wait until I tell you it's done.
5. Run the migration on the branch only. Prove that signed in as user A, user B's dinners and favorites return nothing. Then tell me the steps for production and stop.

neon.com/docs/guides/rls-query-execution

Ship AI · TalksLock It Down13/21

Keep personal data out of sight

claude · ~/whats-for-dinner

⚠ lib/ai.ts:41 logs the request body

⚠ signed_up sends email to PostHog

✓ leads_masked · j***@gmail.com

claudeEvents now carry user ids only.

Copy · mask and minimize PII
Find every PII leak by file and line, add a masked leads view, strip emails from PostHog with property_denylist and before_send, and log ids only.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md, section Data, and GROWTH.md, section Events.

1. List every place an email, name, IP address, ingredient list or dietary note could leak: logs, error messages, PostHog events, AI request logs, emails. Show me file and line only, never the values.
2. Propose a view leads_masked that shows each email as its first letter, three stars and the domain, plus the date and source. Support screens and the admin console will read the view, never the table. Show me the migration before applying it.
3. PostHog: check posthog.com/docs/libraries/js/config, add email and name to property_denylist, and add a before_send that drops any property whose key contains email, phone or ingredients. Identify users by id only.
4. Replace any log of a request body or user object with a log of ids.
5. If we store allergies or dietary needs, treat them like PHI: only the owner and the server read them, and they never reach analytics, logs or error reports.

Show me the diff and stop.

posthog.com/docs/product-analytics/privacy

Ship AI · TalksLock It Down14/21

Stored is not safe

PLAINTEXT

One leaked backup, every token.

ENCRYPTED

Useless without the key.
And the key lives elsewhere.

Copy · encrypt tokens at rest
AES-256-GCM in lib/crypto.ts with a versioned key I generate myself, encrypted OAuth tokens, a proposed migration for old rows and a rotation plan.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md, section Secrets. No token or credential we store goes in the database as plaintext. Stop after each step.

1. Better Auth: if we add social sign-in, set account.encryptOAuthTokens to true. Check better-auth.com/docs/reference/options for the current option first.
2. Write lib/crypto.ts with encrypt and decrypt using Node's crypto and aes-256-gcm: a random 12-byte IV per value, the auth tag stored with the ciphertext, and a key version prefix such as v1: so we can rotate keys.
3. The key comes from APP_ENCRYPTION_KEY. Tell me to generate it myself with openssl rand -base64 32 and add it to .env.local and to the Vercel project as a Secret. Wait until I tell you it's done. Never print it or read it back.
4. Find any column that stores a third-party token or key today. Propose a migration that encrypts existing rows in batches, and show it to me before running anything.
5. Write ROTATION.md: add a v2 key, re-encrypt rows in batches, then retire v1.
6. Tell me in two lines why we encrypt in the app here instead of with pgcrypto: the key would travel inside SQL that can end up in query logs. Stop.

Ship AI · TalksLock It Down15/21

Secrets stay secret

claude · ~/whats-for-dinner

✓ .env*.local ignored · never committed

✓ .env.tpl · 9 op:// references

⚠ RESEND_API_KEY is Config, not Secret

claudeRe-save it as a Secret, then rotate it.

Copy · secrets audit
Check .gitignore and git history, find hardcoded keys by location only, write a 1Password .env.tpl, and give me the Vercel and GitHub checklist.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md, section Secrets. Never print a secret value. Report key names, files and line numbers only.

1. Check .gitignore covers .env and .env*.local, and search the git history by filename for any committed .env file. If one was ever committed, list the key names I need to rotate.
2. Search the code for hardcoded keys and tokens by pattern. Report locations only.
3. Write .env.tpl with a 1Password secret reference for every key name, in the form op://<vault>/<item>/<field>, using the vault plan from Part 1, so I can run: op run --env-file=.env.tpl -- npm run dev
4. Write me a checklist: in Vercel, make sure every API key, token and password is a Secret environment variable, not Config; in GitHub, check what secret scanning and push protection cover for this repo, since public and private repos differ. Wait until I tell you it's done.
5. Add a Rotation table to SECURITY.md: each key name, where it lives, who rotates it and when it was last rotated. Stop.

1password.dev/cli

Ship AI · TalksLock It Down16/21

A second model audits the diff

npx tsx scripts/audit-diff.ts

deepseek/deepseek-v4.1-flash · 14 files

HIGH · app/api/photo/route.ts:22 · no size limit

LOW · lib/email.ts:9 · logs recipient

claudeBoth are real. The size check goes before the AI call.

Copy · the cross-lab audit
A script sends the branch diff and SECURITY.md to DeepSeek V4.1 Flash via AI Gateway for typed findings, then Claude checks each one against the code.

Full prompt

Copy this entire prompt into Claude Code.

Read SECURITY.md. We're adding a second opinion from a cheaper model from a different lab: "deepseek/deepseek-v4.1-flash" through AI Gateway. Check the AI Gateway model list first that the ID is still current.

1. Write scripts/audit-diff.ts: run git fetch, then get the diff with git diff origin/main...HEAD (ask me first if our default branch isn't main, and warn me if the diff is empty), drop any .env file, key file or lockfile, and send the rest with SECURITY.md to the model using generateText with output: Output.object and a Zod schema: findings, each with file, line, severity, which threat in SECURITY.md it maps to, and a suggested fix. If structured output fails with this model, ask for JSON in the prompt and parse it with the same Zod schema.
2. Print the findings as a table, and exit with a non-zero code on any high-severity finding.
3. AI_GATEWAY_API_KEY is already in .env.local. Don't print it.
4. Run it on this branch. Check every finding against the code yourself and tell me which are real and which are noise. Don't fix anything yet. Stop.

vercel.com/ai-gateway/models

Ship AI · TalksLock It Down17/21

A second set of eyes on every PR

Three reviewersEvery PR

Rules from SECURITY.md
in .cursor/BUGBOT.md

01

Bugbot

Cursor reviews each PR for bugs and security issues.

02

Security Review

Cursor's Security Reviewer agents, set up in Automations.

03

/security-review

You type it in Claude Code before every push.

Copy · Bugbot rules and the review habit
Turn SECURITY.md into .cursor/BUGBOT.md, wait while I connect Bugbot, trigger it on a PR, then check every Done when item.

Full prompt

Copy this entire prompt into Claude Code, then the Cursor dashboard and your PR.

Read SECURITY.md. Read cursor.com/docs/bugbot first.

1. Write .cursor/BUGBOT.md from SECURITY.md: the threats, the rules every route follows, and what to flag: a route without a session check, a costly route without a rate limit, a webhook read before its signature is verified, personal data in logs or events, a user query that doesn't go through lib/db-as-user.ts, and any secret in code.
2. Tell me to connect this repo to Bugbot in the Cursor dashboard, and to set up Security Review in Automations if our plan includes Cloud Agents. Wait until I tell you it's done.
3. Open a small PR that adds .cursor/BUGBOT.md. Tell me to comment bugbot run on it, and wait until I tell you it's done.
4. Add to the Review section of SECURITY.md: I type /security-review in Claude Code myself before every push. Check every Done when item in SECURITY.md, tell me which pass, and stop.

Also in the series: Part 10, Production Monitoring. Know the moment it breaks.

Ship AI · TalksLock It Down18/21

Take it home

THE TALK PAGE

Every prompt,
and this deck.

Open the talk page

Ship AI · TalksLock It Down19/21

Founder Weekend

FEB 6‑7, 2027 · FREE

Tonight was one hour.
Take a weekend.

An Arizona AI hackathon. Teams of 1-4.

See the hackathon

Ship AI · TalksLock It Down20/21

SHIP AI DISCORD

Free and open.
Build with us.

Scan to join

Ship AI · TalksLock It Down21/21
01/21