Skip to main content
skill CX Codex

api-security-hardening — Claude Code skill: REST API protection

Skill adds authentication, rate limiting, CORS, input validation and security headers to REST API endpoints.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a claude-code
Open on GitHub

What 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 email field if it fails validator.isEmail

How to install api-security-hardening

1Skills CLI (Vercel)

npx skills add aj-geddes/useful-ai-prompts --skill api-security-hardening -a claude-code

2Manually: put the files in place

~/.claude/skills/api-security-hardening/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/api-security-hardening/

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

Similar skills

All skills for Backend and APIs →

From the same set143

css-architecture A skill that gives your coding agent conventions for structuring CSS with BEM, SMACSS and CSS-in-JS. Handy when stylesheets outgrow the naming scheme you started with. CX Codex +1 959installs api-contract-testing Verifies API contracts between consumers and providers without full integration tests. Helps stop breaking schema changes before deploying microservices. CX Codex +1 913installs event-sourcing A skill that guides your coding agent through event sourcing and CQRS: an event store, aggregates, projections and snapshots. Useful when you need a full change history and queries against past state. CX Codex +1 886installs root-cause-analysis A skill that walks an incident down to the cause you can actually fix, instead of patching the symptom again. CX Codex +1 884installs mobile-first-design A skill that sets the order of UI work: design the phone screen first, then scale to tablet and desktop. Useful when layouts break on small devices. CX Codex +1 857installs mobile-app-testing Provides testing guidelines for iOS and Android apps. Covers unit, UI, and performance tests using Jest, Detox, Espresso, and XCTest. CX Codex +1 823installs technical-specification Gives your agent a structure for technical specs, PRDs, ADRs and RFCs: requirements, architecture, acceptance criteria. Useful before you start coding a feature. CX Codex +1 804installs user-story-writing Structures product requirements into user stories with Given-When-Then acceptance criteria. Helps during sprint planning and backlog refinement. CX Codex +1 787installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor