|
| 1 | +# Security Review Workflow |
| 2 | + |
| 3 | +**Workflow File**: [`.github/workflows/security-review.yml`](../../.github/workflows/security-review.yml) |
| 4 | + |
| 5 | +This workflow analyzes commits for security vulnerabilities, insecure coding patterns, and exposed secrets, then automatically creates issues for Copilot to remediate. |
| 6 | + |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +The Security Review workflow uses GitHub Copilot CLI to examine code changes and identify security concerns before they reach production. By automating security analysis on every push, teams can catch vulnerabilities early without relying solely on manual code review or scheduled scans. |
| 11 | + |
| 12 | + |
| 13 | +## How It Works |
| 14 | + |
| 15 | +```mermaid |
| 16 | +flowchart TD |
| 17 | + A[Push to Repository] --> B{Source files changed?} |
| 18 | + B -->|No| C[Skip workflow] |
| 19 | + B -->|Yes| D[Install Copilot CLI] |
| 20 | + D --> E[Load analyze-security prompt] |
| 21 | + E --> F[Copilot analyzes commit diff] |
| 22 | + F --> G{Security issues found?} |
| 23 | + G -->|No| H[Exit - No concerns found] |
| 24 | + G -->|Yes| I[Create GitHub Issue] |
| 25 | + I --> J[Assign Copilot Coding Agent] |
| 26 | + J --> K[Agent implements fixes] |
| 27 | + K --> L[PR created with remediations] |
| 28 | +``` |
| 29 | + |
| 30 | +### Step-by-Step Process |
| 31 | + |
| 32 | +1. **Triggers on every push** (excluding docs, markdown, and workflow files) |
| 33 | +2. **Installs Copilot CLI** in the GitHub Actions runner |
| 34 | +3. **Loads the analyze-for-security prompt** from [`.github/prompts/analyze-for-security.prompt.md`](../../.github/prompts/analyze-for-security.prompt.md) |
| 35 | +4. **Copilot examines the commit diff** using MCP tools |
| 36 | +5. **If security concerns are found** → Creates a GitHub issue and assigns Copilot |
| 37 | +6. **Copilot Coding Agent** then implements the remediations |
| 38 | + |
| 39 | + |
| 40 | +## Criteria for Security Review |
| 41 | + |
| 42 | +### ✅ Issues ARE Flagged |
| 43 | + |
| 44 | +| Category | Examples | |
| 45 | +|----------|---------| |
| 46 | +| Exposed Credentials | Hardcoded API keys, tokens, passwords | |
| 47 | +| Injection Vulnerabilities | SQL injection, command injection, path traversal | |
| 48 | +| Insecure Input Handling | Missing validation/sanitization on user input | |
| 49 | +| Auth/Authz Weaknesses | Missing auth checks, privilege escalation risks | |
| 50 | +| Insecure Cryptography | Weak algorithms, hardcoded IVs or salts | |
| 51 | +| Sensitive Data Exposure | Logging PII, returning secrets in API responses | |
| 52 | +| Dependency Risks | New dependencies with known CVEs | |
| 53 | +| Configuration Weaknesses | Disabled TLS verification, permissive CORS | |
| 54 | + |
| 55 | +### ❌ Issues NOT Flagged |
| 56 | + |
| 57 | +| Category | Examples | |
| 58 | +|----------|---------| |
| 59 | +| Documentation Only | README, comments, JSDoc | |
| 60 | +| Mock/Fake Credentials in Tests | `password: "fake-test-value"` in test helpers | |
| 61 | +| Formatting Changes | Whitespace, linting fixes | |
| 62 | +| Unrelated Logic Changes | UI tweaks, dependency version bumps with no CVE | |
| 63 | + |
| 64 | + |
| 65 | +## Configuration |
| 66 | + |
| 67 | +### Trigger Configuration |
| 68 | + |
| 69 | +The workflow runs on source code changes: |
| 70 | + |
| 71 | +```yaml |
| 72 | +on: |
| 73 | + push: |
| 74 | + paths-ignore: |
| 75 | + - 'docs/**' |
| 76 | + - '**.md' |
| 77 | + - '.github/workflows/**' |
| 78 | + - '.gitignore' |
| 79 | + - 'LICENSE' |
| 80 | +``` |
| 81 | +
|
| 82 | +### Required Secrets |
| 83 | +
|
| 84 | +| Secret | Description | |
| 85 | +|--------|-------------| |
| 86 | +| `COPILOT_CLI_TOKEN` | Personal Access Token with Copilot permissions | |
| 87 | + |
| 88 | + |
| 89 | +## Prompt File |
| 90 | + |
| 91 | +The workflow uses a specialized prompt to guide Copilot's security analysis: |
| 92 | + |
| 93 | +**Location**: [`.github/prompts/analyze-for-security.prompt.md`](../../.github/prompts/analyze-for-security.prompt.md) |
| 94 | + |
| 95 | +This prompt instructs Copilot to: |
| 96 | +- Analyze the git diff for security anti-patterns and vulnerabilities |
| 97 | +- Assign a severity level (Critical / High / Medium / Low) to each finding |
| 98 | +- Calculate a confidence score to filter out low-signal noise |
| 99 | +- Create a structured issue with actionable remediation guidance |
| 100 | + |
| 101 | + |
| 102 | +## Example Issue Created |
| 103 | + |
| 104 | +When the workflow detects security concerns, it creates an issue like: |
| 105 | + |
| 106 | +```markdown |
| 107 | +## 🔒 Security Review Analysis |
| 108 | +
|
| 109 | +**Commit**: abc1234 |
| 110 | +**Confidence Score**: 92/100 |
| 111 | +
|
| 112 | +### Findings |
| 113 | +
|
| 114 | +| Severity | File | Line(s) | Description | |
| 115 | +|----------|------|---------|-------------| |
| 116 | +| 🔴 Critical | `src/config.ts` | 12 | Hardcoded AWS secret key | |
| 117 | +| 🟠 High | `src/routes/user.ts` | 55-60 | Unsanitized user ID passed to SQL query | |
| 118 | + |
| 119 | +### Detailed Findings |
| 120 | + |
| 121 | +#### Finding 1 – Hardcoded AWS Secret Key |
| 122 | + |
| 123 | +**Severity:** Critical |
| 124 | +**File:** `src/config.ts` (line 12) |
| 125 | + |
| 126 | +**Issue:** |
| 127 | +An AWS secret access key is committed in plain text, exposing the credential to anyone with repository access. |
| 128 | + |
| 129 | +**Recommendation:** |
| 130 | +Remove the hardcoded value, rotate the exposed key immediately, and load it from an environment variable or secrets manager. |
| 131 | + |
| 132 | +--- |
| 133 | +*Auto-generated by security review workflow* |
| 134 | +``` |
| 135 | + |
| 136 | + |
| 137 | +## Troubleshooting |
| 138 | + |
| 139 | +### Workflow Not Triggering |
| 140 | + |
| 141 | +- Verify the push includes files outside the `paths-ignore` patterns |
| 142 | +- Check that the workflow file exists in the default branch |
| 143 | + |
| 144 | +### Copilot Not Creating Issues |
| 145 | + |
| 146 | +- Ensure `COPILOT_CLI_TOKEN` secret is configured |
| 147 | +- Verify the token has `Copilot Requests` permission |
| 148 | +- Check workflow logs for authentication errors |
| 149 | + |
| 150 | +### Agent Not Implementing Fixes |
| 151 | + |
| 152 | +- Confirm Copilot Coding Agent is enabled in repository settings |
| 153 | +- Verify the issue is properly assigned to `@copilot` |
| 154 | +- Review the issue body to ensure findings are clearly described |
0 commit comments