
Api Security Hardening
Harden Express-style REST APIs with helmet, JWT auth, rate limits, CORS, and input sanitization before or right after exposing endpoints publicly.
Install
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill api-security-hardeningWhat is this skill?
- Express SecureAPIServer scaffold with layered security middleware
- Helmet security headers, express-rate-limit, and CORS configuration
- mongo-sanitize, xss-clean, and hpp for injection and parameter pollution
- JWT-based authentication patterns in the quick-start flow
- Validator-based input checks aligned to common REST abuse cases
Adoption & trust: 669 installs on skills.sh; 250 GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Azure Compliancemicrosoft/azure-skills
Openclaw Secure Linux Cloudxixu-me/skills
Entra Agent Idmicrosoft/azure-skills
Firebase Security Rules Auditorfirebase/agent-skills
Firestore Security Rules Auditorfirebase/agent-skills
Skill Vetteruseai-pro/openclaw-skills-security
Journey fit
Common Questions / FAQ
Is Api Security Hardening safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Api Security Hardening
# 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 #!/bin/bash # security-checklist.sh - Generate a security review checklist # Usage: ./security-checklist.sh [--output checklist.md] set -euo pipefail OUTPUT="${{1:-/dev/stdout}}" cat > "$OUTPUT" << 'CHECKLIST' # Security Review Checklist ## Authentication & Authorization - [ ] All endpoints require authentication - [ ] Role-based access control implemented - [ ] Session management is secure ## Input Validation - [ ] All user inputs are validated - [ ] SQL injection prevention - [ ] XSS prevention ## Data Protection - [ ] Sensitive data encrypted at rest - [ ] Sensitive data encrypted in transit - [ ] PII handling compliant ## TODO: Add domain-specific security checks CHECKLIST echo "Checklist generated: $OUTPUT" >&2 # API Gateway Security Configuration ## API Gateway Security Configuration ```yaml # nginx-api-gateway.conf # Nginx API Gateway with security hardening http { # Security headers add_header X-Frame-Options "DENY" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header Content-Security-Policy "default-src 'self'" always; # Rate limiting zones limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s; limit_req_zone $binary_remote_addr zone=auth_limit:10m rate=1r/s; limit_conn_zone $binary_remote_addr zone=conn_limit:10m; # Request body size limit client_max_body_size 10M; client_body_buff