agentleFS
yaaabsyaaabs/nextjs-16-boilerplate/.claude/skills/security-best-practices/SKILL.md

security-best-practices

Skill3 starsChanged 5 months agoMITView on GitHub

Security rules for all code in this repo. Use when handling any external input, env vars, auth, API routes, server actions, or dependencies.

  • Reads credentials

44 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use supabase-postgres-best-practices, api-and-interface-design and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • JetBrainsSkill

    supabase-postgres-best-practices

    Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.

    Also in 5 projects that use this

  • LLl0k0laDSkill

    api-and-interface-design

    Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

    Also in 5 projects that use this

  • HK-hubSkill

    code-simplification

    Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

    Also in 5 projects that use this

  • xfstudioSkill

    swiftui-expert-skill

    Write, review, or improve SwiftUI code following best practices for state management, view composition, performance, modern APIs, Swift concurrency, and iOS 26+ Liquid Glass adoption. Use when building new SwiftUI features, refactoring existing views, reviewing code quality, or adopting modern SwiftUI patterns.

    Also in 3 projects that use this

  • MicrosoftSkill

    break-ui

    Try to break a piece of UI by feeding it worst-case data — long names, unbreakable emails, one-letter names, missing fields, huge counts, zero items, long labels, non-Latin text, emoji, extreme numbers — then render it behind a "Demo data / Worst case" toggle and report everything that broke, with the fix for each. Use when the user asks to stress-test, break, or find edge cases in a component or screen, or to "try the worst case". For visual design critique use emil-design-eng; for motion use review-animations.

    Also in 3 projects that use this

  • harrissohail6Skill

    database-design

    Database schema design and SQL best practices. Use when designing tables, writing queries, or optimizing database performance.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 5 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 43 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every external input is hostile until validated.

    line 8
  2. Distinctive:

    Never log secrets, tokens, session IDs, or personal data.

    line 30
  3. Distinctive:

    Never hardcode credentials, even "temporarily," even in tests.

    line 31
  4. Very specific:

    Add the server-only package import to modules that must never reach the client.

    line 40
  5. Very specific:

    Never use dangerouslySetInnerHTML with user-influenced content.

    line 44
  6. Distinctive:

    Use parameterized queries / an ORM — never string-build SQL.

    line 46
  7. Distinctive:

    Add a Content-Security-Policy when the app's asset sources stabilize (see SECURITY.md).

    line 52
  8. Very specific:

    Use a proven library (Auth.js, Clerk, Better Auth...) — never hand-roll sessions, password hashing, or token logic.

    line 58

“Common” is measured: kept by at least 6 in 10 of the 43 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Security Best Practices

Every external input is hostile until validated. Every secret leaks unless proven otherwise. Apply these rules to all code — they are not optional hardening for "later."

Validate at every boundary with zod

zod is installed for exactly this. Validate — don't trust — all of:

  • Server action arguments and form data
  • Route handler (route.ts) request bodies, params, and search params
  • Anything read from localStorage, cookies, or URL state
  • Third-party API responses your code consumes
  • Environment variables (parse once at startup in a src/lib/env.ts if the app grows)
const CreatePost = z.object({ title: z.string().min(1).max(200) });
const input = CreatePost.parse(await req.json()); // throws on bad input

Secrets & environment

  • Real values go in .env.local (git-ignored). Committed template is .env.example.
  • NEXT_PUBLIC_ prefix = shipped to every browser. Never prefix a secret with it.
  • Never log secrets, tokens, session IDs, or personal data.
  • Never hardcode credentials, even "temporarily," even in tests.

Server/client boundary

  • Privileged logic (DB access, API keys, price calculations, permission checks) lives in Server Components, server actions, or route handlers only.
  • Authorization is checked on the server for every request — client-side checks are UX, not security. Re-verify session/role inside every server action and route handler, not just in layout or UI code.
  • Add the server-only package import to modules that must never reach the client.

Output & injection

  • Never use dangerouslySetInnerHTML with user-influenced content; if unavoidable, sanitize with a maintained library first.
  • Use parameterized queries / an ORM — never string-build SQL.
  • Validate and allowlist URLs before redirecting or fetching them (SSRF).

Headers & platform

  • Baseline security headers are set in next.config.ts — keep them when editing config.
  • Add a Content-Security-Policy when the app's asset sources stabilize (see SECURITY.md).
  • New dependencies: prefer well-maintained, widely-used packages; check npm audit after adding. Fewer dependencies is itself a security feature.

When touching auth (future apps built on this template)

  • Use a proven library (Auth.js, Clerk, Better Auth...) — never hand-roll sessions, password hashing, or token logic.
  • Cookies: httpOnly, secure, sameSite — always.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.