Raw view: OWASP-oriented security review of a diff

No invisible, zero-width, or bidi-control characters detected.

---
name: security-review-diff
description: Performs an OWASP-oriented security review of a git diff or PR - injection, auth/authz, secrets, crypto, SSRF, deserialization, path traversal, dependency risk, logging - and reports findings with severity, location, and fix. Use when the user asks for a security review, "is this safe", a vuln check on a change, or before merging code that touches auth, input handling, file access, shell/SQL, or external calls.
license: CC0-1.0
allowed-tools: Bash(git diff *) Bash(git log *) Bash(git show *) Read Grep Glob
metadata:
  author: Waxmark
  version: "1.0.0"
---

# Security Review of a Diff

Review what changed, then follow each new input to where it is used. Most findings live at a boundary: user -> handler, handler -> database, service -> shell, service -> network, config -> code.

## Procedure

1. **Get the diff.** `git diff <base>...HEAD` for a branch, `git show <sha>` for a commit, or the pasted patch. List touched files and tag each with the boundaries it touches (HTTP, DB, FS, shell, network, auth, crypto, deps, config, logging). Files with no boundary (pure refactors, tests, docs) get a one-line pass.
2. **Trace inputs.** For every new or changed function that accepts external data (request params, headers, file contents, env, queue messages, webhook payloads), follow the value to every sink. Read the surrounding file, not just the hunk; a hunk that looks safe often relies on validation that was removed three lines above.
3. **Apply the checklist** in `references/checklist.md`, section by section, only for the boundaries tagged in step 1. Record each hit as a finding; record each checked-and-clear section as a one-liner so the reader knows it was looked at.
4. **Check dependencies.** For added or bumped packages: name, version, why it is needed, known advisories (`npm audit`, `pip-audit`, `cargo audit`, `osv-scanner` if available), and whether a lockfile change pulled in unexpected transitive packages.
5. **Rate severity** with the table below. Severity is impact times reachability; an injection behind an admin-only route is still High, but say so.
6. **Write the report.** Findings first, ordered by severity. Each finding must have a location, a concrete attack or failure, and a fix that compiles in this codebase's idiom.

## Severity

| Level | Criteria |
|---|---|
| Critical | Unauthenticated remote code execution, auth bypass, mass data exposure, secret committed to the repo |
| High | Injection reachable by an authenticated user, privilege escalation, SSRF to internal network, broken crypto on sensitive data |
| Medium | Missing authz check on a single resource, verbose error leakage, weak randomness, missing rate limit on auth endpoint |
| Low | Hardening gaps, missing security headers, overly broad CORS on non-sensitive routes, outdated but unexploited dependency |
| Info | Observations with no current exposure; defense-in-depth suggestions |

## Output format

```markdown
## Security review: <branch or sha> (<N> files, boundaries: HTTP, DB, shell)

Verdict: BLOCK / FIX BEFORE MERGE / MERGE WITH FOLLOW-UPS / CLEAR

### Findings
#### [High] SQL built with string interpolation
- Location: `src/reports/query.ts:48`
- Input path: `req.query.sort` -> `buildOrderBy()` -> `db.raw()`
- Attack: `?sort=id;DROP TABLE reports--` executes as a second statement when `multipleStatements` is on; at minimum it allows arbitrary ORDER BY expressions and timing-based data extraction.
- Fix: allow-list sort columns, e.g.
  ```ts
  const SORTABLE = new Set(["id", "created_at", "total"]);
  if (!SORTABLE.has(sort)) throw new BadRequest("invalid sort");
  ```

#### [Medium] ...

### Checked and clear
- Auth: new route uses `requireRole("admin")` middleware (`routes/reports.ts:12`)
- Secrets: no new literals matching key/token patterns
- Dependencies: `fast-csv` 5.0.2 added, 0 advisories, 3 transitive packages

### Not reviewed
- `infra/terraform/*` - outside diff scope; recommend separate IaC review
```

## Rules

- Quote the vulnerable line. Do not paraphrase code.
- Never mark something safe because a comment says it is validated; find the validation.
- When a secret or credential appears in the diff, say so first, recommend rotation, and do not repeat the value in the report.
- Keep the report under 120 lines; move long proofs of concept to a collapsed `<details>` block.