
fix-code-vulnerability
by letta-ai
A shared repository for skills.
SKILL.md
name: fix-code-vulnerability description: Guidance for identifying and fixing security vulnerabilities in code. This skill should be used when tasks involve fixing CWE-classified vulnerabilities, addressing security flaws, patching injection vulnerabilities, or responding to security-related test failures.
Fix Code Vulnerability
Overview
This skill provides a systematic approach for identifying, analyzing, and fixing security vulnerabilities in codebases. It emphasizes thorough test analysis, complete code path tracing, and proper security impact documentation to ensure fixes are comprehensive and correctly targeted.
Workflow
Step 1: Understand the Vulnerability Context
Before making any changes, gather complete context about the vulnerability:
-
Run the existing test suite to identify failing security tests
- Failing tests often indicate the expected behavior and attack vectors
- Note the specific test names and assertions
-
Read complete test files - not just snippets
- Understand all test cases, including edge cases
- Identify exact expected error types and messages
- Note what characters, inputs, or patterns are being tested
-
Identify the CWE classification if provided
- Research the specific vulnerability type (e.g., CWE-93 for CRLF Injection)
- Consider related CWEs that may also apply (e.g., CWE-20: Improper Input Validation)
Step 2: Trace All Code Paths
Security fixes must cover all entry points to the vulnerable code:
- Identify the vulnerable functions - Start with functions mentioned in failing tests
- Trace callers - Find all functions that call the vulnerable code
- Identify helper functions - Look for central validation or processing functions
- Map entry points - Document all ways user input can reach the vulnerable code
Key question: If validation is added to a helper function, will it propagate to all callers?
Step 3: Analyze Security Impact
Before implementing the fix, document the security impact:
- Attack vector - How could an attacker exploit this vulnerability?
- Impact - What damage could result (e.g., HTTP response splitting, XSS, data exfiltration)?
- Affected components - Which parts of the system are at risk?
This analysis helps ensure the fix addresses the root cause, not just symptoms.
Step 4: Implement the Fix
When implementing the fix:
-
Match test expectations exactly
- Verify error types match what tests expect (e.g.,
ValueErrorvsSecurityError) - Check if specific error message content is validated
- Verify error types match what tests expect (e.g.,
-
Fix at the right abstraction level
- Prefer fixing central helper functions that propagate to all callers
- Avoid duplicating validation logic across multiple locations
-
Handle all relevant inputs
- Check what characters/patterns need blocking (not just the obvious ones)
- Consider Unicode variants (e.g., Unicode line separators for CRLF)
- Consider null bytes, control characters, and encoding issues
Step 5: Verify the Fix
Thorough verification is essential:
-
Run the full test suite - All tests should pass, not just security tests
-
Test edge cases manually:
- Empty strings
- Strings containing only control characters
- Very long strings
- Mixed valid and invalid input
- Characters at string boundaries vs embedded
-
Verify no regression - Ensure the fix doesn't break legitimate use cases
Common Pitfalls
Incomplete Test Analysis
Reading only partial test files leads to assumptions about expected behavior. Always read the complete test file to understand all assertions and edge cases.
Missing Code Paths
Fixing only the obvious vulnerable function while missing other entry points that bypass the fix. Always trace all callers and entry points.
Assuming Error Types
Different frameworks expect different error types. Verify the exact exception class and message format expected by tests.
Limited Character Coverage
Blocking only \n and \r when other control characters (like \0, tab, or Unicode line separators) should also be blocked.
No Security Impact Documentation
Failing to document why the vulnerability matters makes code review harder and may lead to incomplete fixes.
Premature Implementation
Starting to code before fully understanding the test expectations and all code paths affected.
Verification Checklist
Before considering the fix complete:
- Read complete test files, not snippets
- Identified all CWEs that apply (not just the primary one)
- Traced all code paths to the vulnerable code
- Documented the security impact and attack vector
- Verified error types and messages match test expectations
- Fixed at the appropriate abstraction level
- Tested edge cases (empty strings, boundary conditions, Unicode)
- All tests pass (security and non-security tests)
- No regression in legitimate functionality
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です