| name | security-analysis-skills |
| description | Comprehensive security analysis framework teaching STRIDE threat modeling, OWASP Top 10 vulnerabilities, CVSS risk scoring, and secure coding patterns. Use when conducting security assessments, code reviews, threat modeling, or implementing security controls. Applicable to all development work requiring security consideration. |
| license | MIT |
Security Analysis Skills
Purpose: Universal security knowledge framework for threat modeling, vulnerability assessment, risk scoring, and secure coding. Designed to be applied by ALL development agents (security-agent, developer-agent, devops-agent, rust-expert, python-ml-expert) to ensure security-first development practices.
Created: 2025-11-08
When to Use Security Analysis Skills
✅ Use this skill when:
- Conducting threat modeling for new features/systems
- Performing security code review
- Assessing vulnerabilities and scoring risk
- Implementing authentication/authorization
- Handling sensitive data (PII, credentials, payment info)
- Deploying to production (security checklist)
- Investigating security incidents
- Designing secure architectures
❌ NOT required for:
- Pure documentation tasks with no code
- Read-only data analysis with public data
- Internal tools with no network exposure (but still recommended)
Target Audience: Security specialists AND general developers integrating security into daily work
Core Security Frameworks
1. STRIDE Threat Modeling
Purpose: Systematic identification of threats by category
STRIDE Categories:
-
S - Spoofing Identity
- Definition: Attacker pretends to be someone else
- Examples: Stolen credentials, session hijacking, JWT forgery
- Mitigations: MFA, certificate pinning, signed tokens
-
T - Tampering with Data
- Definition: Unauthorized modification of data
- Examples: Man-in-the-middle, SQL injection, XSS
- Mitigations: HTTPS/TLS, input validation, integrity checks (HMAC)
-
R - Repudiation
- Definition: User denies performing an action
- Examples: Missing audit logs, unsigned transactions
- Mitigations: Audit logging, digital signatures, timestamps
-
I - Information Disclosure
- Definition: Exposure of confidential information
- Examples: Directory traversal, verbose errors, unencrypted data
- Mitigations: Encryption at rest/transit, least privilege, sanitized errors
-
D - Denial of Service
- Definition: Service becomes unavailable
- Examples: Resource exhaustion, infinite loops, DDoS attacks
- Mitigations: Rate limiting, resource quotas, circuit breakers
-
E - Elevation of Privilege
- Definition: Unauthorized permission escalation
- Examples: Privilege escalation bugs, insecure defaults
- Mitigations: Principle of least privilege, role-based access control
How to Apply STRIDE:
- For each component/feature, ask: "What STRIDE threats apply?"
- Fill out threat modeling worksheet (see reference section)
- Prioritize threats by impact × likelihood
- Document mitigations for each identified threat
2. OWASP Top 10 (2021 Edition)
Purpose: Most critical web application security risks
A01: Broken Access Control
Description: Users can act outside their intended permissions
Examples:
- Direct object references:
/user/1234/profile → change to /user/5678/profile
- Missing function-level access control: Regular user accesses
/admin/delete
- IDOR (Insecure Direct Object Reference): Manipulating IDs in URLs/APIs
Secure Patterns:
@app.route('/document/<doc_id>')
def get_document(doc_id):
doc = Document.query.get(doc_id)
return render_template('doc.html', doc=doc)
@app.route('/document/<doc_id>')
@login_required
def get_document(doc_id):
doc = Document.query.get(doc_id)
if not doc or doc.owner_id != current_user.id:
abort(403)
return render_template('doc.html', doc=doc)
Checklist:
A02: Cryptographic Failures
Description: Sensitive data exposed due to weak/missing encryption
Examples:
- Storing passwords in plaintext
- Using weak algorithms (MD5, SHA1 for passwords)
- Transmitting sensitive data over HTTP
- Hardcoded encryption keys
Secure Patterns:
import hashlib
password_hash = hashlib.md5(password.encode()).hexdigest()
import bcrypt
password_hash = bcrypt.hashpw(password.encode(), bcrypt.gensalt())
AES_KEY = "mysecretkey12345"
import os
AES_KEY = os.environ['AES_ENCRYPTION_KEY']
Checklist:
A03: Injection
Description: Untrusted data sent to interpreter as command/query
Types: SQL Injection, NoSQL Injection, Command Injection, LDAP Injection, XPath Injection
SQL Injection Example:
username = request.form['username']
query = f"SELECT * FROM users WHERE username = '{username}'"
username = request.form['username']
query = "SELECT * FROM users WHERE username = ?"
cursor.execute(query, (username,))
Command Injection Example:
filename = request.form['filename']
os.system(f"cat {filename}")
import subprocess
subprocess.run(['cat', filename], check=True, capture_output=True)
Checklist:
A04: Insecure Design
Description: Missing or ineffective security controls in design phase
Examples:
- No rate limiting on login (brute force)
- Password reset without identity verification
- Predictable session IDs
- No transaction verification (CSRF)
Secure Design Patterns:
- Defense in depth (multiple security layers)
- Principle of least privilege
- Fail securely (default deny)
- Separation of duties
- Security by default (opt-in for risky features)
Checklist:
A05: Security Misconfiguration
Description: Insecure default configurations, incomplete setups, exposed admin interfaces
Examples:
- Default admin credentials (admin/admin)
- Verbose error messages revealing stack traces
- Unnecessary features enabled (debug mode in production)
- Missing security headers
- Outdated software versions
Secure Configuration:
app = Flask(__name__)
app.config['DEBUG'] = True
import os
app.config['DEBUG'] = os.environ.get('FLASK_ENV') == 'development'
@app.after_request
def set_security_headers(response):
response.headers['X-Content-Type-Options'] = 'nosniff'
response.headers['X-Frame-Options'] = 'DENY'
response.headers['X-XSS-Protection'] = '1; mode=block'
response.headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains'
return response
Checklist:
A06: Vulnerable and Outdated Components
Description: Using libraries/frameworks with known vulnerabilities
Examples:
- Unmaintained dependencies (no security patches)
- Using deprecated crypto libraries
- Outdated frameworks (old Rails, Django, Spring)
Secure Practices:
npm audit
pip-audit
bundle audit
cargo audit
npm update
pip install --upgrade -r requirements.txt
cargo update
Checklist:
A07: Identification and Authentication Failures
Description: Weak authentication allows attackers to compromise accounts
Examples:
- Weak password policy (no complexity requirements)
- Session fixation
- Missing MFA
- Predictable session tokens
- No account lockout on brute force
Secure Authentication:
MIN_LENGTH = 12
REQUIRE_UPPERCASE = True
REQUIRE_DIGIT = True
REQUIRE_SPECIAL = True
from secrets import token_urlsafe
session_id = token_urlsafe(32)
from flask_limiter import Limiter
limiter = Limiter(app, default_limits=["5 per minute"])
@app.route('/login', methods=['POST'])
@limiter.limit("5 per minute")
def login():
pass
Checklist:
A08: Software and Data Integrity Failures
Description: Code/infrastructure relies on untrusted sources without integrity verification
Examples:
- Downloading dependencies without checksum verification
- Auto-update without signature validation
- Insecure CI/CD pipeline
- Deserialization of untrusted data
Secure Practices:
import pickle
data = pickle.loads(request.data)
import json
data = json.loads(request.data)
pip install --require-hashes -r requirements.txt
Checklist:
A09: Security Logging and Monitoring Failures
Description: Insufficient logging prevents detection of breaches
Examples:
- No logging of authentication events
- Logs not reviewed/alerted
- Sensitive data in logs (passwords, tokens)
- No integrity protection (logs can be tampered)
Secure Logging:
import logging
import hashlib
logger = logging.getLogger('security')
@app.route('/login', methods=['POST'])
def login():
username = request.form['username']
password = request.form['password']
if authenticate(username, password):
logger.info(f"Successful login: user={username}, ip={request.remote_addr}")
return "Success"
else:
logger.warning(f"Failed login: user={username}, ip={request.remote_addr}")
return "Invalid credentials", 401
logger.info(f"User {username} logged in with password {password}")
logger.info(f"User {username} logged in")
Checklist:
A10: Server-Side Request Forgery (SSRF)
Description: Web app fetches remote resource without validating user-supplied URL
Examples:
- Fetching arbitrary URLs from user input
- Accessing internal services (localhost, 169.254.169.254)
- Port scanning via web app
SSRF Example:
import requests
url = request.args.get('url')
response = requests.get(url)
ALLOWED_DOMAINS = ['api.example.com', 'cdn.example.com']
from urllib.parse import urlparse
url = request.args.get('url')
parsed = urlparse(url)
if parsed.hostname not in ALLOWED_DOMAINS:
abort(400, "Invalid domain")
response = requests.get(url)
Checklist:
3. Risk Scoring (CVSS v3.1)
Purpose: Quantify vulnerability severity for prioritization
CVSS Formula: Base Score (0-10) = f(Impact, Exploitability)
Severity Levels:
- Critical (9.0-10.0): Immediate action required, exploit in the wild
- High (7.0-8.9): High priority, exploitable remotely
- Medium (4.0-6.9): Medium priority, requires user interaction
- Low (0.1-3.9): Low priority, limited impact
Impact Scoring:
- Confidentiality Impact: None / Low / High
- Integrity Impact: None / Low / High
- Availability Impact: None / Low / High
Exploitability Scoring:
- Attack Vector: Network (highest) / Adjacent / Local / Physical (lowest)
- Attack Complexity: Low (easy) / High (difficult)
- Privileges Required: None (highest) / Low / High (lowest)
- User Interaction: None (highest) / Required (lower)
Quick Risk Matrix (Impact × Likelihood):
| Impact / Likelihood | Low | Medium | High |
|---|
| High | Med | High | Crit |
| Medium | Low | Med | High |
| Low | Low | Low | Med |
Example Scoring:
Vulnerability: SQL Injection in login endpoint
CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N
- Attack Vector: Network (AV:N) - remotely exploitable
- Attack Complexity: Low (AC:L) - easy to exploit
- Privileges Required: None (PR:N) - unauthenticated
- User Interaction: None (UI:N) - no user action needed
- Confidentiality: High (C:H) - all user data exposed
- Integrity: High (I:H) - data can be modified
- Availability: None (A:N) - no DoS
Base Score: 9.1 (CRITICAL)
Checklist:
4. Security Code Review Patterns
Purpose: Identify common vulnerabilities during code review
Input Validation
Rule: Never trust user input
Patterns:
ALLOWED_EXTENSIONS = {'.jpg', '.png', '.pdf'}
file_ext = os.path.splitext(filename)[1].lower()
if file_ext not in ALLOWED_EXTENSIONS:
raise ValueError("Invalid file type")
import re
EMAIL_PATTERN = re.compile(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
if not EMAIL_PATTERN.match(email):
raise ValueError("Invalid email")
from pydantic import BaseModel, validator
class UserInput(BaseModel):
age: int
email: str
@validator('age')
def age_must_be_positive(cls, v):
if v < 0 or v > 150:
raise ValueError('Invalid age')
return v
Authentication & Authorization
Rule: Verify identity and permissions at every access point
Patterns:
from functools import wraps
def require_role(role):
def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if not current_user.has_role(role):
abort(403)
return f(*args, **kwargs)
return decorated_function
return decorator
@app.route('/admin/users')
@require_role('admin')
def list_users():
return render_template('users.html', users=User.query.all())
def check_ownership(resource, user):
if resource.owner_id != user.id and not user.is_admin():
abort(403, "Not authorized to access this resource")
Cryptography Best Practices
Rules:
- Don't roll your own crypto
- Use standard libraries (cryptography, libsodium)
- Use authenticated encryption (AES-GCM, ChaCha20-Poly1305)
Patterns:
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
import os
key = AESGCM.generate_key(bit_length=256)
aesgcm = AESGCM(key)
nonce = os.urandom(12)
ciphertext = aesgcm.encrypt(nonce, plaintext, associated_data=None)
import bcrypt
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt(rounds=12))
import secrets
token = secrets.token_urlsafe(32)
Secrets Management
Rule: Never hardcode secrets
Patterns:
API_KEY = "sk_live_abc123xyz789"
import os
API_KEY = os.environ['API_KEY']
import boto3
client = boto3.client('secretsmanager')
response = client.get_secret_value(SecretId='prod/api-key')
API_KEY = response['SecretString']
import json
with open('/etc/secrets/config.json') as f:
config = json.load(f)
API_KEY = config['api_key']
Checklist:
STRIDE Threat Modeling Worksheet
Use this template for every new feature/component:
## Threat Model: [Feature/Component Name]
**Description**: [Brief description of functionality]
**Date**: [YYYY-MM-DD]
**Reviewer**: [Your name]
---
### Components
List all components involved:
1. [Component 1: e.g., Login API endpoint]
2. [Component 2: e.g., User database]
3. [Component 3: e.g., Session store]
---
### Data Flow
Describe how data flows:
1. User submits credentials → Login API
2. Login API queries User DB
3. On success, create session in Session Store
4. Return session token to user
---
### Threats Identified
#### Spoofing
- [ ] **Threat**: Attacker uses stolen credentials
- **Mitigation**: Implement MFA
- **Priority**: High
#### Tampering
- [ ] **Threat**: Man-in-the-middle modifies login request
- **Mitigation**: Enforce HTTPS/TLS 1.3
- **Priority**: Critical
#### Repudiation
- [ ] **Threat**: User denies login action
- **Mitigation**: Log all authentication events with timestamp
- **Priority**: Medium
#### Information Disclosure
- [ ] **Threat**: Verbose error reveals username existence
- **Mitigation**: Generic error message "Invalid credentials"
- **Priority**: Medium
#### Denial of Service
- [ ] **Threat**: Brute force attack exhausts server resources
- **Mitigation**: Rate limiting (5 attempts/minute)
- **Priority**: High
#### Elevation of Privilege
- [ ] **Threat**: Session fixation allows privilege escalation
- **Mitigation**: Regenerate session ID on login
- **Priority**: High
---
### Risk Summary
Total threats identified: [N]
- Critical: [N]
- High: [N]
- Medium: [N]
- Low: [N]
**Overall Risk Level**: [Critical/High/Medium/Low]
Security Checklist (Pre-Deployment)
Use this before deploying any code to production:
Authentication & Authorization
Input Validation
Cryptography
Error Handling
Security Headers
Logging & Monitoring
Dependencies
Infrastructure
Reference Materials
Detailed Guides:
Secure Coding Guides:
Tools:
- Static Analysis: Bandit (Python), ESLint (JS), cargo-audit (Rust)
- Dependency Scanning: Snyk, Dependabot, npm audit
- Dynamic Analysis: OWASP ZAP, Burp Suite
Self-Assessment
After applying security analysis, verify:
Confidence Level:
- High (90%+): All frameworks applied, threat model complete, security tests passing
- Medium (70-89%): Main threats addressed, some edge cases remain
- Low (<70%): Significant security gaps identified - continue working
Summary
Security Analysis Skills provide systematic frameworks for integrating security into all development work:
- STRIDE Threat Modeling: Identify threats by category (Spoofing, Tampering, Repudiation, Information Disclosure, DoS, Elevation of Privilege)
- OWASP Top 10: Address most critical web vulnerabilities
- CVSS Risk Scoring: Quantify and prioritize vulnerability remediation
- Secure Coding Patterns: Apply proven security patterns in code review
Remember: Security is not a feature, it's a requirement. Apply these frameworks proactively during design and development, not reactively after incidents.
Target: Zero Critical/High vulnerabilities in production deployments.