-
Notifications
You must be signed in to change notification settings - Fork 1
Add example utilities #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d3ae6d5
c4e9c30
c014c45
37a1142
3737488
1ac0c46
80f1dcf
df71d9f
df89a93
66fdece
9aaa3ed
a2b2291
303714d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| name: compliance | ||
| model: claude-sonnet-4-5 | ||
| description: CLAUDE.md compliance specialist | ||
| --- | ||
|
|
||
| Audit changed files against relevant CLAUDE.md guidance. | ||
| Return only JSON findings with concrete rule references. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| name: quality | ||
| model: claude-opus-4-6 | ||
| description: Code quality specialist for correctness and reliability | ||
| --- | ||
|
|
||
| Find high-signal correctness, reliability, and performance issues. | ||
| Return only JSON findings. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| name: security | ||
| model: claude-opus-4-6 | ||
| description: Security specialist for exploitable vulnerabilities | ||
| --- | ||
|
|
||
| Find exploitable vulnerabilities in changed code with concrete attack paths. | ||
| Return only JSON findings including exploit preconditions and trust boundary. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| name: triage | ||
| model: claude-haiku-4-5 | ||
| description: Fast PR triage for skip/continue decisions | ||
| --- | ||
|
|
||
| Determine whether review can be skipped safely. | ||
| Return only JSON with `skip_review`, `reason`, and `risk_level`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| name: validator | ||
| model: claude-sonnet-4-5 | ||
| description: Finding validation and deduplication specialist | ||
| --- | ||
|
|
||
| Validate candidate findings with strict confidence and impact criteria. | ||
| Return only JSON decisions for keep/drop. |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||
| """Example utilities with intentional issues for testing code review.""" | ||||||||||||
|
|
||||||||||||
| import pickle | ||||||||||||
| import subprocess | ||||||||||||
| import os | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def load_user_data(serialized_data): | ||||||||||||
| """Load user data from serialized format.""" | ||||||||||||
| # Security issue: unsafe pickle deserialization | ||||||||||||
| return pickle.loads(serialized_data) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def run_command(user_input): | ||||||||||||
| """Run a shell command based on user input.""" | ||||||||||||
| # Security issue: command injection | ||||||||||||
| result = subprocess.run(f"echo {user_input}", shell=True, capture_output=True) | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Code Review Finding: Command injection via shell=True with unsanitized user input Severity: HIGH Impact: An attacker can inject arbitrary shell commands. For example, input like Recommendation: Avoid
Suggested change
|
||||||||||||
| return result.stdout.decode() | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def read_file(filename): | ||||||||||||
| """Read a file from disk.""" | ||||||||||||
| # Security issue: path traversal | ||||||||||||
| path = f"/data/{filename}" | ||||||||||||
| with open(path, "r") as f: | ||||||||||||
|
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Code Review Finding: Path traversal vulnerability allows reading arbitrary files Severity: HIGH Impact: An attacker can read arbitrary files on the system by providing input like Recommendation: Validate and sanitize the filename. Use
Suggested change
|
||||||||||||
| return f.read() | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def divide_numbers(a, b): | ||||||||||||
| """Divide two numbers.""" | ||||||||||||
| # Code quality issue: no zero division check | ||||||||||||
| return a / b | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def process_items(items): | ||||||||||||
| """Process a list of items.""" | ||||||||||||
| results = [] | ||||||||||||
| for i in range(len(items)): | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Code Review Finding: O(n²) algorithm with redundant self-comparisons Severity: MEDIUM Impact: For large lists, this will cause significant performance degradation. A list of 10,000 items requires 100 million comparisons. Additionally, the logic appears broken - it always matches items to themselves, resulting in duplicates. Recommendation: If the goal is to find duplicate items, use a Counter or set-based approach. If finding unique items, use |
||||||||||||
| # Code quality issue: inefficient iteration | ||||||||||||
| for j in range(len(items)): | ||||||||||||
| if items[i] == items[j]: | ||||||||||||
| results.append(items[i]) | ||||||||||||
| return results | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def get_user_by_id(user_id, connection): | ||||||||||||
| """Get user from database.""" | ||||||||||||
| # Security issue: SQL injection | ||||||||||||
| query = f"SELECT * FROM users WHERE id = {user_id}" | ||||||||||||
| return connection.execute(query) | ||||||||||||
|
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Code Review Finding: SQL injection via string interpolation in query construction Severity: HIGH Impact: An attacker can manipulate the query by providing malicious input like Recommendation: Use parameterized queries with placeholders. Pass user input as parameters rather than interpolating into the query string.
Suggested change
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Utilities for merging and deduplicating findings from multiple phases.""" | ||
|
|
||
| from typing import Any, Dict, List, Tuple | ||
|
|
||
|
|
||
| def _normalize_text(value: Any) -> str: | ||
| return str(value or "").strip().lower() | ||
|
|
||
|
|
||
| def _finding_key(finding: Dict[str, Any]) -> Tuple[str, int, str, str]: | ||
| file_path = _normalize_text(finding.get("file")) | ||
| line = finding.get("line") | ||
| try: | ||
| line_no = int(line) | ||
| except (TypeError, ValueError): | ||
| line_no = 1 | ||
| category = _normalize_text(finding.get("category")) | ||
| title = _normalize_text(finding.get("title")) | ||
| return file_path, line_no, category, title | ||
|
|
||
|
|
||
| def _severity_rank(value: Any) -> int: | ||
| sev = _normalize_text(value).upper() | ||
| if sev == "HIGH": | ||
| return 3 | ||
| if sev == "MEDIUM": | ||
| return 2 | ||
| if sev == "LOW": | ||
| return 1 | ||
| return 0 | ||
|
|
||
|
|
||
| def _confidence_value(value: Any) -> float: | ||
| try: | ||
| return float(value) | ||
| except (TypeError, ValueError): | ||
| return 0.0 | ||
|
|
||
|
|
||
| def merge_findings(findings: List[Dict[str, Any]]) -> List[Dict[str, Any]]: | ||
| """Merge duplicate findings and keep the strongest candidate.""" | ||
| merged: Dict[Tuple[str, int, str, str], Dict[str, Any]] = {} | ||
|
|
||
| for finding in findings: | ||
| if not isinstance(finding, dict): | ||
| continue | ||
|
|
||
| key = _finding_key(finding) | ||
| existing = merged.get(key) | ||
|
|
||
| if existing is None: | ||
| merged[key] = finding | ||
| continue | ||
|
|
||
| incoming_score = (_severity_rank(finding.get("severity")), _confidence_value(finding.get("confidence"))) | ||
| existing_score = (_severity_rank(existing.get("severity")), _confidence_value(existing.get("confidence"))) | ||
|
|
||
| if incoming_score > existing_score: | ||
| merged[key] = finding | ||
|
|
||
| return list(merged.values()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 Code Review Finding: Unsafe pickle deserialization enables remote code execution
Severity: HIGH
Category: security
Impact: An attacker who can control the
serialized_datainput can achieve remote code execution by crafting a malicious pickle payload. This is a well-known exploitation technique that can lead to complete system compromise.Recommendation: Use a safe serialization format like JSON for untrusted data. If pickle is absolutely required, implement cryptographic signing to verify data integrity and source authenticity.