agentsclimarketplace

Api security

Skill LeahyCC/claude-skills/skills/api-security

OWASP API Security Top 10 (2023) with production Next.js App Router code — access control, authentication, input validation, rate limiting, security headers, data exposure, supply chain, SSRFFrom its SKILL.md

Install
npx -y skills add LeahyCC/claude-skills --skill api-security

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

One thing to look at

  • 3 stars3 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.

SKILL.md

8.8 KB, ~1.9k tokens by cl100k_base, as published. Nobody here has run it

API Security — OWASP API Security Top 10 (2023) for Next.js

Production-grade API security patterns for Next.js App Router. Covers every category in the OWASP API Security Top 10 (2023) with cross-references to the OWASP Web Top 10 (2021). Verified against the official OWASP specifications.

Architecture

Request → proxy.ts (auth gate) → Route Handler / Server Action
                                       ↓
                                  Input Validation (Zod)
                                       ↓
                                  Data Access Layer (auth + authz + DTO)
                                       ↓
                                  Database (parameterized queries)
                                       ↓
                                  Filtered Response (DTO, no raw records)

The Data Access Layer (DAL) is the central security architecture recommended by Next.js. All database access, authorization checks, and response filtering happen in one server-only module — never in components or actions directly.

Quick Reference

ResourceOWASP APIOWASP WebWhat It Covers
Access ControlAPI1, API5A01BOLA/IDOR, function-level auth, ownership checks
AuthenticationAPI2A07, A02Session management, JWT, Clerk/Auth0, proxy.ts
Input ValidationAPI3, API8A03Zod schemas, SQL injection, XSS, Server Action validation
Rate LimitingAPI4A04Per-endpoint limits, cost attacks, Upstash patterns
Security HeadersAPI8A05CSP, HSTS, CORS, Permissions-Policy, next.config
Data ExposureAPI3, API6A04DAL pattern, DTOs, error sanitization, response filtering
Supply ChainAPI9, API10A06, A08Dependencies, env vars, CI/CD, third-party APIs
SSRF & LoggingAPI7A09, A10URL validation, fetch safety, secure logging, audit trails

Decision Matrix: "Where Do I Add Security?"

LayerWhat to CheckWhy
proxy.tsAuth redirect, CSP nonce, rate limit headersFirst line — blocks unauthenticated requests early
Route Handler (route.ts)Auth + authz, input validation, CORS, CSRFPublic HTTP endpoint — treat as untrusted
Server Action ('use server')Auth + authz, input validation, return filteringAlso a public HTTP endpoint — not protected by the UI
Data Access Layer (data/*.ts)Ownership checks, field filtering, parameterized queriesLast line — defense in depth
next.config.tsSecurity headers, redirects, allowed image domainsStatic security baseline

The #1 Mistake: Server Actions Are Public Endpoints

Every exported 'use server' function is reachable via direct POST request. Page-level auth does NOT protect actions on that page.

// FAIL — no auth check, anyone can call this via POST
'use server'
export async function deleteAccount(userId: string) {
  await db.delete(users).where(eq(users.id, userId))
}

// PASS — validates auth AND ownership inside the action
'use server'
import { getCurrentUser } from '@/data/auth'

export async function deleteAccount() {
  const user = await getCurrentUser()
  if (!user) throw new Error('Unauthorized')
  await db.delete(users).where(eq(users.id, user.id))
}

Notice: the PASS version doesn't accept userId as a parameter — it derives it from the session. This prevents IDOR (Insecure Direct Object Reference).

Decision Matrix: "Is This Secure?"

QuestionIf No →Resource
Does every Server Action re-verify auth?Add getCurrentUser() checkAccess Control
Does every Route Handler validate input with Zod?Add schema validationInput Validation
Are database queries parameterized?Use tagged templates or ORMInput Validation
Does the response return only needed fields?Add DTO layerData Exposure
Are rate limits in place for auth endpoints?Add Upstash/ArcjetRate Limiting
Are security headers configured?Add to next.config.tsSecurity Headers
Is proxy.ts checking auth before page access?Add auth middlewareAuthentication
Are env vars only accessed in the DAL?Move to server-only moduleSupply Chain
Does fetch() in server code validate URLs?Add URL allowlistSSRF & Logging
Are errors sanitized before returning to client?Return generic messagesData Exposure

OWASP API Security Top 10 (2023) — Full Mapping

#CategorySeverityResource
API1Broken Object Level Authorization (BOLA)Criticalaccess-control
API2Broken AuthenticationCriticalauthentication
API3Broken Object Property Level AuthorizationHighinput-validation, data-exposure
API4Unrestricted Resource ConsumptionHighrate-limiting
API5Broken Function Level AuthorizationCriticalaccess-control
API6Unrestricted Access to Sensitive Business FlowsMediumdata-exposure
API7Server Side Request ForgeryHighssrf-and-logging
API8Security MisconfigurationMediumsecurity-headers, input-validation
API9Improper Inventory ManagementMediumsupply-chain
API10Unsafe Consumption of APIsMediumsupply-chain

OWASP Web Top 10 (2021) — Cross-Reference

#CategoryMapped To
A01Broken Access Controlaccess-control
A02Cryptographic Failuresauthentication
A03Injectioninput-validation
A04Insecure Designrate-limiting, data-exposure
A05Security Misconfigurationsecurity-headers
A06Vulnerable & Outdated Componentssupply-chain
A07Auth Failuresauthentication
A08Software & Data Integrity Failuressupply-chain
A09Logging & Monitoring Failuresssrf-and-logging
A10SSRFssrf-and-logging

Code Review Checklist

When reviewing API code in Next.js, verify:

  • Every 'use server' function checks auth — no exceptions
  • No user-supplied IDs used for ownership — derive from session
  • All inputs validated with Zod before use
  • Database queries use parameterized queries or ORM
  • Responses return DTOs, not raw database records
  • Error messages don't leak stack traces, SQL, or internal paths
  • Security headers set in next.config.ts (CSP, HSTS, X-Frame-Options)
  • Rate limiting on auth endpoints and expensive operations
  • proxy.ts gates auth before page/action access
  • Environment variables accessed only in server-only modules
  • No fetch() to user-controlled URLs without allowlist
  • Dependencies audited — no known vulnerabilities
  • .env*.local in .gitignore

What ships with it: 9 files

83.5 KB alongside SKILL.md

Gives 2 of the 12 instructions most security skills give in ~1.9k tokens

Counted across 666 of the 889 authors here whose files we hold, read 2026-09-06

  • Use parameterized queries for database accesshere, and in 82 of 666, across 79 files
  • Hash passwords with BCryptin 55 of 666, across 39 files
  • Implement rate limiting for public endpointshere, and in 48 of 666, across 34 files
  • Use environment variables for secretsin 35 of 666
  • Scan dependencies for vulnerabilitiesin 35 of 666, across 24 files
  • Validate and sanitize all user inputin 35 of 666, across 32 files
  • Add security headers to all responsesin 34 of 666, across 20 files
  • Validate all external input at the system boundaryin 26 of 666, across 25 files
  • Use parameterized queries to prevent SQL injectionin 25 of 666, across 13 files
  • Store secrets in Vault or environment variablesin 25 of 666, across 10 files
  • Run containers as a non-root userin 21 of 666, across 18 files
  • Validate all input using Bean Validationin 19 of 666, across 5 files

Said here and by no other author read

  • Derive user IDs from session instead of parameters
  • Filter responses using data transfer objects
  • Sanitize error messages before returning to client
  • Gate page access using authentication middleware
  • Access environment variables only in server-only modules

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.

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.