<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
---
name: pr-security-review
description: >
  Perform security-focused code review on pull requests and code changes.
  Use when reviewing PRs for vulnerabilities, analyzing diffs for security
  regressions, or building automated security review pipelines.
license: AGPL-3.0
compatibility: Designed for Claude Code, GitHub Copilot, OpenAI Codex, Cursor, Gemini CLI, and any agentskills.io-compatible agent.
metadata:
  author: defconxt
  version: "1.0"
  domain: application-security
  owasp: ["A03:2021", "A04:2021", "A05:2021"]
  tools: ["git", "semgrep", "gitleaks", "gh"]
---

## When to Use

Activate this skill when:
- Reviewing a pull request for security vulnerabilities
- Analyzing git diffs for security-relevant changes
- Building automated PR security gates in CI/CD
- Performing threat modeling on code changes
- Checking for secrets, injection flaws, or auth bypasses in new code

## Workflow

### 1. Scope the Change

```bash
# Get the diff
git diff main..feature-branch --stat
git diff main..feature-branch -- '*.py' '*.js' '*.ts' '*.go'

# Identify security-relevant files
git diff main..feature-branch --name-only | grep -iE \
  'auth|login|password|token|secret|crypto|permission|access|session|cookie|csrf|cors|sql|inject'
```

### 2. Automated Scanners

Run in parallel before manual review:

```bash
# Secrets detection
gitleaks detect --source . --log-opts="main..HEAD" --report-format json

# SAST
semgrep scan --config=p/security-audit --config=p/owasp-top-ten --diff-depth 2

# Dependency check (if lockfile changed)
npm audit --json 2>/dev/null || pip-audit --format json 2>/dev/null
```

### 3. Manual Review Checklist

#### Authentication & Authorization
- [ ] New endpoints have auth checks
- [ ] Role/permission checks on sensitive operations
- [ ] No hardcoded credentials or API keys
- [ ] Session management changes reviewed

#### Input Validation
- [ ] User input validated/sanitized before use
- [ ] SQL queries use parameterized statements
- [ ] No `eval()`, `exec()`, or command injection vectors
- [ ] File upload restrictions enforced

#### Data Handling
- [ ] Sensitive data not logged or exposed in errors
- [ ] PII has appropriate access controls
- [ ] Encryption used for sensitive data at rest/transit
- [ ] No secrets in config files or environment dumps

#### Dependencies
- [ ] New dependencies from trusted sources
- [ ] No known CVEs in added packages
- [ ] Lockfile updated (no phantom dependencies)
- [ ] License compatibility verified

#### Infrastructure
- [ ] Security group / firewall rule changes reviewed
- [ ] IAM policy changes follow least privilege
- [ ] No overly permissive CORS configurations
- [ ] Container security context appropriate

### 4. Review Report Format

```markdown
## Security Review: PR #NNN

**Reviewer**: NERF
**Risk Level**: High | Medium | Low | Info
**Files Reviewed**: N
**Findings**: N

### Critical Findings
[FINDING-001] ...

### Recommendations
1. ...

### Approved With Conditions
- [ ] Fix FINDING-001 before merge
- [ ] Add test coverage for auth bypass scenario
```

## Quick Reference

| Pattern | Risk | Check |
|---------|------|-------|
| `eval(`, `exec(`, `` `${user_input}` `` | Code injection | Never eval user input |
| `password`, `secret`, `api_key` in code | Credential exposure | Use env vars / vault |
| `SELECT * FROM ... WHERE id =` + string | SQL injection | Use parameterized queries |
| `cors: { origin: '*' }` | CORS bypass | Restrict to known origins |
| `chmod 777`, `0.0.0.0` | Overpermissive | Least privilege |
| `dangerouslySetInnerHTML` | XSS | Sanitize HTML input |
| `pickle.loads`, `yaml.load` | Deserialization | Use safe alternatives |
| `subprocess.call(shell=True)` | Command injection | Use list form, no shell |

## Verification

- [ ] All security-relevant changes identified in diff
- [ ] Automated scanners ran (gitleaks, semgrep, dependency audit)
- [ ] Manual review completed with checklist
- [ ] Findings documented with severity and remediation
- [ ] No critical/high findings remain unresolved before merge
- [ ] Detection opportunities noted for monitoring team
