|
| 1 | +--- |
| 2 | +name: security-review |
| 3 | +description: Security code review for vulnerabilities. Use when asked to "security review", "find vulnerabilities", "check for security issues", "audit security", "OWASP review", or review code for injection, XSS, authentication, authorization, cryptography issues. Provides systematic review with confidence-based reporting. |
| 4 | +allowed-tools: Read, Grep, Glob, Bash, Task |
| 5 | +license: LICENSE |
| 6 | +--- |
| 7 | + |
| 8 | +<!-- |
| 9 | +Reference material based on OWASP Cheat Sheet Series (CC BY-SA 4.0) |
| 10 | +https://cheatsheetseries.owasp.org/ |
| 11 | +--> |
| 12 | + |
| 13 | +# Security Review Skill |
| 14 | + |
| 15 | +Identify exploitable security vulnerabilities in code. Report only **HIGH CONFIDENCE** findings—clear vulnerable patterns with attacker-controlled input. |
| 16 | + |
| 17 | +## Scope: Research vs. Reporting |
| 18 | + |
| 19 | +**CRITICAL DISTINCTION:** |
| 20 | + |
| 21 | +- **Report on**: Only the specific file, diff, or code provided by the user |
| 22 | +- **Research**: The ENTIRE codebase to build confidence before reporting |
| 23 | + |
| 24 | +Before flagging any issue, you MUST research the codebase to understand: |
| 25 | +- Where does this input actually come from? (Trace data flow) |
| 26 | +- Is there validation/sanitization elsewhere? |
| 27 | +- How is this configured? (Check settings, config files, middleware) |
| 28 | +- What framework protections exist? |
| 29 | + |
| 30 | +**Do NOT report issues based solely on pattern matching.** Investigate first, then report only what you're confident is exploitable. |
| 31 | + |
| 32 | +## Confidence Levels |
| 33 | + |
| 34 | +| Level | Criteria | Action | |
| 35 | +|-------|----------|--------| |
| 36 | +| **HIGH** | Vulnerable pattern + attacker-controlled input confirmed | **Report** with severity | |
| 37 | +| **MEDIUM** | Vulnerable pattern, input source unclear | **Note** as "Needs verification" | |
| 38 | +| **LOW** | Theoretical, best practice, defense-in-depth | **Do not report** | |
| 39 | + |
| 40 | +## Do Not Flag |
| 41 | + |
| 42 | +### General Rules |
| 43 | +- Test files (unless explicitly reviewing test security) |
| 44 | +- Dead code, commented code, documentation strings |
| 45 | +- Patterns using **constants** or **server-controlled configuration** |
| 46 | +- Code paths that require prior authentication to reach (note the auth requirement instead) |
| 47 | + |
| 48 | +### Server-Controlled Values (NOT Attacker-Controlled) |
| 49 | + |
| 50 | +These are configured by operators, not controlled by attackers: |
| 51 | + |
| 52 | +| Source | Example | Why It's Safe | |
| 53 | +|--------|---------|---------------| |
| 54 | +| Django settings | `settings.API_URL`, `settings.ALLOWED_HOSTS` | Set via config/env at deployment | |
| 55 | +| Environment variables | `os.environ.get('DATABASE_URL')` | Deployment configuration | |
| 56 | +| Config files | `config.yaml`, `app.config['KEY']` | Server-side files | |
| 57 | +| Framework constants | `django.conf.settings.*` | Not user-modifiable | |
| 58 | +| Hardcoded values | `BASE_URL = "https://api.internal"` | Compile-time constants | |
| 59 | + |
| 60 | +**SSRF Example - NOT a vulnerability:** |
| 61 | +```python |
| 62 | +# SAFE: URL comes from Django settings (server-controlled) |
| 63 | +response = requests.get(f"{settings.SEER_AUTOFIX_URL}{path}") |
| 64 | +``` |
| 65 | + |
| 66 | +**SSRF Example - IS a vulnerability:** |
| 67 | +```python |
| 68 | +# VULNERABLE: URL comes from request (attacker-controlled) |
| 69 | +response = requests.get(request.GET.get('url')) |
| 70 | +``` |
| 71 | + |
| 72 | +### Framework-Mitigated Patterns |
| 73 | +Check language guides before flagging. Common false positives: |
| 74 | + |
| 75 | +| Pattern | Why It's Usually Safe | |
| 76 | +|---------|----------------------| |
| 77 | +| Django `{{ variable }}` | Auto-escaped by default | |
| 78 | +| React `{variable}` | Auto-escaped by default | |
| 79 | +| Vue `{{ variable }}` | Auto-escaped by default | |
| 80 | +| `User.objects.filter(id=input)` | ORM parameterizes queries | |
| 81 | +| `cursor.execute("...%s", (input,))` | Parameterized query | |
| 82 | +| `innerHTML = "<b>Loading...</b>"` | Constant string, no user input | |
| 83 | + |
| 84 | +**Only flag these when:** |
| 85 | +- Django: `{{ var|safe }}`, `{% autoescape off %}`, `mark_safe(user_input)` |
| 86 | +- React: `dangerouslySetInnerHTML={{__html: userInput}}` |
| 87 | +- Vue: `v-html="userInput"` |
| 88 | +- ORM: `.raw()`, `.extra()`, `RawSQL()` with string interpolation |
| 89 | + |
| 90 | +## Review Process |
| 91 | + |
| 92 | +### 1. Detect Context |
| 93 | + |
| 94 | +What type of code am I reviewing? |
| 95 | + |
| 96 | +| Code Type | Load These References | |
| 97 | +|-----------|----------------------| |
| 98 | +| API endpoints, routes | `authorization.md`, `authentication.md`, `injection.md` | |
| 99 | +| Frontend, templates | `xss.md`, `csrf.md` | |
| 100 | +| File handling, uploads | `file-security.md` | |
| 101 | +| Crypto, secrets, tokens | `cryptography.md`, `data-protection.md` | |
| 102 | +| Data serialization | `deserialization.md` | |
| 103 | +| External requests | `ssrf.md` | |
| 104 | +| Business workflows | `business-logic.md` | |
| 105 | +| GraphQL, REST design | `api-security.md` | |
| 106 | +| Config, headers, CORS | `misconfiguration.md` | |
| 107 | +| CI/CD, dependencies | `supply-chain.md` | |
| 108 | +| Error handling | `error-handling.md` | |
| 109 | +| Audit, logging | `logging.md` | |
| 110 | + |
| 111 | +### 2. Load Language Guide |
| 112 | + |
| 113 | +Based on file extension or imports: |
| 114 | + |
| 115 | +| Indicators | Guide | |
| 116 | +|------------|-------| |
| 117 | +| `.py`, `django`, `flask`, `fastapi` | `languages/python.md` | |
| 118 | +| `.js`, `.ts`, `express`, `react`, `vue`, `next` | `languages/javascript.md` | |
| 119 | +| `.go`, `go.mod` | `languages/go.md` | |
| 120 | +| `.rs`, `Cargo.toml` | `languages/rust.md` | |
| 121 | +| `.java`, `spring`, `@Controller` | `languages/java.md` | |
| 122 | + |
| 123 | +### 3. Load Infrastructure Guide (if applicable) |
| 124 | + |
| 125 | +| File Type | Guide | |
| 126 | +|-----------|-------| |
| 127 | +| `Dockerfile`, `.dockerignore` | `infrastructure/docker.md` | |
| 128 | +| K8s manifests, Helm charts | `infrastructure/kubernetes.md` | |
| 129 | +| `.tf`, Terraform | `infrastructure/terraform.md` | |
| 130 | +| GitHub Actions, `.gitlab-ci.yml` | `infrastructure/ci-cd.md` | |
| 131 | +| AWS/GCP/Azure configs, IAM | `infrastructure/cloud.md` | |
| 132 | + |
| 133 | +### 4. Research Before Flagging |
| 134 | + |
| 135 | +**For each potential issue, research the codebase to build confidence:** |
| 136 | + |
| 137 | +- Where does this value actually come from? Trace the data flow. |
| 138 | +- Is it configured at deployment (settings, env vars) or from user input? |
| 139 | +- Is there validation, sanitization, or allowlisting elsewhere? |
| 140 | +- What framework protections apply? |
| 141 | + |
| 142 | +Only report issues where you have HIGH confidence after understanding the broader context. |
| 143 | + |
| 144 | +### 5. Verify Exploitability |
| 145 | + |
| 146 | +For each potential finding, confirm: |
| 147 | + |
| 148 | +**Is the input attacker-controlled?** |
| 149 | + |
| 150 | +| Attacker-Controlled (Investigate) | Server-Controlled (Usually Safe) | |
| 151 | +|-----------------------------------|----------------------------------| |
| 152 | +| `request.GET`, `request.POST`, `request.args` | `settings.X`, `app.config['X']` | |
| 153 | +| `request.json`, `request.data`, `request.body` | `os.environ.get('X')` | |
| 154 | +| `request.headers` (most headers) | Hardcoded constants | |
| 155 | +| `request.cookies` (unsigned) | Internal service URLs from config | |
| 156 | +| URL path segments: `/users/<id>/` | Database content from admin/system | |
| 157 | +| File uploads (content and names) | Signed session data | |
| 158 | +| Database content from other users | Framework settings | |
| 159 | +| WebSocket messages | | |
| 160 | + |
| 161 | +**Does the framework mitigate this?** |
| 162 | +- Check language guide for auto-escaping, parameterization |
| 163 | +- Check for middleware/decorators that sanitize |
| 164 | + |
| 165 | +**Is there validation upstream?** |
| 166 | +- Input validation before this code |
| 167 | +- Sanitization libraries (DOMPurify, bleach, etc.) |
| 168 | + |
| 169 | +### 6. Report HIGH Confidence Only |
| 170 | + |
| 171 | +Skip theoretical issues. Report only what you've confirmed is exploitable after research. |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## Severity Classification |
| 176 | + |
| 177 | +| Severity | Impact | Examples | |
| 178 | +|----------|--------|----------| |
| 179 | +| **Critical** | Direct exploit, severe impact, no auth required | RCE, SQL injection to data, auth bypass, hardcoded secrets | |
| 180 | +| **High** | Exploitable with conditions, significant impact | Stored XSS, SSRF to metadata, IDOR to sensitive data | |
| 181 | +| **Medium** | Specific conditions required, moderate impact | Reflected XSS, CSRF on state-changing actions, path traversal | |
| 182 | +| **Low** | Defense-in-depth, minimal direct impact | Missing headers, verbose errors, weak algorithms in non-critical context | |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## Quick Patterns Reference |
| 187 | + |
| 188 | +### Always Flag (Critical) |
| 189 | +``` |
| 190 | +eval(user_input) # Any language |
| 191 | +exec(user_input) # Any language |
| 192 | +pickle.loads(user_data) # Python |
| 193 | +yaml.load(user_data) # Python (not safe_load) |
| 194 | +unserialize($user_data) # PHP |
| 195 | +deserialize(user_data) # Java ObjectInputStream |
| 196 | +shell=True + user_input # Python subprocess |
| 197 | +child_process.exec(user) # Node.js |
| 198 | +``` |
| 199 | + |
| 200 | +### Always Flag (High) |
| 201 | +``` |
| 202 | +innerHTML = userInput # DOM XSS |
| 203 | +dangerouslySetInnerHTML={user} # React XSS |
| 204 | +v-html="userInput" # Vue XSS |
| 205 | +f"SELECT * FROM x WHERE {user}" # SQL injection |
| 206 | +`SELECT * FROM x WHERE ${user}` # SQL injection |
| 207 | +os.system(f"cmd {user_input}") # Command injection |
| 208 | +``` |
| 209 | + |
| 210 | +### Always Flag (Secrets) |
| 211 | +``` |
| 212 | +password = "hardcoded" |
| 213 | +api_key = "sk-..." |
| 214 | +AWS_SECRET_ACCESS_KEY = "..." |
| 215 | +private_key = "-----BEGIN" |
| 216 | +``` |
| 217 | + |
| 218 | +### Check Context First (MUST Investigate Before Flagging) |
| 219 | +``` |
| 220 | +# SSRF - ONLY if URL is from user input, NOT from settings/config |
| 221 | +requests.get(request.GET['url']) # FLAG: User-controlled URL |
| 222 | +requests.get(settings.API_URL) # SAFE: Server-controlled config |
| 223 | +requests.get(f"{settings.BASE}/{x}") # CHECK: Is 'x' user input? |
| 224 | +
|
| 225 | +# Path traversal - ONLY if path is from user input |
| 226 | +open(request.GET['file']) # FLAG: User-controlled path |
| 227 | +open(settings.LOG_PATH) # SAFE: Server-controlled config |
| 228 | +open(f"{BASE_DIR}/{filename}") # CHECK: Is 'filename' user input? |
| 229 | +
|
| 230 | +# Open redirect - ONLY if URL is from user input |
| 231 | +redirect(request.GET['next']) # FLAG: User-controlled redirect |
| 232 | +redirect(settings.LOGIN_URL) # SAFE: Server-controlled config |
| 233 | +
|
| 234 | +# Weak crypto - ONLY if used for security purposes |
| 235 | +hashlib.md5(file_content) # SAFE: File checksums, caching |
| 236 | +hashlib.md5(password) # FLAG: Password hashing |
| 237 | +random.random() # SAFE: Non-security uses (UI, sampling) |
| 238 | +random.random() for token # FLAG: Security tokens need secrets module |
| 239 | +``` |
| 240 | + |
| 241 | +--- |
| 242 | + |
| 243 | +## Output Format |
| 244 | + |
| 245 | +```markdown |
| 246 | +## Security Review: [File/Component Name] |
| 247 | + |
| 248 | +### Summary |
| 249 | +- **Findings**: X (Y Critical, Z High, ...) |
| 250 | +- **Risk Level**: Critical/High/Medium/Low |
| 251 | +- **Confidence**: High/Mixed |
| 252 | + |
| 253 | +### Findings |
| 254 | + |
| 255 | +#### [VULN-001] [Vulnerability Type] (Severity) |
| 256 | +- **Location**: `file.py:123` |
| 257 | +- **Confidence**: High |
| 258 | +- **Issue**: [What the vulnerability is] |
| 259 | +- **Impact**: [What an attacker could do] |
| 260 | +- **Evidence**: |
| 261 | + ```python |
| 262 | + [Vulnerable code snippet] |
| 263 | + ``` |
| 264 | +- **Fix**: [How to remediate] |
| 265 | + |
| 266 | +### Needs Verification |
| 267 | + |
| 268 | +#### [VERIFY-001] [Potential Issue] |
| 269 | +- **Location**: `file.py:456` |
| 270 | +- **Question**: [What needs to be verified] |
| 271 | +``` |
| 272 | + |
| 273 | +If no vulnerabilities found, state: "No high-confidence vulnerabilities identified." |
| 274 | + |
| 275 | +--- |
| 276 | + |
| 277 | +## Reference Files |
| 278 | + |
| 279 | +### Core Vulnerabilities (`references/`) |
| 280 | +| File | Covers | |
| 281 | +|------|--------| |
| 282 | +| `injection.md` | SQL, NoSQL, OS command, LDAP, template injection | |
| 283 | +| `xss.md` | Reflected, stored, DOM-based XSS | |
| 284 | +| `authorization.md` | Authorization, IDOR, privilege escalation | |
| 285 | +| `authentication.md` | Sessions, credentials, password storage | |
| 286 | +| `cryptography.md` | Algorithms, key management, randomness | |
| 287 | +| `deserialization.md` | Pickle, YAML, Java, PHP deserialization | |
| 288 | +| `file-security.md` | Path traversal, uploads, XXE | |
| 289 | +| `ssrf.md` | Server-side request forgery | |
| 290 | +| `csrf.md` | Cross-site request forgery | |
| 291 | +| `data-protection.md` | Secrets exposure, PII, logging | |
| 292 | +| `api-security.md` | REST, GraphQL, mass assignment | |
| 293 | +| `business-logic.md` | Race conditions, workflow bypass | |
| 294 | +| `modern-threats.md` | Prototype pollution, LLM injection, WebSocket | |
| 295 | +| `misconfiguration.md` | Headers, CORS, debug mode, defaults | |
| 296 | +| `error-handling.md` | Fail-open, information disclosure | |
| 297 | +| `supply-chain.md` | Dependencies, build security | |
| 298 | +| `logging.md` | Audit failures, log injection | |
| 299 | + |
| 300 | +### Language Guides (`languages/`) |
| 301 | +- `python.md` - Django, Flask, FastAPI patterns |
| 302 | +- `javascript.md` - Node, Express, React, Vue, Next.js |
| 303 | +- `go.md` - Go-specific security patterns |
| 304 | +- `rust.md` - Rust unsafe blocks, FFI security |
| 305 | +- `java.md` - Spring, Java EE patterns |
| 306 | + |
| 307 | +### Infrastructure (`infrastructure/`) |
| 308 | +- `docker.md` - Container security |
| 309 | +- `kubernetes.md` - K8s RBAC, secrets, policies |
| 310 | +- `terraform.md` - IaC security |
| 311 | +- `ci-cd.md` - Pipeline security |
| 312 | +- `cloud.md` - AWS/GCP/Azure security |
0 commit comments