- Home
- Skills
- APIs & Backend
- Hardened API Defense Playbook
Works with the AI Agents you already use
Hardened API Defense Playbook
Lock down every API request with five enforcement gates: identity, authorization, input contracts, quotas, and safe non-leaking failures.
Free
Hardened API Defense Playbook
Example session with this skill installed
Our team ships a Node/Express B2B payments API with 14 endpoints, a React dashboard, and a partner-facing GraphQL gateway. The pen test is in three weeks and we already know invoices/:id lets a caller pass any ID. Review the routes under src/routes and src/middleware, then produce a hardening plan using the five-gate model: fix auth and refresh-token rotation, add object-level authorization middleware, strict payload schemas, and rate plus cost limits for login and exports. Show me the exact middleware code to drop in and a prioritized checklist my juniors can execute this sprint.
- Read your context and instructions
- Compiled the hardened api defense
Summary
Applied the five-gate model to the payments API (14 endpoints). Fixed an IDOR on /api/invoices/:id, replaced the 30-day JWT with 10-minute access tokens plus rotating refresh tokens, and added per-actor cost quotas on exports.
| Gate | Before | After |
|---|---|---|
| Identity | 30-day JWT, alg not pinned | 10-min HS256, issuer+audience validated, hashed refresh families |
| Authorization | Client userId trusted | Ownership/tenant middleware, deny by default |
| Input | Unbounded JSON, no schema | Zod .strict() schemas, 100 kb body cap |
| Abuse | Single global limiter | 8/min login, 120/min API, 500 cost-units/min export guard |
| Failure | Stack traces in 500s | Request-ID logs, generic code payloads, allowlisted CORS |
Next steps
- Deploy the refresh-token revocation job before the audit
- Add WAF rules for
/api/auth/*floods - Re-run the gate checklist on webhook callbacks in two weeks
Connects securely to your tools. The creator never sees your data.
About this skill
Exposed APIs are the primary vector for data breaches and resource abuse. This skill provides a systematic framework for securing REST, GraphQL, and WebSocket interfaces by implementing a five-gate defense strategy. It moves beyond basic authentication to enforce strict object-level authorization, input validation, and cost-based rate limiting.
What it does
- Identity Enforcement implements short-lived access tokens and revocable refresh token families to minimize session hijacking risks.
- Granular Authorization ensures every request is checked for ownership, tenant isolation, and functional permissions at the object level.
- Contract Validation enforces strict request schemas using tools like Zod to reject malformed payloads, unknown fields, and oversized inputs.
- Abuse Prevention applies multi-layered rate limiting based on request count and computational cost to protect against DoS and resource exhaustion.
- Secure Failure Handling standardizes error responses to prevent information leakage of stack traces or internal system architecture.
How it works
- Gate Sequencing routes every incoming request through five sequential checks: Identity, Authorization, Input Contract, Abuse Control, and Transport.
- Resource Loading uses specialized middleware to resolve resource ownership before any business logic executes.
- Cost Guarding tracks the computational weight of requests (like PDF exports or heavy searches) to apply tighter quotas on expensive operations.
- Realtime Hardening applies origin validation and message-size limits to long-lived WebSocket connections.
Frameworks & tools
The implementation logic uses Node.js, Express, and Redis. It relies on jsonwebtoken for identity, zod for schema enforcement, helmet for security headers, and rate-limit-redis for distributed abuse control.
Why this beats prompting it yourself
Generic prompts often overlook the "broken object-level authorization" (BOLA) risks that plague modern APIs. This skill provides production-ready middleware patterns that handle edge cases like refresh token rotation and GraphQL query depth that standard LLM outputs typically miss.
Use cases
- Hardening a public-facing SaaS API against automated scraping and credential stuffing.
- Implementing multi-tenant isolation for enterprise B2B applications.
- Protecting expensive AI or data-processing endpoints from budget-draining abuse.
- Preparing an API surface for professional penetration testing or SOC2 compliance.
Known limitations
This skill focuses on application-layer defenses. It does not cover infrastructure-level WAF configuration, OS-level hardening, or specific database encryption-at-rest implementations.
Code samples are Node/Express-flavored and need porting for other runtimes. It guides design and remediation; it does not scan or penetration-test a live server.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
1 use
Times used to date
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 1 month ago
- Free with an Agensi account
Permissions
File Scopes
The skill only reads your API source and writes hardened middleware or plan files locally; it needs no network access or credentials.