Skip to main content
Episode 18 of 24Secure and test60 min

Harden your store: headers, limits, admin safety and a review

Add security headers, rate limiting, strict input checks and safer admin access, scan for leaked secrets and weak packages, set up backups, and get an honest OWASP-style review.

You will have: A hardened store with a SECURITY_REVIEW.md that lists what was checked, what was fixed and what still needs a human decision.

Before you start

  • Episodes 1 to 17 are done and your latest work is committed to GitHub on main
  • Start a fresh session, on a new branch, so every change is easy to review or undo
  • Know which authenticator app you would use for admin two-step login, if you want it (any standard TOTP app works)
  • Be ready to answer a question about where to keep rate-limit counters; the agent will explain the options

Make it yours

Change the example (fashion store) to your own. Your answers are saved in this browser and used in every episode.

Other series keywords (4)

Your prompt

Paste into: Your AI agent (Claude Code or Codex) opened in your project folder. Use your normal permission mode, not any skip-permissions mode, because this episode touches security settings.
You are a careful senior application security engineer working inside my project folder. The store is "Thread & Needle", a fashion e-commerce store selling women's and men's clothing, shoes and accessories in United States at threadandneedle.com, with payments through Stripe. Harden it and review it. I am not a programmer, so explain any technical word in a few words and tell me what each change protects against.

Plan first: inspect the whole project, then show me a numbered plan with the risks you found and wait for my OK before changing anything. Work on a new branch and use small commits.

Tasks:
1. Security headers: Content-Security-Policy, Strict-Transport-Security, X-Content-Type-Options, Referrer-Policy, Permissions-Policy and frame protection. Allow only what the store really uses (my own domain, Cloudinary images, Stripe's hosted pages and scripts if any). Start the Content-Security-Policy in report-only mode, test every page, then enforce it. Read the documentation of the Next.js version installed in this project before writing config, because file names and APIs differ between versions.
2. Rate limiting for login, sign-up, password reset, contact forms, checkout start and admin routes. Serverless hosting does not share memory between requests, so do not rely on a simple in-memory counter in production. Explain the options (a database table, or a free hosted store, or the host's firewall) and ask me which to use.
3. Input validation: confirm every route handler and server action validates with Zod, limits lengths and sizes, and escapes output. Look for raw SQL strings and unsafe HTML rendering.
4. Sessions and CSRF: check Auth.js cookie settings (httpOnly, secure, sameSite), session lifetime, password hashing, safe redirects after login, and that webhooks verify signatures and are the only routes outside normal request protection.
5. Admin protection: server-side role checks everywhere, no default or shared admin password, a rate limit and clear lockout message, and optional two-step login for admins with a standard authenticator app, including recovery codes stored hashed.
6. Secrets: scan the working files and the full git history with a secret scanner such as gitleaks, confirm .env.local is git-ignored, and confirm .env.example has names only. If a secret was ever committed, tell me to rotate it; do not just delete it.
7. Dependencies: run npm audit, fix what is safe, and list what needs my decision. Do not run forced upgrades without asking.
8. Backups: add a documented script for a local database dump and a tested restore into a scratch database. Explain what the online database provider offers for backups and restore, and tell me to verify it on their pricing page.
9. Logging: use structured logs with redaction so passwords, tokens, emails, addresses and payment details never appear.
10. OWASP Top 10 review: go through each category for this project and write SECURITY_REVIEW.md with status (fixed, ok, needs decision), evidence and the file involved. Be honest about limits; this is not a substitute for a professional penetration test.

Security rules for you: never print, log or commit a secret, and ask me for any key you need.

Verify: run type-check, lint, tests and a production build, then show me the response headers of the home page, a blocked rapid-login attempt, and the secret scan result.

Report back in this format: 1) What was done. 2) What I should check myself. 3) Anything that needs my decision.

Review the prompt, then copy it. Never paste real passwords or API keys into a chat.

How to check it worked

  • Opening your site in a browser shows no broken images or blocked scripts after the policy is enforced
  • Five or six wrong passwords in a row get a calm "try again later" message instead of unlimited tries
  • The secret scan reports no findings, or lists exactly what to rotate
  • SECURITY_REVIEW.md has a row for every OWASP Top 10 category with evidence
  • If you enabled admin two-step login, signing in as admin asks for a code and wrong codes are refused
  • The backup script creates a file and you restored it into a scratch database without errors

Sample result

Example: fashion store

Example result for the fashion store: the agent's review summary. Findings are illustrative.

If something goes wrong

After the security policy is enforced, images, fonts or the payment page stop loading.
Open the browser's developer console, copy the blocked-source messages to the agent and ask it to allow only those exact sources. Switch back to report-only while you fix it.
Rate limiting blocks you or real customers.
Ask the agent to show the current limits and raise them for the affected route. Limits for login should be strict; limits for browsing should be generous.
The secret scanner flags a test key or an example.
Ask the agent to explain each finding. Real secrets must be rotated at the provider. Fake placeholders can be allow-listed with a comment explaining why.
npm audit lists problems that need a major version upgrade.
Do not force it. Ask for the risk in plain words, whether the vulnerable code is used in your store, and a separate branch with the upgrade and a full test run.

Free tools throughout: gitleaks and npm audit cost nothing. If you pick a hosted rate-limit store or a firewall add-on, check its free allowance on the provider's pricing page.

More in Secure and test

This is part of the series Build a secure, no-cost e-commerce website with AI agents. See all 24 episodes, the tools used and answers to common questions on the series page.

We use optional cookies for analytics and referral tracking. Learn more about our privacy policy