Skip to main content
skill CX Codex

api-security-hardening · secondsky — Claude Code skill: how to install

Security layers for a REST API on Express: rate limits and input validation. Useful before the API goes to production.

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

What api-security-hardening does

This skill gives the agent a ready layout for locking down a REST API built on Express. It wires in helmet and express-mongo-sanitize, then adds two express-rate-limit rules: 100 requests per 15 minutes on /api/, and a tighter 5 on /api/auth/. A validation sample with express-validator checks emails, requires passwords of at least 8 characters with an uppercase letter and a digit, and caps names at 100.

There is also a block of response headers (Content-Security-Policy, X-Frame-Options, Strict-Transport-Security) and a checklist that covers HTTPS, CORS origins and hiding stack traces in production. Python users get references/python-nginx.md with FastAPI, Pydantic and Nginx setup.

XSS cleanup isn't part of this skill. xss-clean is abandoned, so it points you to xss-prevention instead. Also, express-validator v7+ dropped .escape(), and the sample works around that with a customSanitizer built on escape-html.

What it helps with

  • rate-limit /api/ and throttle /api/auth/ harder
  • validate email and password on POST /users with express-validator
  • set Content-Security-Policy and HSTS headers
  • walk an API through a checklist before production
  • harden a FastAPI service using the pattern in references/python-nginx.md

Example prompts for the agent

  • Run my Express API through api-security-hardening and add helmet plus rate limits
  • Use api-security-hardening to set up validation on POST /users and security headers
  • Check this API against the api-security-hardening checklist before release

How to install api-security-hardening

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --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 do I install api-security-hardening in Claude Code?

Run npx skills add secondsky/claude-skills --skill api-security-hardening -a claude-code. The skill file sits at ~/.claude/skills/api-security-hardening/SKILL.md.

What does api-security-hardening do?

It hands the agent a protection plan for an Express REST API: helmet, rate limits and express-validator checks. Security headers and a release checklist come with it.

Why does api-security-hardening skip xss-clean?

The xss-clean package is abandoned, so the skill avoids it. For input sanitizing it refers you to the xss-prevention skill.

Source text

SKILL.md · MIT
---
name: api-security-hardening
description: REST API security hardening with authentication, rate limiting, input validation, security headers. Use for production APIs, security audits, defense-in-depth, or encountering vulnerabilities, injection attacks, CORS issues.
license: MIT
---

# API Security Hardening

Protect REST APIs against common vulnerabilities with multiple security layers.

## Security Middleware Stack (Express)

```javascript
const helmet = require('helmet');
const rateLimit = require('express-rate-limit');
const mongoSanitize = require('express-mongo-sanitize');

app.use(helmet());
app.use(mongoSanitize());
// For input sanitization, see the `xss-prevention` skill — do NOT use the
// deprecated `xss-clean` package (unmaintained since 2018; its own README
// recommends migrating off it).

app.use('/api/', rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 100
}));

app.use('/api/auth/', rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 5
}));
```

## Input Validation

```javascript
const { body, validationResult } = require('express-validator');
const escapeHtml = require('escape-html');

app.post('/users',
  body('email').isEmail().normalizeEmail(),
  body('password').isLength({ min: 8 }).matches(/[A-Z]/).matches(/[0-9]/),
  // express-validator v7+ removed the built-in .escape() sanitizer; use a
  // customSanitizer backed by `escape-html` to HTML-escape the value.
  body('name').trim().isLength({ max: 100 }).customSanitizer(v => escapeHtml(v)),
  (req, res) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.status(400).json({ errors: errors.array() });
    }
    // Process request
  }
);
```

## Security Headers

```javascript
app.use((req, res, next) => {
  res.setHeader('Content-Security-Policy', "default-src 'self'");
  res.setHeader('X-Frame-Options', 'DENY');
  res.setHeader('X-Content-Type-Options', 'nosniff');
  res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
  res.setHeader('X-XSS-Protection', '1; mode=block');
  next();
});
```

## Security Checklist

- [ ] HTTPS everywhere
- [ ] Authentication on all protected routes
- [ ] Input validation and sanitization
- [ ] Rate limiting enabled
- [ ] Security headers configured
- [ ] CORS restricted to allowed origins
- [ ] No stack traces in production errors
- [ ] Audit logging enabled
- [ ] Dependencies regularly updated

## Additional Implementations

See [references/python-nginx.md](references/python-nginx.md) for:
- Python FastAPI security middleware
- Pydantic input validation with password rules
- Nginx SSL/TLS and security headers configuration
- HTTP Parameter Pollution prevention

## Never Do

- Trust user input without validation
- Return detailed errors in production
- Store secrets in code
- Use GET for state-changing operations
- Disable security for convenience

© secondsky · MIT · secondsky/claude-skills

Similar skills

All skills for Security →

api-security-hardening by other authors comes first.

From the same set116

bun-sqlite A skill that tells your agent how to write bun:sqlite code: queries, prepared statements, transactions and parameters. CX Codex +1 495installs architecture-patterns A skill that gives your agent backend architecture templates: Clean Architecture layers, ports and adapters, and Domain-Driven Design building blocks. CX Codex +1 493installs api-rate-limiting A skill that walks you through rate limiting an API with token bucket, sliding window and Redis-backed counters. Useful when you open an endpoint to the public or split access by plan. CX Codex +1 491installs better-auth Guides Better Auth setup across TypeScript stacks, Cloudflare D1, and Drizzle ORM. Prevents broken adapter imports and schema migration bugs. CX Codex +1 488installs react-composition-patterns Teaches coding agents clean React composition patterns. Replaces boolean prop clutter with compound components and decoupled context providers. CX Codex +1 481installs design-system-creation A skill that walks the agent through building a design system: tokens, typography, components and their docs. Useful when UI standards need to be settled before code. CX Codex +1 481installs api-contract-testing Verifies API contracts between microservices with consumer-driven tests and OpenAPI schemas, skipping full end-to-end setups. CX Codex +1 475installs technical-specification This skill walks the agent through a technical spec template: requirements, architecture, API design, rollout plan, tests and risks. Useful before a feature turns into code. CX Codex +1 470installs

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