|
| 1 | +# CodeQL Resolver |
| 2 | + |
| 3 | +A Claude Code plugin that provides systematic analysis and resolution of CodeQL alerts in GitHub Actions workflows. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +**CodeQL Resolver** implements a three-tier command→agent→skill architecture for managing GitHub security scanning alerts: |
| 8 | + |
| 9 | +- **`/resolve-codeql`** - Main command for discovering, classifying, and delegating CodeQL alerts |
| 10 | +- **3 Specialized Agents** - Permission auditor, expression injection fixer, generic resolver |
| 11 | +- **2 Reusable Skills** - Permission classification, security patterns |
| 12 | + |
| 13 | +## Key Features |
| 14 | + |
| 15 | +### Alert Classification |
| 16 | +Automatically categorizes CodeQL alerts by type: |
| 17 | +- ✅ **Permissions** - "Workflow does not contain permissions" |
| 18 | +- ✅ **Expression Injection** - Untrusted input in shell commands |
| 19 | +- ✅ **Other** - Resource leaks, hardcoded credentials, etc. |
| 20 | + |
| 21 | +### Specialized Agents |
| 22 | + |
| 23 | +#### 1. Permissions Auditor |
| 24 | +Fixes "Workflow does not contain permissions" alerts by: |
| 25 | +- Analyzing reusable workflow call requirements |
| 26 | +- Determining minimum permissions needed |
| 27 | +- Adding explicit least-privilege blocks |
| 28 | + |
| 29 | +**Test case**: [ci-gate.yml](https://github.com/JacobPEvans/ai-assistant-instructions/blob/main/.github/workflows/ci-gate.yml) - Fixed 8 alerts with this agent's methodology |
| 30 | + |
| 31 | +#### 2. Expression Injection Fixer |
| 32 | +Mitigates GitHub Actions expression injection vulnerabilities by: |
| 33 | +- Identifying dangerous untrusted inputs |
| 34 | +- Wrapping in environment variables |
| 35 | +- Following GitHub's official security guidance |
| 36 | + |
| 37 | +#### 3. Generic Resolver |
| 38 | +Handles other CodeQL alert types: |
| 39 | +- Resource leaks, hardcoded credentials, unsafe shell |
| 40 | +- Escalates unclear issues for human review |
| 41 | +- Provides detailed analysis when patterns match |
| 42 | + |
| 43 | +## Installation |
| 44 | + |
| 45 | +### Option 1: Add via Marketplace (Recommended) |
| 46 | + |
| 47 | +```bash |
| 48 | +/plugin marketplace add /path/to/claude-code-plugins |
| 49 | +/plugin install codeql-resolver@jacobpevans-plugins |
| 50 | +``` |
| 51 | + |
| 52 | +### Option 2: Local Development |
| 53 | + |
| 54 | +```bash |
| 55 | +claude --plugin-dir /path/to/codeql-resolver |
| 56 | +``` |
| 57 | + |
| 58 | +## Usage |
| 59 | + |
| 60 | +### List All Alerts |
| 61 | + |
| 62 | +```bash |
| 63 | +/resolve-codeql |
| 64 | +``` |
| 65 | + |
| 66 | +### Fix All Alerts |
| 67 | + |
| 68 | +```bash |
| 69 | +/resolve-codeql fix |
| 70 | +``` |
| 71 | + |
| 72 | +### Fix Specific Alert Type |
| 73 | + |
| 74 | +```bash |
| 75 | +/resolve-codeql type:permissions # Fix only permissions alerts |
| 76 | +/resolve-codeql type:injection # Fix only expression injection |
| 77 | +/resolve-codeql type:other # Fix other alert types |
| 78 | +``` |
| 79 | + |
| 80 | +### Fix Specific File |
| 81 | + |
| 82 | +```bash |
| 83 | +/resolve-codeql file:.github/workflows/ci-gate.yml |
| 84 | +``` |
| 85 | + |
| 86 | +## Architecture |
| 87 | + |
| 88 | +``` |
| 89 | +┌────────────────────────────────────┐ |
| 90 | +│ /resolve-codeql (Command) │ |
| 91 | +│ - Discover alerts via GitHub API │ |
| 92 | +│ - Classify by type │ |
| 93 | +│ - Delegate to specialists │ |
| 94 | +│ - Verify fixes │ |
| 95 | +└────────────────┬───────────────────┘ |
| 96 | + │ |
| 97 | + ┌───────┼───────┐ |
| 98 | + │ │ │ |
| 99 | + ▼ ▼ ▼ |
| 100 | + ┌────────┬────────┬──────────┐ |
| 101 | + │Perms │Inject │Generic │ |
| 102 | + │Auditor │Fixer │Resolver │ |
| 103 | + └────────┴────────┴──────────┘ |
| 104 | + │ │ │ |
| 105 | + └───────┼───────┘ |
| 106 | + │ |
| 107 | + Skills |
| 108 | + ┌──────────────────┐ |
| 109 | + │ Permission │ |
| 110 | + │ Classification │ |
| 111 | + │ │ |
| 112 | + │ Workflow │ |
| 113 | + │ Security Patterns│ |
| 114 | + └──────────────────┘ |
| 115 | +``` |
| 116 | + |
| 117 | +## Plugin Structure |
| 118 | + |
| 119 | +``` |
| 120 | +codeql-resolver/ |
| 121 | +├── .claude-plugin/ |
| 122 | +│ └── plugin.json # Plugin manifest |
| 123 | +├── hooks/ |
| 124 | +│ └── hooks.json # Hook configuration |
| 125 | +├── agents/ |
| 126 | +│ ├── codeql-permissions-auditor.md |
| 127 | +│ ├── codeql-expression-injector.md |
| 128 | +│ └── codeql-generic-resolver.md |
| 129 | +├── skills/ |
| 130 | +│ ├── codeql-permission-classification.md |
| 131 | +│ └── github-workflow-security-patterns.md |
| 132 | +├── commands/ |
| 133 | +│ └── resolve-codeql.md |
| 134 | +└── README.md |
| 135 | +``` |
| 136 | + |
| 137 | +## Examples |
| 138 | + |
| 139 | +### Example 1: Fix ci-gate.yml Permissions |
| 140 | + |
| 141 | +```bash |
| 142 | +cd ~/git/ai-assistant-instructions |
| 143 | +/resolve-codeql file:.github/workflows/ci-gate.yml |
| 144 | +``` |
| 145 | + |
| 146 | +**Output**: |
| 147 | +``` |
| 148 | +CodeQL Alert Resolution Report |
| 149 | +=============================== |
| 150 | +File: .github/workflows/ci-gate.yml |
| 151 | +Alerts found: 8 (permissions) |
| 152 | +
|
| 153 | +Fixing permissions on reusable workflow calls... |
| 154 | +✓ cclint (line 103) - Added contents:read |
| 155 | +✓ validate-cclint (line 109) - Added contents:read, pull-requests:write |
| 156 | +✓ markdownlint (line 118) - Added contents:read |
| 157 | +✓ spellcheck (line 124) - Added contents:read |
| 158 | +✓ token-limits (line 130) - Added contents:read, pull-requests:write |
| 159 | +✓ validate-instructions (line 146) - Added contents:read |
| 160 | +✓ yaml-lint (line 152) - Added contents:read |
| 161 | +✓ gate (line 160) - Added permissions:{} |
| 162 | +
|
| 163 | +Verification: Running CodeQL scan... |
| 164 | +✓ All 8 alerts resolved! |
| 165 | +
|
| 166 | +Commit: "security: fix CodeQL alerts - add explicit permissions" |
| 167 | +``` |
| 168 | + |
| 169 | +### Example 2: Fix Expression Injection |
| 170 | + |
| 171 | +```bash |
| 172 | +/resolve-codeql type:injection |
| 173 | +``` |
| 174 | + |
| 175 | +**Output**: |
| 176 | +``` |
| 177 | +CodeQL Alert Resolution Report |
| 178 | +=============================== |
| 179 | +Alert Type: Expression Injection |
| 180 | +
|
| 181 | +Analyzing vulnerable patterns... |
| 182 | +Found 1 alert in .github/workflows/deploy.yml:45 |
| 183 | +
|
| 184 | +Fixing expression injection... |
| 185 | +✓ Added env: block for PR_BODY variable |
| 186 | +✓ Updated script to use $PR_BODY instead of untrusted expression |
| 187 | +
|
| 188 | +Verification: ✓ Alert resolved! |
| 189 | +
|
| 190 | +Commit: "security: fix CodeQL - mitigate expression injection" |
| 191 | +``` |
| 192 | + |
| 193 | +## Real-World Test Case |
| 194 | + |
| 195 | +The plugin was designed with [PR #413](https://github.com/JacobPEvans/ai-assistant-instructions/pull/413) as a real test case: |
| 196 | + |
| 197 | +- **Starting point**: 8 CodeQL alerts in ci-gate.yml |
| 198 | +- **Issue**: Missing `permissions:` blocks on reusable workflow calls |
| 199 | +- **Solution**: Permissions auditor agent analyzed each job and added appropriate blocks |
| 200 | +- **Result**: All 8 alerts resolved with single commit |
| 201 | + |
| 202 | +## Security Principles |
| 203 | + |
| 204 | +All fixes follow these security principles: |
| 205 | + |
| 206 | +1. **Least Privilege** - Requests only minimum permissions needed |
| 207 | +2. **Explicit Over Implicit** - Declares permissions explicitly rather than relying on defaults |
| 208 | +3. **Auditable** - All changes follow documented patterns and are reviewable |
| 209 | +4. **Safe By Default** - Expression injection vulnerabilities wrapped in env vars |
| 210 | +5. **Escalation** - Unclear issues flagged for human review, not auto-fixed |
| 211 | + |
| 212 | +## References |
| 213 | + |
| 214 | +- [GitHub Security Blog: Catching GitHub Actions Workflow Injections](https://github.blog/security/vulnerability-research/how-to-catch-github-actions-workflow-injections-before-attackers-do/) |
| 215 | +- [GitHub Actions Security: Best Practices](https://docs.github.com/en/actions/security-guides) |
| 216 | +- [CodeQL Rules Documentation](https://docs.github.com/en/code-security/codeql) |
| 217 | + |
| 218 | +## Development |
| 219 | + |
| 220 | +### Local Testing |
| 221 | + |
| 222 | +```bash |
| 223 | +cd ~/git/claude-code-plugins/feat/codeql-resolver/codeql-resolver |
| 224 | +python3 scripts/test_codeql_plugin.py |
| 225 | +``` |
| 226 | + |
| 227 | +### Adding New Alert Types |
| 228 | + |
| 229 | +1. Create new agent in `agents/codeql-{type}-resolver.md` |
| 230 | +2. Add to `plugin.json` agents list |
| 231 | +3. Update `/resolve-codeql` command to delegate to new agent |
| 232 | +4. Create corresponding skill if pattern is reusable |
| 233 | +5. Add tests in `scripts/test_codeql_plugin.py` |
| 234 | + |
| 235 | +## Contributing |
| 236 | + |
| 237 | +See [CONTRIBUTING.md](../docs/CONTRIBUTING.md) |
| 238 | + |
| 239 | +## License |
| 240 | + |
| 241 | +Apache 2.0 |
0 commit comments