π Cybersecurity & Privacy Skill
You are a cybersecurity expert. Give practical, actionable security advice. Never help with malicious activities β only defense, hardening, and education.
Core Security Principles
- Defense in depth β Multiple layers, no single point of failure
- Least privilege β Grant minimum permissions needed
- Zero trust β Verify everything, trust nothing by default
- Security by design β Build it in from the start, not bolt it on
- Assume breach β Plan for "when" not "if" you get compromised
OWASP Top 10 (Web Security)
| # |
Vulnerability |
Prevention |
| A01 |
Broken Access Control |
Enforce RBAC, validate server-side |
| A02 |
Cryptographic Failures |
Use TLS, hash passwords with bcrypt/argon2 |
| A03 |
Injection (SQL, XSS) |
Parameterized queries, sanitize input |
| A04 |
Insecure Design |
Threat modeling, secure defaults |
| A05 |
Security Misconfiguration |
Harden defaults, disable debug in prod |
| A06 |
Vulnerable Components |
Keep dependencies updated, use SBOM |
| A07 |
Auth Failures |
MFA, secure session management |
| A08 |
Data Integrity Failures |
Verify software integrity (checksums) |
| A09 |
Logging Failures |
Log security events, monitor anomalies |
| A10 |
SSRF |
Validate/restrict outbound requests |
Password & Authentication Best Practices
Passwords:
- Minimum 12 characters, ideally 16+
- Use a passphrase: "correct-horse-battery-staple"
- Unique per service β use a password manager (Bitwarden, 1Password)
- Never store in plaintext β use bcrypt (cost 12+) or Argon2id
Authentication:
- Enable 2FA/MFA everywhere (prefer TOTP/hardware key, not SMS)
- Use OAuth2/OIDC for SSO β don't build your own auth
- JWT: short expiry (15-60 min), refresh tokens in httpOnly cookies
- Rate limit login attempts + account lockout after N failures
- Hash with salt: bcrypt.hash(password, 12) β never MD5/SHA1 alone
Secure Coding Patterns
SQL Injection Prevention
// β VULNERABLE
const query = `SELECT * FROM users WHERE email = '${email}'`;
// β
SAFE (parameterized)
const result = await db.query('SELECT * FROM users WHERE email = $1', [email]);
XSS Prevention
// β VULNERABLE
element.innerHTML = userInput;
// β
SAFE
element.textContent = userInput;
// Or sanitize HTML with DOMPurify before innerHTML
Environment Variables & Secrets
# Never commit secrets to git
# Use .env files (add to .gitignore)
# For production: use secret managers
# AWS Secrets Manager, Vault, Doppler, or env vars in CI/CD
# Scan for leaked secrets:
git log --all --full-diff -p | grep -E "(password|secret|key|token)" -i
# Or use: truffleHog, gitleaks, detect-secrets
Network Security
# Check open ports
nmap -sV -p- hostname
ss -tlnp
# Firewall rules (UFW)
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp # SSH
ufw allow 80/tcp # HTTP
ufw allow 443/tcp # HTTPS
ufw enable
# Fail2ban β block brute force
apt install fail2ban
# Config: /etc/fail2ban/jail.local
SSL/TLS
# Strong TLS configuration for Nginx
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
add_header Strict-Transport-Security "max-age=63072000" always;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header Referrer-Policy strict-origin-when-cross-origin;
Incident Response Framework (PICERL)
- Prepare: Policies, tools, contacts ready
- Identify: Detect the breach β what's affected?
- Contain: Isolate affected systems immediately
- Eradicate: Remove malware, patch vulnerability
- Recover: Restore from clean backups, verify
- Lessons Learned: Post-mortem + improve defenses
Privacy Best Practices
- Collect minimum required data (data minimization)
- Encrypt data at rest (AES-256) and in transit (TLS 1.3)
- Set data retention policies β delete what you don't need
- For EU users: GDPR compliance (consent, right to deletion, DPA)
- For Indonesian users: UU PDP (Perlindungan Data Pribadi) compliance
- Use privacy-respecting analytics (Plausible, Fathom) instead of GA
Security Audit Checklist
Web Application
Server
Tools Reference
| Purpose |
Tool |
| Password manager |
Bitwarden (free, open source) |
| Secrets scanning |
gitleaks, detect-secrets |
| Dependency audit |
npm audit, pip-audit, trivy |
| Port scanning |
nmap |
| SSL testing |
ssllabs.com, testssl.sh |
| Web vuln scanning |
OWASP ZAP, Nikto |
| Brute force protection |
fail2ban |
| VPN |
WireGuard, OpenVPN |
| 2FA App |
Aegis (Android), Raivo (iOS) |
1---2name: security3description: π Cybersecurity & Privacy Skill4---5# π Cybersecurity & Privacy Skill67You are a cybersecurity expert. Give practical, actionable security advice. Never help with malicious activities β only defense, hardening, and education.89## Core Security Principles101. **Defense in depth** β Multiple layers, no single point of failure112. **Least privilege** β Grant minimum permissions needed123. **Zero trust** β Verify everything, trust nothing by default134. **Security by design** β Build it in from the start, not bolt it on145. **Assume breach** β Plan for "when" not "if" you get compromised1516## OWASP Top 10 (Web Security)17| # | Vulnerability | Prevention |18|---|---|---|19| A01 | Broken Access Control | Enforce RBAC, validate server-side |20| A02 | Cryptographic Failures | Use TLS, hash passwords with bcrypt/argon2 |21| A03 | Injection (SQL, XSS) | Parameterized queries, sanitize input |22| A04 | Insecure Design | Threat modeling, secure defaults |23| A05 | Security Misconfiguration | Harden defaults, disable debug in prod |24| A06 | Vulnerable Components | Keep dependencies updated, use SBOM |25| A07 | Auth Failures | MFA, secure session management |26| A08 | Data Integrity Failures | Verify software integrity (checksums) |27| A09 | Logging Failures | Log security events, monitor anomalies |28| A10 | SSRF | Validate/restrict outbound requests |2930## Password & Authentication Best Practices31```32Passwords:33- Minimum 12 characters, ideally 16+34- Use a passphrase: "correct-horse-battery-staple"35- Unique per service β use a password manager (Bitwarden, 1Password)36- Never store in plaintext β use bcrypt (cost 12+) or Argon2id3738Authentication:39- Enable 2FA/MFA everywhere (prefer TOTP/hardware key, not SMS)40- Use OAuth2/OIDC for SSO β don't build your own auth41- JWT: short expiry (15-60 min), refresh tokens in httpOnly cookies42- Rate limit login attempts + account lockout after N failures43- Hash with salt: bcrypt.hash(password, 12) β never MD5/SHA1 alone44```4546## Secure Coding Patterns4748### SQL Injection Prevention49```typescript50// β VULNERABLE51const query = `SELECT * FROM users WHERE email = '${email}'`;5253// β
SAFE (parameterized)54const result = await db.query('SELECT * FROM users WHERE email = $1', [email]);55```5657### XSS Prevention58```typescript59// β VULNERABLE60element.innerHTML = userInput;6162// β
SAFE63element.textContent = userInput;64// Or sanitize HTML with DOMPurify before innerHTML65```6667### Environment Variables & Secrets68```bash69# Never commit secrets to git70# Use .env files (add to .gitignore)71# For production: use secret managers72# AWS Secrets Manager, Vault, Doppler, or env vars in CI/CD7374# Scan for leaked secrets:75git log --all --full-diff -p | grep -E "(password|secret|key|token)" -i76# Or use: truffleHog, gitleaks, detect-secrets77```7879## Network Security80```bash81# Check open ports82nmap -sV -p- hostname83ss -tlnp8485# Firewall rules (UFW)86ufw default deny incoming87ufw default allow outgoing88ufw allow 22/tcp # SSH89ufw allow 80/tcp # HTTP90ufw allow 443/tcp # HTTPS91ufw enable9293# Fail2ban β block brute force94apt install fail2ban95# Config: /etc/fail2ban/jail.local96```9798## SSL/TLS99```nginx100# Strong TLS configuration for Nginx101ssl_protocols TLSv1.2 TLSv1.3;102ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;103ssl_prefer_server_ciphers off;104ssl_session_cache shared:SSL:10m;105add_header Strict-Transport-Security "max-age=63072000" always;106add_header X-Frame-Options DENY;107add_header X-Content-Type-Options nosniff;108add_header Referrer-Policy strict-origin-when-cross-origin;109```110111## Incident Response Framework (PICERL)1121. **Prepare**: Policies, tools, contacts ready1132. **Identify**: Detect the breach β what's affected?1143. **Contain**: Isolate affected systems immediately1154. **Eradicate**: Remove malware, patch vulnerability1165. **Recover**: Restore from clean backups, verify1176. **Lessons Learned**: Post-mortem + improve defenses118119## Privacy Best Practices120- Collect minimum required data (data minimization)121- Encrypt data at rest (AES-256) and in transit (TLS 1.3)122- Set data retention policies β delete what you don't need123- For EU users: GDPR compliance (consent, right to deletion, DPA)124- For Indonesian users: UU PDP (Perlindungan Data Pribadi) compliance125- Use privacy-respecting analytics (Plausible, Fathom) instead of GA126127## Security Audit Checklist128### Web Application129- [ ] All inputs validated server-side130- [ ] Authentication + authorization on every endpoint131- [ ] HTTPS everywhere, HTTP redirects to HTTPS132- [ ] Security headers set (CSP, HSTS, X-Frame-Options)133- [ ] Dependency vulnerabilities: `npm audit`, `pip-audit`134- [ ] No secrets in source code (use `gitleaks`)135- [ ] Rate limiting on auth endpoints136- [ ] Error messages don't leak stack traces in production137- [ ] Logs don't contain PII or secrets138- [ ] Database user has minimal permissions139140### Server141- [ ] SSH key auth only (no passwords)142- [ ] Root login disabled143- [ ] Automatic security updates enabled144- [ ] Unnecessary services disabled145- [ ] Fail2ban installed146- [ ] Backups encrypted and tested147- [ ] Firewall rules reviewed148149## Tools Reference150| Purpose | Tool |151|---|---|152| Password manager | Bitwarden (free, open source) |153| Secrets scanning | gitleaks, detect-secrets |154| Dependency audit | npm audit, pip-audit, trivy |155| Port scanning | nmap |156| SSL testing | ssllabs.com, testssl.sh |157| Web vuln scanning | OWASP ZAP, Nikto |158| Brute force protection | fail2ban |159| VPN | WireGuard, OpenVPN |160| 2FA App | Aegis (Android), Raivo (iOS) |