api-security-best-practices

Implement authentication, input validation, and rate limiting for REST, GraphQL, and WebSocket APIs.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/AdityaBorkar/igbot-fork --skill api-security-best-practices-adityaborkar
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: api-security-best-practices
Source: https://github.com/AdityaBorkar/igbot-fork/tree/main/.agents/skills/api-security-best-practices
Command: npx skills add https://github.com/AdityaBorkar/igbot-fork --skill api-security-best-practices-adityaborkar

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? APIs are frequent targets for injection attacks, brute force attempts, and unauthorized access, and developers often ship endpoints without proper authentication, validation, or rate limiting. This Skill provides concrete implementation patterns and checklists to secure APIs against the OWASP API Security Top 10. ## Core Features & Use Cases - Authentication & Authorization: Implement JWT-based auth with refresh tokens, RBAC, and per-resource authorization checks. - Input Validation & Injection Prevention: Use parameterized queries, Zod schema validation, and output sanitization to block SQL injection and XSS. - Rate Limiting & DDoS Protection: Configure per-user and per-IP rate limits with Redis-backed stores and security headers via Helmet. - Use Case: When building a new Express endpoint that handles user data, apply the provided JWT middleware, request validation schema, and tiered rate limiter to ship a hardened route. ## Quick Start Ask the AI to review your API endpoint code and apply secure authentication, input validation, and rate limiting patterns.

Frequently Asked Questions about api-security-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement JWT authentication in an Express API?▼

Generate a signed JWT on login with a short expiration, then verify it in middleware using the Authorization Bearer header. Store refresh tokens in a database so they can be revoked, and validate the token issuer and audience claims.

How to prevent SQL injection in Node.js APIs?▼

Use parameterized queries or an ORM like Prisma instead of string concatenation in SQL statements. Validate input types and formats first, for example checking that an ID parameter matches expected numeric patterns before querying.

What rate limiting strategy works for login endpoints?▼

Apply a strict limiter such as 5 attempts per 15 minutes on authentication routes, skipping successful requests so legitimate users are not penalized. Use a Redis store so limits persist across multiple server instances.

Does this guidance cover GraphQL and WebSocket APIs?▼

Yes, the security patterns apply to REST, GraphQL, and WebSocket APIs. Core controls like authentication, input validation, rate limiting, and secure error handling are protocol-agnostic, though implementation details differ per framework.

Why should error messages be sanitized in API responses?▼

Verbose errors leak internal details like database constraints, stack traces, and schema names that attackers use for reconnaissance. Return generic client-facing messages while logging full error details server-side for debugging.

What are the limitations of storing data in JWT payloads?▼

JWT payloads are base64-encoded, not encrypted, so anyone holding the token can read its contents. Never store passwords or sensitive data in the payload, and keep tokens short-lived since they cannot be individually revoked without a blacklist.