agentsclimarketplace

Nextjs security

Skill FilippoDeSilva/skills/skills/nextjs/nextjs-security

Secure Next.js App Router with middleware auth, Server Action validation, CSP headers, and taint APIs. Use when adding authentication middleware, validating Server Action inputs with Zod, or preventing secret leakage to client bundles.From its SKILL.md

Install
npx -y skills add FilippoDeSilva/skills --skill nextjs-security

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

2.9 KB, 547 tokens by cl100k_base, as published. Nobody here has run it

Next.js Security

Priority: P0 (CRITICAL)

Workflow: Secure Next.js App

  1. Add auth middleware — Create middleware.ts to verify JWT/session on protected routes.
  2. Validate Server Actions — Parse all inputs with Zod schemas; call await auth() first.
  3. Set security headers — Add CSP, HSTS, X-Frame-Options in middleware response.
  4. Use server-only — Import in modules containing secrets to prevent client bundling.
  5. Taint sensitive objects — Use taintObjectReference to block server objects from reaching client.

Secure Server Action Example

See implementation examples

Implementation Guidelines

  • Next.js Middleware: Use middleware.ts for edge-side authentication, role-based access control (RBAC), and enforcing Security Headers (e.g., Content-Security-Policy (CSP), X-XSS-Protection).
  • Server Actions: Always sanitize all inputs from FormData or JSON using Zod. Perform authentication checks (await auth()) inside every action to verify caller.
  • Data Tainting: Use experimental_taint API (taintObjectReference) to ensure sensitive server objects (e.g., User with passwordHash) never leak into Client Component.
  • Route Handlers (route.ts): Implement rate limiting to prevent brute-force or DoS attacks. Verify Origin/Referer headers to mitigate CSRF (Cross-Site Request Forgery).
  • Auth Tokens: strictly use HttpOnly, Secure cookies with SameSite: 'Lax' for session management. Never store tokens in localStorage.
  • Logic Isolation: use server-only package to prevent backend-specific logic from included in client bundle.
  • Component Purity: Escape all user-provided content rendered in components. Never use dangerouslySetInnerHTML without sanitizer like DOMPurify.

Anti-Patterns

  • No leaking DB fields to client: Use DTOs; never pass raw model objects.
  • No process.env in client bundles: Mark as NEXT_PUBLIC_ only if safe to expose.
  • No unvalidated Server Action inputs: Always validate with Zod schema.
  • No auth checks in shared Layouts: Auth in layouts insecure; use Middleware.

References

What ships with it: 2 files

3.1 KB alongside SKILL.md

evals/

references/

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.