API Security Hardening

API Security Hardening

Guides a coding agent to harden REST APIs with authentication, rate limiting, CORS, input validation and security middleware in Node.js/Express and FastAPI.

Skill files5 files

references/

scripts/

SKILL.md96 lines
1
---
2
name: api-security-hardening
3
description: >
4
Secure REST APIs with authentication, rate limiting, CORS, input validation,
5
and security middleware. Use when building or hardening API endpoints against
6
common attacks.
7
---
8
9
# API Security Hardening
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement comprehensive API security measures including authentication, authorization, rate limiting, input validation, and attack prevention to protect against common vulnerabilities.
22
23
## When to Use
24
25
- New API development
26
- Security audit remediation
27
- Production API hardening
28
- Compliance requirements
29
- High-traffic API protection
30
- Public API exposure
31
32
## Quick Start
33
34
Minimal working example:
35
36
```javascript
37
// secure-api.js - Comprehensive API security
38
const express = require("express");
39
const helmet = require("helmet");
40
const rateLimit = require("express-rate-limit");
41
const mongoSanitize = require("express-mongo-sanitize");
42
const xss = require("xss-clean");
43
const hpp = require("hpp");
44
const cors = require("cors");
45
const jwt = require("jsonwebtoken");
46
const validator = require("validator");
47
48
class SecureAPIServer {
49
constructor() {
50
this.app = express();
51
this.setupSecurityMiddleware();
52
this.setupRoutes();
53
}
54
55
setupSecurityMiddleware() {
56
// 1. Helmet - Set security headers
57
this.app.use(
58
helmet({
59
contentSecurityPolicy: {
60
directives: {
61
defaultSrc: ["'self'"],
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [Node.js/Express API Security](references/nodejsexpress-api-security.md) | Node.js/Express API Security |
72
| [Python FastAPI Security](references/python-fastapi-security.md) | Python FastAPI Security |
73
| [API Gateway Security Configuration](references/api-gateway-security-configuration.md) | API Gateway Security Configuration |
74
75
## Best Practices
76
77
### ✅ DO
78
79
- Use HTTPS everywhere
80
- Implement rate limiting
81
- Validate all inputs
82
- Use security headers
83
- Log security events
84
- Implement CORS properly
85
- Use strong authentication
86
- Version your APIs
87
88
### ❌ DON'T
89
90
- Expose stack traces
91
- Return detailed errors
92
- Trust user input
93
- Use HTTP for APIs
94
- Skip input validation
95
- Ignore rate limiting
96

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…