Security Infrastructure Skill
Infrastructure security, headers, encryption, and compliance patterns.
Quick Reference
Security Headers
| Header |
Purpose |
Value |
| Content-Security-Policy |
XSS prevention |
Restrict sources |
| X-Frame-Options |
Clickjacking |
DENY |
| Strict-Transport-Security |
Force HTTPS |
max-age=31536000 |
| X-Content-Type-Options |
MIME sniffing |
nosniff |
| Referrer-Policy |
Leak prevention |
strict-origin |
Helmet.js Configuration
import helmet from 'helmet';
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],
imgSrc: ["'self'", "data:", "https:"],
objectSrc: ["'none'"],
frameAncestors: ["'none'"],
},
},
hsts: { maxAge: 31536000, includeSubDomains: true },
}));
Encryption (AES-256-GCM)
import crypto from 'crypto';
function encrypt(plaintext: string, key: Buffer): EncryptedData {
const iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
let ciphertext = cipher.update(plaintext, 'utf8', 'base64');
ciphertext += cipher.final('base64');
return {
ciphertext,
iv: iv.toString('base64'),
authTag: cipher.getAuthTag().toString('base64'),
};
}
function decrypt(data: EncryptedData, key: Buffer): string {
const decipher = crypto.createDecipheriv(
'aes-256-gcm',
key,
Buffer.from(data.iv, 'base64')
);
decipher.setAuthTag(Buffer.from(data.authTag, 'base64'));
let plaintext = decipher.update(data.ciphertext, 'base64', 'utf8');
plaintext += decipher.final('utf8');
return plaintext;
}
Secrets Management
// Environment variables (basic)
const apiKey = process.env.API_KEY;
// AWS Secrets Manager
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
const client = new SecretsManager({ region: 'us-east-1' });
const secret = await client.getSecretValue({ SecretId: 'my-secret' });
// HashiCorp Vault
import Vault from 'node-vault';
const vault = Vault({ endpoint: process.env.VAULT_ADDR });
const { data } = await vault.read('secret/data/myapp');
CORS Configuration
import cors from 'cors';
app.use(cors({
origin: ['https://app.example.com'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization'],
credentials: true,
maxAge: 86400,
}));
Compliance Checklist
GDPR Requirements
PCI-DSS Requirements
F5 Quality Gates
| Gate |
Requirement |
| G4 |
Security audit completed |
| G5 |
Production hardening verified |
| G5 |
Compliance checklist passed |
1---
2name: security-infra
3version: "1.0.0"
4description: |
5 Infrastructure security, headers, encryption, and compliance.
6
7 Use when: (1) Configuring security headers (CSP, CORS, HSTS),
8 (2) Setting up HTTPS/TLS, (3) Data encryption at rest/transit,
9 (4) Implementing compliance (GDPR, PCI-DSS), (5) Secrets management.
10
11 Auto-detects: helmet, csp, cors, hsts, https, tls, ssl, encrypt,
12 gdpr, pci-dss, compliance, secret, vault, kms
13related:
14 - security
15 - security-auth
16 - devops
17metadata:
18 source: https://skillmd.com/skills/aibot88/security-infra
19---
20
21# Security Infrastructure Skill
22
23Infrastructure security, headers, encryption, and compliance patterns.
24
25## Quick Reference
26
27### Security Headers
28
29| Header | Purpose | Value |
30|--------|---------|-------|
31| Content-Security-Policy | XSS prevention | Restrict sources |
32| X-Frame-Options | Clickjacking | DENY |
33| Strict-Transport-Security | Force HTTPS | max-age=31536000 |
34| X-Content-Type-Options | MIME sniffing | nosniff |
35| Referrer-Policy | Leak prevention | strict-origin |
36
37## Helmet.js Configuration
38
39```typescript
40import helmet from 'helmet';
41
42app.use(helmet({
43 contentSecurityPolicy: {
44 directives: {
45 defaultSrc: ["'self'"],
46 scriptSrc: ["'self'"],
47 styleSrc: ["'self'", "'unsafe-inline'"],
48 imgSrc: ["'self'", "data:", "https:"],
49 objectSrc: ["'none'"],
50 frameAncestors: ["'none'"],
51 },
52 },
53 hsts: { maxAge: 31536000, includeSubDomains: true },
54}));
55```
56
57## Encryption (AES-256-GCM)
58
59```typescript
60import crypto from 'crypto';
61
62function encrypt(plaintext: string, key: Buffer): EncryptedData {
63 const iv = crypto.randomBytes(12);
64 const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
65
66 let ciphertext = cipher.update(plaintext, 'utf8', 'base64');
67 ciphertext += cipher.final('base64');
68
69 return {
70 ciphertext,
71 iv: iv.toString('base64'),
72 authTag: cipher.getAuthTag().toString('base64'),
73 };
74}
75
76function decrypt(data: EncryptedData, key: Buffer): string {
77 const decipher = crypto.createDecipheriv(
78 'aes-256-gcm',
79 key,
80 Buffer.from(data.iv, 'base64')
81 );
82 decipher.setAuthTag(Buffer.from(data.authTag, 'base64'));
83
84 let plaintext = decipher.update(data.ciphertext, 'base64', 'utf8');
85 plaintext += decipher.final('utf8');
86
87 return plaintext;
88}
89```
90
91## Secrets Management
92
93```typescript
94// Environment variables (basic)
95const apiKey = process.env.API_KEY;
96
97// AWS Secrets Manager
98import { SecretsManager } from '@aws-sdk/client-secrets-manager';
99const client = new SecretsManager({ region: 'us-east-1' });
100const secret = await client.getSecretValue({ SecretId: 'my-secret' });
101
102// HashiCorp Vault
103import Vault from 'node-vault';
104const vault = Vault({ endpoint: process.env.VAULT_ADDR });
105const { data } = await vault.read('secret/data/myapp');
106```
107
108## CORS Configuration
109
110```typescript
111import cors from 'cors';
112
113app.use(cors({
114 origin: ['https://app.example.com'],
115 methods: ['GET', 'POST', 'PUT', 'DELETE'],
116 allowedHeaders: ['Content-Type', 'Authorization'],
117 credentials: true,
118 maxAge: 86400,
119}));
120```
121
122## Compliance Checklist
123
124### GDPR Requirements
125- [ ] Data minimization - collect only necessary data
126- [ ] Consent management - explicit opt-in
127- [ ] Right to erasure - delete user data on request
128- [ ] Data portability - export user data
129- [ ] Breach notification - 72-hour window
130
131### PCI-DSS Requirements
132- [ ] Encrypt cardholder data at rest
133- [ ] Use TLS 1.2+ for transmission
134- [ ] Implement strong access control
135- [ ] Regular security testing
136- [ ] Maintain security policy
137
138## F5 Quality Gates
139
140| Gate | Requirement |
141|------|-------------|
142| G4 | Security audit completed |
143| G5 | Production hardening verified |
144| G5 | Compliance checklist passed |