cors--csp-headers-hardenerlisted
Install: claude install-skill RMAzrim/opencode-artes
# CORS & CSP Headers Hardener
## 1. System Architecture & Prerequisites
- Python 3.10+ (stdlib only: `json`, `argparse`, `urllib.request`, `urllib.error`, `pathlib`)
- Target: a running local HTTP server reachable at `--url` (e.g. `http://127.0.0.1:3000`)
- No external `requests` dependency — `urllib.request` performs the header reconnaissance
- Output guards: hardened Node/Express `helmet` middleware and Python/FastAPI middleware variants
## 2. Input/Output Data Contracts
**Input (CLI args):**
```json
{
"type": "object",
"properties": {
"url": { "type": "string", "description": "Base URL of local web server, e.g. http://127.0.0.1:3000" },
"report_dir": { "type": "string", "description": "Output directory", "default": "./header-reports" },
"write_guards": { "type": "boolean", "description": "Emit hardened middleware files", "default": false }
},
"required": ["url"]
}
```
**Output artifacts:**
- `{report_dir}/headers_report.json` — collected headers + findings for each endpoint
- `{report_dir}/strict_csp.txt` — strict CSP policy string
- `{report_dir}/helmet_hardened.js` — Node helmet + CORS allowlist middleware
- `{report_dir}/fastapi_hardened.py` — FastAPI CORSMiddleware + SecurityHeaders middleware
## 3. Production Reference Implementation
```python
#!/usr/bin/env python3
"""CORS & CSP Headers Hardener — header reconnaissance, gap analysis, hardened middleware generation."""
import re
import json
import argparse
import urllib.request
import urllib