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.
npx skills add secondsky/claude-skills --skill api-security-hardening -a claude-codeWhat 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 /userswithexpress-validator - set
Content-Security-Policyand 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
helmetplus rate limits - Use api-security-hardening to set up validation on
POST /usersand 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-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 secondsky/claude-skills --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 secondsky/claude-skills --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 secondsky/claude-skills api-security-hardening2Manually: put the files in place
.github/skills/api-security-hardening/SKILL.md1Skills CLI (Vercel)
npx skills add secondsky/claude-skills --skill api-security-hardening -a gemini-cli2Platform CLI
gemini skills install https://github.com/secondsky/claude-skills --path plugins/api-security-hardening/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 secondsky/claude-skills --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 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.