nextjs-security — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited nextjs-security (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Apply these security standards to every Next.js application. Security is a multi-layered concern spanning the client, server, and network boundaries. Every Server Action and Route Handler is a public endpoint — treat all input as hostile.
Defense in Depth: Never rely on a single security boundary. Middleware can be bypassed (CVE-2025-29927). Client-side checks can be spoofed. Every layer must independently verify authentication, authorization, and input validity.
Every Server Action and Route Handler must implement all five layers:
Verify the user is logged in. Use cookies() to read session tokens set as httpOnly, Secure, SameSite=Lax (or Strict) cookies. Never store tokens in localStorage.
Never trust client input. Validate and parse with Zod or Valibot using safeParse(). Reject invalid input before any database operation.
Verify the authenticated user has permission to access or mutate the specific resource. Prevents Insecure Direct Object Reference (IDOR) attacks.
Protect against brute-force and DDoS using tools like @upstash/ratelimit. Apply per-user and per-IP limits.
Catch errors gracefully. Return generic messages to the client. Never expose backend stack traces, database errors, or internal paths.
'use server';
import { z } from 'zod';
import { verifyAuth } from '@/lib/auth';
const schema = z.object({
amount: z.number().positive().max(10000),
userId: z.string().uuid(),
});
export async function createTransaction(data: unknown) {
const session = await verifyAuth(); // 1. Auth
if (!session) throw new Error('Unauthorized');
const parsed = schema.safeParse(data); // 2. Validate
if (!parsed.success) throw new Error('Invalid input');
if (session.user.id !== parsed.data.userId) // 3. Authorize
throw new Error('Forbidden');
// 4. Rate limit (await rateLimit(session.user.id))
try {
// Database operation
return { success: true };
} catch (error) {
console.error('Server error:', error); // 5. Safe errors
throw new Error('An internal error occurred');
}
}Secure, SameSite=Lax (or Strict). Never localStorage.server-only PackageMark any module containing database queries, API keys, or sensitive logic with import 'server-only'. The build fails immediately if accidentally imported into a Client Component.
Centralize all database queries in a dedicated server-only DAL that:
React.cache() for deduplicationprocess.env access to this layer onlyUse taintObjectReference or taintUniqueValue to mark sensitive data. Next.js throws an error if tainted data crosses the Server→Client boundary. Check current API status in Next.js docs — these APIs may still be experimental in some versions.
Origin vs. Host headers and abort on mismatch.serverActions.allowedOrigins in next.config.ts.SameSite=Lax/Strict and consider third-party CSRF tokens (@edge-csrf/nextjs).DOMPurify or isomorphic-dompurify first.returnTo parameters.Apply these headers via next.config.ts headers() or middleware/proxy:
| Header | Value | Purpose |
|---|---|---|
Content-Security-Policy | default-src 'self'; script-src 'self' 'nonce-...' 'strict-dynamic' | Prevents unauthorized script execution |
X-Frame-Options | DENY | Prevents clickjacking |
X-Content-Type-Options | nosniff | Prevents MIME-sniffing |
Strict-Transport-Security | max-age=63072000; includeSubDomains; preload | Enforces HTTPS |
Referrer-Policy | strict-origin-when-cross-origin | Controls referrer leakage |
.env and .env.local from version control. Use secret managers for production (AWS Secrets Manager, Vault, Vercel Env Vars).process.env access to the DAL to prevent accidental frontend leakage.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY to prevent cross-instance request failures.Critical: Do not treat middleware (or proxy.ts in Next.js 16) as the sole security boundary. CVE-2025-29927 demonstrated that attackers could spoof headers to bypass middleware authorization entirely.
Always re-verify auth inside:
Middleware is appropriate for edge-level routing, header injection, and redirects — not for complete access control.
For the complete pre-deployment security audit checklist with code examples:
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.