agentleFS
LeahyCCLeahyCC/claude-skills/skills/api-security/SKILL.md

api-security

Skill3 starsChanged 8 months agoMITView on GitHub

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, SSRF

  • Reads credentials

24 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use src-hunter, database-security 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.
  • xAmirHamza77Skill

    src-hunter

    实战 SRC / 众测 / Bug bounty vulnerability挖掘工作流 skill。包含:5 phasemethodology(intake → recon → enum → hunt → report)、19 个攻击类 playbook(SQLi/XSS/RCE/SSRF/IDOR/CSRF/Path Traversal/File Upload/SSTI/XXE/Race/HTTP Smuggling/OAuth/JWT/SAML/GraphQL/Mobile/LLM/DoS)、305 个结构化 payload、263 个 WAF/EDR bypass变体、2887 份 HackerOne 真实 High/Critical 已披露案例、77,000+ WooYun 案例统计、国产 OA / 中间件指纹库、银行 / 电信行业垂直 playbook。当用户提到 "src 挖洞 / src vulnerability挖掘 / bug bounty / 众测 / hackerone / vulnerability赏金 / SRC / 任意 X vulnerability / penetration testing" 或问"如何挖某个target / 怎么测某个 API / 如何bypass WAF" 时触发。

    Also in 5 projects that use this

  • JeremyMorganSkill

    database-security

    Examines all database interactions for injection, access control, encryption, and data-exposure risks. Use when auditing database and data-layer security.

    Also in 5 projects that use this

  • xAmirHamza77Skill

    attack-chain

    Use for authorized multi-stage attack-path planning and orchestration when a task spans reconnaissance, initial access, privilege escalation, lateral movement, or impact assessment. Route single-stage tasks directly to their specialist skill.

    Also in 4 projects that use this

  • +9 more from xAmirHamza77

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every exported 'use server' function is reachable via direct POST request.

    line 82
  2. Very specific:

    When reviewing API code in Next.js, verify:

    line 151

“Common” is measured: kept by at least 6 in 10 of the 17 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

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

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.