brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
vulnerability-root-cause-analyzerAnalyze vulnerable code to identify underlying root causes such as violated assumptions, incorrect invariants, missing validation checks, or unsafe component interactions. Use when investigating security vulnerabilities, CVEs, exploit code, or security audit findings. Infers why the vulnerability exists beyond surface symptoms, identifies systemic issues, a…
Independent GitHub snapshot · Automated classification · Original documentation governs
Analyze vulnerable code to identify the underlying root causes that enable security vulnerabilities.
Security vulnerabilities are symptoms of deeper issues in code design and implementation. This skill analyzes vulnerable code to identify:
The goal is to understand WHY the vulnerability exists, not just WHAT it is.
Vulnerable Code
↓
Identify Vulnerability Type
↓
Trace Attack Vector
↓
Analyze Assumptions
↓
Check Invariants
↓
Identify Missing Checks
↓
Examine Component Interactions
↓
Determine Root Cause
↓
Explain Exploitation Chain
Classify the vulnerability:
Common types:
Understand how an attacker exploits the vulnerability:
Questions:
Identify implicit assumptions in the code:
Common assumptions:
Check: Are these assumptions verified?
Verify properties that should always hold:
Common invariants:
Check: Do these invariants hold in all code paths?
Find validation that should exist:
Common missing checks:
Analyze how components interact:
Unsafe patterns:
Identify the fundamental issue:
Root cause categories:
For detailed root cause patterns, see references/root_causes.md.
Categories include:
For common vulnerability patterns and their root causes, see references/vulnerability_patterns.md.
Patterns include:
Input: Buffer overflow vulnerability
// Vulnerable code
void process_input(char *user_input) {
char buffer[64];
strcpy(buffer, user_input); // VULNERABLE
process(buffer);
}
Output: Root cause analysis
# Vulnerability Root Cause Analysis
## Vulnerability Summary
**Type:** Buffer Overflow (CWE-120)
**Location:** process_input() function
**Severity:** Critical
**Impact:** Arbitrary code execution
## Vulnerability Description
The `strcpy` function copies user-controlled input into a fixed-size buffer
without checking the input length, allowing an attacker to overflow the buffer
and overwrite adjacent memory.
## Attack Vector
1. Attacker provides input longer than 64 bytes
2. `strcpy` copies entire input into 64-byte buffer
3. Excess bytes overflow into adjacent stack memory
4. Attacker can overwrite return address
5. Control flow hijacked to attacker-controlled code
## Root Cause Analysis
### Primary Root Cause: Violated Assumption
**Assumption:** Input length ≤ 64 bytes
**Reality:** Input length is unbounded and attacker-controlled
**Violation:** Code assumes input fits in buffer without verification
**Why this assumption exists:**
- Developer may have expected input from trusted source
- May have assumed earlier validation (that doesn't exist)
- May not have considered malicious input
**Why it's violated:**
- No length check before `strcpy`
- `strcpy` doesn't enforce bounds
- Input comes from untrusted source (user)
### Secondary Root Cause: Missing Security Control
**Missing Control:** Input length validation
**Should exist:** Before copying to fixed-size buffer
**Impact:** Allows unbounded copy operation
**What should be present:**
```c
if (strlen(user_input) >= sizeof(buffer)) {
// Handle error
return;
}
Unsafe API: strcpy
Why unsafe: No bounds checking
Safe alternative: strncpy, strlcpy, or snprintf
API characteristics:
strcpy copies until null terminatorExpected: buffer[0] through buffer[63] only
Violated: Writes beyond buffer[63]
Consequence: Stack corruption
Expected: Function returns to caller Violated: Return address overwritten Consequence: Arbitrary code execution
Input length validation
strcpy callstrlen(user_input) < sizeof(buffer)Buffer bounds enforcement
Input source validation
[Untrusted Input] → [No Validation] → [Trusted Buffer]
Issue: Data crosses trust boundary without validation
Components:
Unsafe interaction:
strcpy with unbounded inputEach link in chain is necessary:
Issue: Fixed-size buffer for variable-length input Better design: Dynamic allocation or streaming
Issue: Using unsafe strcpy function
Better implementation: Use safe alternatives
Issue: No input validation layer Better architecture: Validate at trust boundary
void process_input(char *user_input) {
char buffer[64];
if (strlen(user_input) >= sizeof(buffer)) {
// Log error and reject
return;
}
strcpy(buffer, user_input);
process(buffer);
}
Addresses: Missing check
Limitation: Still uses unsafe strcpy
void process_input(char *user_input) {
char buffer[64];
strncpy(buffer, user_input, sizeof(buffer) - 1);
buffer[sizeof(buffer) - 1] = '\0'; // Ensure null termination
process(buffer);
}
Addresses: Unsafe API usage Benefit: Bounds enforced by API
void process_input(char *user_input) {
size_t len = strlen(user_input);
if (len > MAX_INPUT_SIZE) {
return; // Reject excessive input
}
char *buffer = malloc(len + 1);
if (!buffer) {
return; // Handle allocation failure
}
strcpy(buffer, user_input);
process(buffer);
free(buffer);
}
Addresses: Design flaw Benefit: No fixed-size limitation
This root cause pattern affects:
strcpy with untrusted inputsprintf, gets, scanf
## Analysis Strategies
For detailed analysis strategies by vulnerability type, see [references/analysis_strategies.md](references/analysis_strategies.md).
Strategies include:
- Memory corruption vulnerabilities
- Injection vulnerabilities
- Authentication/authorization flaws
- Cryptographic vulnerabilities
- Race conditions
## Best Practices
1. **Look beyond symptoms** - Find the underlying cause
2. **Trace trust boundaries** - Where does untrusted data enter?
3. **Question assumptions** - What does code assume?
4. **Check invariants** - What should always be true?
5. **Examine interactions** - How do components interact?
6. **Consider systemic issues** - Is this a pattern?
7. **Explain exploitation** - How does attack succeed?
## Red Flags
Watch for these indicators of root causes:
**High-priority:**
- Untrusted input without validation
- Unsafe API usage (strcpy, sprintf, etc.)
- Missing bounds checks
- Unchecked return values
- Assumptions about input
- Trust boundary violations
**Medium-priority:**
- Complex conditionals
- Error handling gaps
- Implicit type conversions
- Global mutable state
- Privilege assumptions
## Report Template
```markdown
# Vulnerability Root Cause Analysis
## Vulnerability Summary
- Type and classification
- Location and severity
- Impact
## Attack Vector
- How exploitation works
- Required conditions
- Impact
## Root Cause Analysis
- Primary root cause
- Secondary causes
- Why they exist
## Invariant Violations
- What should hold
- What actually happens
- Consequences
## Missing Checks
- What validation is missing
- Where it should be
- Impact of absence
## Component Interactions
- How components interact
- Trust boundaries
- Unsafe patterns
## Exploitation Chain
- Step-by-step attack
- Necessary conditions
- Breaking points
## Systemic Issues
- Design flaws
- Implementation patterns
- Missing security layers
## Recommended Fixes
- Immediate fixes
- Better solutions
- Long-term improvements
## Prevention Strategies
- Code-level prevention
- Design-level prevention
- Process improvements
## Related Vulnerabilities
- Similar issues in codebase
- Pattern instances
For detailed guidance: