arabelatso/security-patch-advisor
Proposes secure remediation strategies for detected security vulnerabilities including buffer overflows, injection risks, insecure deserialization, improper authentication, and unsafe cryptographic usage. Provides recommended security checks, safer API alternatives, design-level changes, code examples, trade-off analysis, and prioritized remediation plans. Does NOT automatically modify code unless explicitly requested.
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill security-patch-advisor
This skill analyzes security vulnerabilities and provides comprehensive remediation strategies without automatically modifying code. It offers multiple remediation approaches with detailed trade-off analysis, code examples, and implementation guidance for vulnerabilities categorized by CWE (Common Weakness Enumeration) and severity.
Use this skill when you need:
Trigger scenarios:
When presented with a security vulnerability, analyze:
Context Gathering:
Questions to Consider:
Provide multiple remediation approaches:
Strategy Components:
For Each Strategy, Include:
Provide concrete before/after examples:
Example Structure:
### Vulnerable Code
[Show the insecure code with clear vulnerability markers]
**Vulnerability:** CWE-XXX (Name)
**Risk:** [Explain the security risk]
**Attack Example:** [Show how it could be exploited]
### Remediated Code (Approach 1)
[Show the fixed code with security improvements]
**Changes:**
- [List specific changes made]
- [Explain security mechanisms added]
**Trade-offs:**
- ✅ [Benefits]
- ⚠️ [Limitations or considerations]
### Alternative Remediation (Approach 2)
[Show alternative fix if applicable]
**Trade-offs:**
- ✅ [Benefits]
- ⚠️ [Limitations or considerations]
Provide step-by-step implementation instructions:
Guidance Should Include:
Help prioritize remediation efforts:
Prioritization Factors:
Priority Levels:
Common Remediations:
strncpy, snprintf)Common Remediations:
Common Remediations:
Common Remediations:
Common Remediations:
Common Remediations:
Common Remediations:
Structure your remediation advice as follows:
## Vulnerability Summary
- **Type:** [CWE-XXX: Name]
- **Severity:** [Critical/High/Medium/Low]
- **Location:** [File:Line or Component]
- **Impact:** [Brief description of security impact]
## Risk Analysis
[Explain the security risk, attack vectors, and potential impact]
## Recommended Remediation (Primary)
[Detailed description of the recommended fix]
### Code Example
[Before/after code showing the fix]
### Implementation Steps
1. [Step 1]
2. [Step 2]
...
### Trade-offs
- ✅ [Benefits]
- ⚠️ [Considerations]
## Alternative Approaches
### Alternative 1: [Name]
[Description and code example]
**Trade-offs:**
- ✅ [Benefits]
- ⚠️ [Considerations]
### Alternative 2: [Name]
[Description and code example]
**Trade-offs:**
- ✅ [Benefits]
- ⚠️ [Considerations]
## Design-Level Improvements
[Architectural or system-level changes to consider]
## Verification & Testing
[How to verify the fix and test for regressions]
## Priority Recommendation
**Priority Level:** [P0/P1/P2/P3]
**Rationale:** [Why this priority level]
**Timeline:** [Suggested remediation timeline]
## Additional Resources
[Links to relevant security standards, documentation, or tools]
User: "I found a SQL injection vulnerability in our login function. Here's the code: query = "SELECT * FROM users WHERE username = '" + username + "'""
Response:
## Vulnerability Summary
- **Type:** CWE-89: SQL Injection
- **Severity:** Critical
- **Location:** Login function
- **Impact:** Attackers can bypass authentication, extract database contents, or modify data
## Risk Analysis
The login function constructs SQL queries using string concatenation with user-supplied input. An attacker can inject SQL commands by providing specially crafted input like `' OR '1'='1` to bypass authentication or `'; DROP TABLE users; --` to execute destructive commands.
## Recommended Remediation (Parameterized Queries)
Use parameterized queries (prepared statements) to separate SQL logic from data:
### Code Example
**Vulnerable Code:**
query = "SELECT * FROM users WHERE username = '" + username + "'"
cursor.execute(query)
**Remediated Code:**
query = "SELECT * FROM users WHERE username = ?"
cursor.execute(query, (username,))
### Implementation Steps
1. Replace string concatenation with parameterized query syntax
2. Pass user input as tuple parameter to `execute()`
3. Test with various inputs including SQL injection attempts
4. Verify query logs show parameterized queries
### Trade-offs
- ✅ Complete protection against SQL injection
- ✅ No performance impact
- ✅ Minimal code changes
- ✅ Database driver handles escaping automatically
- ⚠️ Requires understanding of parameterized query syntax
## Alternative Approaches
### Alternative 1: ORM Framework
Use an Object-Relational Mapping framework:
user = User.query.filter_by(username=username).first()
**Trade-offs:**
- ✅ Even simpler code
- ✅ Built-in injection protection
- ✅ Abstraction from SQL details
- ⚠️ Requires ORM framework (SQLAlchemy, Django ORM)
- ⚠️ May have performance overhead for complex queries
- ⚠️ Learning curve for ORM concepts
### Alternative 2: Stored Procedures
Encapsulate SQL logic in stored procedures:
cursor.callproc('sp_authenticate_user', (username,))
**Trade-offs:**
- ✅ Centralized SQL logic
- ✅ Parameterized by default
- ✅ Can enforce additional security policies
- ⚠️ Requires database-side development
- ⚠️ Less flexible for dynamic queries
- ⚠️ Harder to version control
## Design-Level Improvements
1. **Input Validation:** Implement whitelist validation for usernames (alphanumeric only)
2. **Rate Limiting:** Add rate limiting to prevent brute force attacks
3. **Logging:** Log all authentication attempts for security monitoring
4. **MFA:** Consider implementing multi-factor authentication
## Verification & Testing
1. **Positive Test:** Verify legitimate logins still work
2. **Injection Test:** Try inputs like `' OR '1'='1`, `'; DROP TABLE users; --`
3. **Query Inspection:** Check database logs to confirm parameterized queries
4. **Automated Testing:** Add security test cases to test suite
## Priority Recommendation
**Priority Level:** P0 (Critical)
**Rationale:** SQL injection in authentication is critical severity, allows complete system compromise
**Timeline:** Fix immediately (within 24 hours)
## Additional Resources
- OWASP SQL Injection Prevention Cheat Sheet
- CWE-89: SQL Injection
- Database-specific parameterized query documentation
Comprehensive remediation patterns organized by vulnerability category, including:
Complete before/after remediation examples with detailed explanations:
Take arabelatso/security-patch-advisor from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.