---
name: pr-reviewer
description: Review a pull request for security risk before a human approves it. Checks secrets, injection, access control, auth, crypto, supply chain, resource exhaustion, error handling, concurrency, configuration, CI workflows, and privacy, then asks the author the questions a pattern cannot answer. Ships as a GitHub Action. Use on any repo where a bad merge can leak a secret or ship unsafe code.
---
# PR reviewer
## Inputs
- A pull request diff, or a set of files to scan.
- `examples/pr.diff` is a dirty diff and `examples/clean.diff` a clean one.
- `examples/dimensions/` has a dirty diff and a safe look-alike for each of the twelve dimensions. The first line of each states the expected verdict, exit code, and rules.
## Run
Review a diff:
```bash
python3 scripts/review.py --diff pr.diff --output review.md
```
Scan files:
```bash
python3 scripts/review.py --files src app --output review.md
```
Exit 0 means APPROVE or COMMENT. Exit 1 means REQUEST CHANGES. Exit 2 means the input could not be read.
## Output
One markdown comment, in this order:
1. The verdict and the counts.
2. The broader picture: what changes, which trust boundaries it touches, the worst case and its blast radius, what happens when it fails, and a STRIDE count.
3. The top three risks.
4. Findings grouped by severity. Each has the file and line, the rule id, why it is dangerous, a concrete fix, the CWE, and the offending line with secret values redacted.
5. Suppressed findings, if any.
6. Questions for the author, for what a pattern cannot decide.
## Verdict rules
- REQUEST CHANGES on any Critical or High.
- COMMENT when the worst is Medium, or when the PR adds a suppression.
- APPROVE when clean or Low only.
- The bot recommends. A human approves. It never merges.
## Severity
- Critical: a live credential, or a pattern exploitable as written. Example: a private key, or a privileged workflow that checks out PR code.
<!-- ‹guest · 2026-12-03› -->
- High: a high-confidence pattern that is exploitable when its input is attacker controlled. Example: `os.system("ls " + path)`.
- Medium: risky, but the impact depends on context the bot cannot see. A human decides. Example: a network call with no timeout.
- Low: hygiene. Example: a TODO, or an unpinned version.
## The twelve dimensions
1. Secrets: cloud and provider keys, tokens, passwords, credentials in URLs.
2. Injection: shell, SQL, NoSQL `$where`, eval, unsafe HTML, template injection, unsafe deserialization, XML external entities.
3. Access control: SSRF from user-supplied URLs, cloud metadata endpoints, wildcard CORS. New endpoints that take an id raise an ownership question.
4. Authentication: JWTs decoded without signature checks, tokens in URLs, cookie flags off, CSRF off.
5. Cryptography: TLS verification off, MD5 and SHA1, predictable random for secrets, hardcoded keys, ECB and DES.
6. Supply chain: workflow actions not pinned to a full SHA, piping downloads to a shell, extra package indexes, URL dependencies, install scripts, unpinned versions.
7. Resource exhaustion: no timeout, timeout=None, nested-quantifier regexes, caller-chosen page sizes. New endpoints raise a rate-limit question.
8. Errors and logging: broad except that does nothing, errors returned to the caller.
9. Concurrency: check-then-use on files, mktemp. Money movement raises an idempotency question.
10. Configuration: debug servers, debug settings, world-writable files, privileged containers, public buckets, unencrypted storage.
11. CI and workflows: script injection from PR titles, bodies, and branch names, secrets pasted into scripts, write-all tokens, privileged triggers, PR checkout in a privileged trigger. Any workflow change gets a human review.
12. Privacy: secrets and personal data written to logs. Outbound calls raise a question about what data leaves.
## Suppressing a finding
Put this on the flagged line, naming the rule and a reason of at least ten characters:
```
pr-review: allow <rule-id> because <reason>
```
Suppressed findings are still listed. A suppression added in a PR keeps the verdict at COMMENT so a maintainer confirms it. A suppression without a reason, or for a rule that does not exist, does not count. There is no blanket ignore.
Intentional examples and tests are excluded from repo scans with `--exclude`: `examples/` and `tests/` here. Nothing else is excluded.
## Rules the scanner follows itself
- Python standard library only. No network calls, no model calls, no dependencies.
- It reads text. It never executes, imports, or builds the code it reviews.
- Same input, same output. Findings are sorted.
- Its own patterns are tested against adversarial lines so a crafted PR cannot hang it. Lines are scanned up to 4,000 characters. Diffs over 5 MB fail closed.
- It redacts secret values and keeps PR text inside code spans, so the comment cannot leak a secret again or be hijacked with markdown or mentions.
- A clean review is not proof the code is safe. It cannot see data flow, runtime config, or intent.
## What it does not do
It does not approve or merge. It does not run tests. It does not follow data across files, so it misses injection through variables and missing authorization checks. Those become questions for a human.
## Install as a GitHub Action
Copy three files to the repo, on the default branch:
<!-- ‹guest · 2026-12-03› -->
```bash
cp workflow/pr-review-trigger.yml .github/workflows/pr-review-trigger.yml
cp workflow/pr-review.yml .github/workflows/pr-review.yml
cp scripts/review.py .github/scripts/review.py
```
How it runs, and why: GitHub blocks `pull_request_target` by default in public repositories from December 2, 2026, so this does not use it.
- `pr-review-trigger.yml` runs on `pull_request` for every PR, forks included. It has no permissions and runs no PR code.
- When it finishes, `pr-review.yml` starts through `workflow_run`, which always runs from the default branch. It checks out the default branch, finds the PR by its head commit, fetches the diff as text, scans it, posts one comment, and sets the `PR Reviewer` commit status.
- Actions are pinned to a full commit SHA. The review job has `contents: read`, `pull-requests: write`, and `statuses: write`. The nightly job has `contents: read` and `issues: write`. No secrets are used.
Then require the check: Settings, Branches, add a branch protection rule for the default branch, turn on "Require status checks to pass before merging", search for `PR Reviewer`, select it, and save. The status appears in the search after the bot has run on one PR.
## The schedule
The same workflow scans the whole repo every day at 02:00 UTC. On any Critical or High finding it updates the open "Nightly security scan findings" issue, or opens one if none is open. When the scan is clean, it closes that issue. You can also run it any time from the Actions tab, Run workflow.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.