/security-patterns
Security best practices covering API key management, input validation, injection prevention, and OWASP patterns. Use when handling secrets, user input, or security-sensitive code. TRIGGER when: security, API key, secret, input validation, injection, OWASP. DO NOT TRIGGER when:
$ npx -y skills add akaszubski/autonomous-dev --skill security-patterns --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/security-patterns
Context preview
The summary Claude sees to decide when to auto-load this skill.
Security best practices covering API key management, input validation, injection prevention, and OWASP patterns. Use when handling secrets, user input, or security-sensitive code. TRIGGER when: security, API key, secret, input validation, injection, OWASP. DO NOT TRIGGER when:
SKILL.md
security-patterns.SKILL.mdname: security-patterns
description: "Security best practices covering API key management, input validation, injection prevention, and OWASP patterns. Use when handling secrets, user input, or security-sensitive code. TRIGGER when: security, API key, secret, input validation, injection, OWASP. DO NOT TRIGGER when: non-security code, styling, documentation, test scaffolding."
allowed-tools: [Read]
Security Patterns Skill
Security best practices and patterns for secure development.
**See:** [code-examples.md](code-examples.md) for Python implementations **See:** [templates.md](templates.md) for checklists and config templates
When This Activates
- API key handling
- User input validation
- File operations
- Security-sensitive code
- Keywords: "security", "api key", "secret", "validate", "input"
---
API Keys & Secrets
Environment Variables (REQUIRED)
**Rule:** Never hardcode secrets. Always use environment variables via `.env` files.
# ✅ CORRECT
api_key = os.getenv("ANTHROPIC_API_KEY")
# ❌ WRONG
api_key = "sk-ant-1234567890abcdef" # NEVER!**See:** [code-examples.md#api-keys--secrets](code-examples.md#api-keys--secrets) for full validation code
---
Input Validation
Path Traversal Prevention
**Rule:** Always validate paths are within allowed directories.
# Use is_relative_to() to prevent ../ attacks
if not file_path.is_relative_to(base_dir):
raise ValueError("Path traversal detected")Command Injection Prevention
**Rule:** Never use `shell=True`. Pass arguments as lists.
# ✅ CORRECT
subprocess.run([command] + args, shell=False)
# ❌ WRONG
subprocess.run(f"ls {user_input}", shell=True) # Injection risk!SQL Injection Prevention
**Rule:** Always use parameterized queries.
# ✅ CORRECT
cursor.execute("SELECT * FROM users WHERE username = ?", (username,))
# ❌ WRONG
cursor.execute(f"SELECT * FROM users WHERE username = '{username}'")**See:** [code-examples.md#input-validation](code-examples.md#input-validation) for complete examples
---
File Operations Security
Secure Permissions
| Use Case | Permission | Octal | |----------|------------|-------| | Sensitive files | `rw-------` | 0o600 | | Sensitive dirs | `rwx------` | 0o700 | | Public files | `rw-r--r--` | 0o644 |
File Upload Validation
- Validate extensions (whitelist only)
- Check file size limits
- Reject executable files
**See:** [code-examples.md#file-operations-security](code-examples.md#file-operations-security)
---
Cryptographic Operations
Secure Random
**Rule:** Use `secrets` module for security-sensitive random values.
# ✅ CORRECT
token = secrets.token_hex(32)
# ❌ WRONG
token = str(random.randint(0, 999999)) # Not cryptographically secure!
**See:** [code-examples.md#cryptographic-operations](code-examples.md#cryptographic-operations) for password hashing
---
Logging Security
**Rule:** Never log full secrets. Mask sensitive values.
# ✅ CORRECT
masked_key = api_key[:7] + "***" + api_key[-4:]
logging.info(f"Using key {masked_key}")
# ❌ WRONG
logging.info(f"Using key {api_key}") # Exposes full key!---
Dependencies Security
# Check for vulnerabilities
pip install safety && safety check
# OR
pip install pip-audit && pip-audit
---
Key Takeaways
1. **Never hardcode secrets** - Use environment variables 2. **Validate all inputs** - User data, file paths, commands 3. **Prevent path traversal** - Use `is_relative_to()` 4. **No shell=True** - Use list arguments with subprocess 5. **Parameterized queries** - Never string interpolation 6. **Secure random** - Use `secrets` module 7. **Restrict permissions** - Files 0o600, dirs 0o700 8. **Mask secrets in logs** - Show only first/last few chars 9. **Scan dependencies** - Use safety/pip-audit 10. **.gitignore secrets** - .env, *.key, *.pem
---
Related Files
- [code-examples.md](code-examples.md) - Complete Python code examples
- [templates.md](templates.md) - .env, .gitignore, and security checklists
OWASP Top 10 Quick Reference
**See:** [templates.md#owasp-top-10-quick-reference](templates.md#owasp-top-10-quick-reference)
Read more
name: security-patterns description: "Security best practices covering API key management, input validation, injection prevention, and OWASP patterns. Use when handling secrets, user input, or security-sensitive code. TRIGGER when: security, API key, secret, input validation, injection, OWASP. DO NOT TRIGGER when: non-security code, styling, documentation, test scaffolding." allowed-tools: [Read]
Security Patterns Skill
Security best practices and patterns for secure development.
**See:** [code-examples.md](code-examples.md) for Python implementations **See:** [templates.md](templates.md) for checklists and config templates
When This Activates
- API key handling
- User input validation
- File operations
- Security-sensitive code
- Keywords: "security", "api key", "secret", "validate", "input"
---
API Keys & Secrets
Environment Variables (REQUIRED)
**Rule:** Never hardcode secrets. Always use environment variables via `.env` files.
# ✅ CORRECT
api_key = os.getenv("ANTHROPIC_API_KEY")
# ❌ WRONG
api_key = "sk-ant-1234567890abcdef" # NEVER!**See:** [code-examples.md#api-keys--secrets](code-examples.md#api-keys--secrets) for full validation code
---
Input Validation
Path Traversal Prevention
**Rule:** Always validate paths are within allowed directories.
# Use is_relative_to() to prevent ../ attacks
if not file_path.is_relative_to(base_dir):
raise ValueError("Path traversal detected")Command Injection Prevention
**Rule:** Never use `shell=True`. Pass arguments as lists.
# ✅ CORRECT
subprocess.run([command] + args, shell=False)
# ❌ WRONG
subprocess.run(f"ls {user_input}", shell=True) # Injection risk!SQL Injection Prevention
**Rule:** Always use parameterized queries.
# ✅ CORRECT
cursor.execute("SELECT * FROM users WHERE username = ?", (username,))
# ❌ WRONG
cursor.execute(f"SELECT * FROM users WHERE username = '{username}'")**See:** [code-examples.md#input-validation](code-examples.md#input-validation) for complete examples
---
File Operations Security
Secure Permissions
| Use Case | Permission | Octal | |----------|------------|-------| | Sensitive files | `rw-------` | 0o600 | | Sensitive dirs | `rwx------` | 0o700 | | Public files | `rw-r--r--` | 0o644 |
File Upload Validation
- Validate extensions (whitelist only)
- Check file size limits
- Reject executable files
**See:** [code-examples.md#file-operations-security](code-examples.md#file-operations-security)
---
Cryptographic Operations
Secure Random
**Rule:** Use `secrets` module for security-sensitive random values.
# ✅ CORRECT token = secrets.token_hex(32) # ❌ WRONG token = str(random.randint(0, 999999)) # Not cryptographically secure!
**See:** [code-examples.md#cryptographic-operations](code-examples.md#cryptographic-operations) for password hashing
---
Logging Security
**Rule:** Never log full secrets. Mask sensitive values.
# ✅ CORRECT
masked_key = api_key[:7] + "***" + api_key[-4:]
logging.info(f"Using key {masked_key}")
# ❌ WRONG
logging.info(f"Using key {api_key}") # Exposes full key!---
Dependencies Security
# Check for vulnerabilities pip install safety && safety check # OR pip install pip-audit && pip-audit
---
Key Takeaways
1. **Never hardcode secrets** - Use environment variables 2. **Validate all inputs** - User data, file paths, commands 3. **Prevent path traversal** - Use `is_relative_to()` 4. **No shell=True** - Use list arguments with subprocess 5. **Parameterized queries** - Never string interpolation 6. **Secure random** - Use `secrets` module 7. **Restrict permissions** - Files 0o600, dirs 0o700 8. **Mask secrets in logs** - Show only first/last few chars 9. **Scan dependencies** - Use safety/pip-audit 10. **.gitignore secrets** - .env, *.key, *.pem
---
Related Files
- [code-examples.md](code-examples.md) - Complete Python code examples
- [templates.md](templates.md) - .env, .gitignore, and security checklists
OWASP Top 10 Quick Reference
**See:** [templates.md#owasp-top-10-quick-reference](templates.md#owasp-top-10-quick-reference)
A harness that wraps Claude Code with enforcement, specialist agents, and alignment gates to deliver consistent, production-grade software engineering outcomes.
Repo: akaszubski/autonomous-dev
Other skills on autonomous-dev.
- /api-design
REST API design best practices covering versioning, error handling, pagination, and OpenAPI documentation. Use when designing or implementing REST APIs or HTTP endpoints. TRIGGER when: API design, REST endpoint, HTTP route, OpenAPI, swagger, pagination. DO NOT TRIGGER when:
Open skill - /api-integration-patterns
Subprocess safety, GitHub CLI integration, retry logic, authentication, rate limiting, and timeout handling. Use when integrating external APIs or CLI tools. TRIGGER when: subprocess, gh cli, API call, retry logic, rate limiting, authentication. DO NOT TRIGGER when: internal
Open skill - /architecture-patterns
File-by-file architecture planning with ADR format, dependency ordering, and testability gates. Use when designing system architecture or creating ADRs. TRIGGER when: architecture plan, system design, ADR, file breakdown, component design. DO NOT TRIGGER when: simple config
Open skill - /code-review
10-point code review checklist covering correctness, tests, error handling, type hints, naming, security, and performance. Use when reviewing PRs or evaluating code quality. TRIGGER when: code review, PR review, review checklist, code quality check. DO NOT TRIGGER when: writing
Open skill - /content-allocation
One topic, one home. Routes content to its canonical store (CLAUDE.md, PROJECT.md, MEMORY.md, docs/, memory/) and audits for duplication. TRIGGER when: auditing CLAUDE.md/PROJECT.md/MEMORY.md sizes, deduplicating docs, applying the content-allocation pattern to a new repo,
Open skill - /debugging-workflow
Systematic debugging methodology — reproduce, isolate, bisect, fix, verify. Use when diagnosing failures, tracing errors, or investigating unexpected behavior. TRIGGER when: debug, error, traceback, stack trace, bisect, breakpoint, failing test, unexpected behavior. DO NOT
Open skill

