api-security-hardening — Claude Code skill: REST API protection
Skill adds authentication, rate limiting, CORS, input validation and security headers to REST API endpoints.
npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a claude-codeWhat api-security-hardening does
Skill builds defences against injections, XSS, brute-force and stack leaks into the API layer. Agent sets up Helmet for headers, express-rate-limit for throttling, validator for input params, JWT middleware and CORS policy. Inside: working examples for Node.js/Express, Python FastAPI and API Gateway config.
Logs security events, versions endpoints and sanitises MongoDB queries via express-mongo-sanitize. Requires helmet, express-rate-limit, validator, jsonwebtoken and cors installed in the project.
Covers both greenfield APIs and production audits: agent applies an eight-point checklist (HTTPS, validation, rate limiting, headers) and strips stack traces from error responses.
What it helps with
- Block SQL injection and XSS in API routes
- Add throttling to prevent credential stuffing
- Set up JWT auth and CORS policy
- Prepare endpoints for compliance audit
- Hide error details and stack traces in production
Example prompts for the agent
- Add rate limiting to
/api/users: 100 requests per minute, JWT required - Set CORS for
api.example.com, allow GET and POST only - Reject
emailfield if it failsvalidator.isEmail
How to install api-security-hardening
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a claude-code2Manually: put the files in place
~/.claude/skills/api-security-hardening/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/api-security-hardening/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a codex2Manually: put the files in place
.agents/skills/api-security-hardening/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a cursor2Manually: put the files in place
.cursor/skills/api-security-hardening/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install aj-geddes/useful-ai-prompts api-security-hardening2Manually: put the files in place
.github/skills/api-security-hardening/SKILL.md1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a gemini-cli2Platform CLI
gemini skills install https://github.com/aj-geddes/useful-ai-prompts --path skills/api-security-hardeningManually: put the files in place
.devin/skills/api-security-hardening/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about api-security-hardening
How to install api-security-hardening in Claude Code?
Run npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a claude-code, the skill lands in ~/.claude/skills/api-security-hardening/SKILL.md.
What does api-security-hardening do?
Skill hardens REST APIs with rate limiting, input validation, Helmet headers, CORS, JWT authentication and query sanitisation. Agent applies an eight-point security checklist and closes common vulnerabilities.
Which libraries does the skill need?
Project must have helmet, express-rate-limit, validator, jsonwebtoken, cors, express-mongo-sanitize, xss-clean and hpp installed. Middleware will not start without them.
Source text
SKILL.md · MIT
---
name: api-security-hardening
description: >
Secure REST APIs with authentication, rate limiting, CORS, input validation,
and security middleware. Use when building or hardening API endpoints against
common attacks.
---
# API Security Hardening
## Table of Contents
- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)
## Overview
Implement comprehensive API security measures including authentication, authorization, rate limiting, input validation, and attack prevention to protect against common vulnerabilities.
## When to Use
- New API development
- Security audit remediation
- Production API hardening
- Compliance requirements
- High-traffic API protection
- Public API exposure
## Quick Start
Minimal working example:
```javascript
// secure-api.js - Comprehensive API security
const express = require("express");
const helmet = require("helmet");
const rateLimit = require("express-rate-limit");
const mongoSanitize = require("express-mongo-sanitize");
const xss = require("xss-clean");
const hpp = require("hpp");
const cors = require("cors");
const jwt = require("jsonwebtoken");
const validator = require("validator");
class SecureAPIServer {
constructor() {
this.app = express();
this.setupSecurityMiddleware();
this.setupRoutes();
}
setupSecurityMiddleware() {
// 1. Helmet - Set security headers
this.app.use(
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
// ... (see reference guides for full implementation)
```
## Reference Guides
Detailed implementations in the `references/` directory:
| Guide | Contents |
|---|---|
| [Node.js/Express API Security](references/nodejsexpress-api-security.md) | Node.js/Express API Security |
| [Python FastAPI Security](references/python-fastapi-security.md) | Python FastAPI Security |
| [API Gateway Security Configuration](references/api-gateway-security-configuration.md) | API Gateway Security Configuration |
## Best Practices
### ✅ DO
- Use HTTPS everywhere
- Implement rate limiting
- Validate all inputs
- Use security headers
- Log security events
- Implement CORS properly
- Use strong authentication
- Version your APIs
### ❌ DON'T
- Expose stack traces
- Return detailed errors
- Trust user input
- Use HTTP for APIs
- Skip input validation
- Ignore rate limiting
© aj-geddes · MIT · aj-geddes/useful-ai-prompts