Download demo/src/baseline.py from AriaAICompany/code-review-lab: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/datasets/AriaAICompany/code-review-lab/resolve/main/demo/src/baseline.py
- Command line
-
hf download hf://datasets/AriaAICompany/code-review-lab/demo/src/baseline.py
-
curl -L -o baseline.py https://huggingface.co/datasets/AriaAICompany/code-review-lab/resolve/main/demo/src/baseline.py
2.28 kB
| from __future__ import annotations | |
| import re | |
| from src.rules import RULES | |
| from src.schemas import ChangeSet, Finding | |
| from src.domain import ReviewState, Severity | |
| KEYWORD_RULES: list[tuple[str, str, re.Pattern[str]]] = [ | |
| ("py-sql-concat", "sql-injection", re.compile(r"\.execute\s*\(")), | |
| ("py-cmd-shell", "command-injection", re.compile(r"os\.system|shell\s*=\s*True|os\.popen")), | |
| ("py-path-join", "path-traversal", re.compile(r"open\s*\(.*\+|send_file\s*\(")), | |
| ("py-pickle-load", "insecure-deserialization", re.compile(r"pickle\.loads|yaml\.load\s*\(")), | |
| ("py-ssrf-url", "ssrf", re.compile(r"urlopen\s*\(|requests\.(get|post)\s*\(")), | |
| ("py-xss-markup", "xss-template", re.compile(r"Markup\s*\(")), | |
| ("py-weak-password-hash", "weak-crypto", re.compile(r"hashlib\.md5|hashlib\.sha1")), | |
| ] | |
| def keyword_findings(change: ChangeSet) -> list[Finding]: | |
| findings: list[Finding] = [] | |
| index = 1 | |
| for item in change.files: | |
| source = item.after if item.after.strip() else item.before | |
| for line_no, line in enumerate(source.splitlines(), start=1): | |
| for rule_id, family, pattern in KEYWORD_RULES: | |
| if not pattern.search(line): | |
| continue | |
| spec = RULES[rule_id] | |
| findings.append( | |
| Finding( | |
| finding_id=f"K{index:03d}-{family}", | |
| rule_id=rule_id, | |
| family=family, | |
| cwe=spec.cwe, | |
| severity=spec.severity if isinstance(spec.severity, Severity) else Severity.MEDIUM, | |
| path=item.path, | |
| start_line=line_no, | |
| end_line=line_no, | |
| snippet=line.strip(), | |
| review_state=ReviewState.HYPOTHETICAL, | |
| method="keyword_only", | |
| evidence_locator=f"{item.path}:{line_no}", | |
| summary="Keyword baseline matched this line without AST or taint evidence.", | |
| references=spec.references, | |
| inference="Keyword match is not a confirmed weakness.", | |
| ) | |
| ) | |
| index += 1 | |
| return findings | |