Commit 79427a2
authored
feat: PR security checks — suspicious paths, committer identity, auto-merge override (#1109)
<h3>PR Summary by Qodo</h3>
Add PR security checks for suspicious paths, committer identity, and
auto-merge override
<code>✨ Enhancement</code> <code>🧪 Tests</code> <code>⚙️ Configuration
changes</code> <code>📝 Documentation</code> <code>🕐 40+ Minutes</code>
<img
src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg"
height="10%" alt="Grey Divider">
<h3>Walkthroughs</h3>
<details open>
<summary>User Description</summary>
<br/>
## Summary
Three configurable security checks to detect and block malicious PR
attack vectors:
### Suspicious Path Detection
- New `security-suspicious-paths` check run
- Configurable path prefixes (default: `.claude/`, `.vscode/`,
`.cursor/`, `.devcontainer/`, `.pi/`, `.github/workflows/`,
`.github/actions/`)
- Fails check when PR modifies files in sensitive locations
### Committer Identity Check
- New `security-committer-identity` check run
- Flags when last committer differs from PR author
- Handles unknown committer identity explicitly
### Auto-Merge Override
- Blocks auto-merge when PR touches suspicious paths
- Posts comment explaining why auto-merge was blocked
### Security Design
- Config only from server-side `config.yaml` (not overridable by in-repo
`.github-webhook-server.yaml`)
- Prevents attackers from weakening security policy via PR
Closes #1106
</details>
<details open>
<summary>AI Description</summary>
<br/>
<pre>
• Add configurable PR security check runs for suspicious paths and
committer identity.
• Block auto-merge and comment when PR touches security-sensitive path
prefixes.
• Document/validate security-checks config and add full test coverage
for new behavior.
</pre>
</details>
<details>
<summary>Diagram</summary>
<br/>
```mermaid
graph TD
cfg["server config.yaml"] --> wh(["GitHubWebhook"]) --> prh(["PullRequestHandler"]) --> ofh(["OwnersFileHandler"])
prh --> rh(["RunnerHandler"]) --> crh(["CheckRunHandler"]) --> gh{{"GitHub API"}}
prh -. "comment / enable automerge" .-> gh
subgraph Legend
direction LR
_file["Config/File"] ~~~ _svc(["Handler/Service"]) ~~~ _ext{{"External"}}
end
```
</details>
<details>
<summary>High-Level Assessment</summary>
<br/>
The following are alternative approaches to this PR:
<details>
<summary><b>1. Use CODEOWNERS + branch protection for sensitive
paths</b></summary>
- ➕ Native GitHub enforcement; no extra webhook-side logic
- ➕ Can require reviews for .github/workflows/ and similar paths
- ➖ CODEOWNERS lives in-repo; attacker PR may attempt to modify it
(mitigations require additional protections)
- ➖ Doesn’t detect committer mismatch vs PR author
- ➖ Doesn’t provide an explicit auto-merge override message path
</details>
<details>
<summary><b>2. Required GitHub Actions workflow with path
filters</b></summary>
- ➕ Clear CI signal in GitHub UI; can block merges via required checks
- ➕ Easy to extend with additional detectors
- ➖ Workflows are in-repo and are themselves part of the attack surface
- ➖ May not run as expected depending on repo settings/permissions;
weaker central enforcement than server-side config
</details>
<details>
<summary><b>3. Org policy: require verified commits / signature
enforcement</b></summary>
- ➕ Stronger identity assurance than comparing GitHub usernames alone
- ➕ Moves trust decision into cryptographic verification
- ➖ Org-wide operational overhead; may block legitimate contributors
- ➖ Doesn’t address suspicious-path modifications; still needs
path-based review controls
</details>
**Recommendation:** The PR’s approach (server-side, non-overridable
security policy + explicit check-runs + auto-merge override) is a good
fit for defending against repo-config supply-chain attacks. Consider
adding CODEOWNERS/branch protections as defense-in-depth, but keep these
webhook checks as the centrally enforced gate.
</details>
<img
src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg"
height="10%" alt="Grey Divider">
<h3>File Changes</h3>
<details>
<summary><strong>Enhancement</strong> (4)</summary>
<blockquote>
<details>
<summary><strong>github_api.py</strong> <code>Load server-side security
policy and make committer identity explicit</code>
<code>+10/-1</code></summary>
<br/>
>Load server-side security policy and make committer identity explicit
>
><pre>
>• Sets last_committer to "unknown" when no GitHub user is
associated with the last commit committer. Loads security-checks only
from server configuration (no per-repo extra_dict override) and exposes
security_suspicious_paths and security_committer_identity_check on the
webhook context.
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-7c5f6dfcadb38e75c2d0f1d418ba1a861cc9f6c0efe72905a250e9f43a6cfdcf'>webhook_server/libs/github_api.py</a>
<hr/>
</details>
</blockquote>
<blockquote>
<details>
<summary><strong>pull_request_handler.py</strong> <code>Queue/run
security check-runs and block auto-merge on suspicious paths</code>
<code>+63/-0</code></summary>
<br/>
>Queue/run security check-runs and block auto-merge on suspicious paths
>
><pre>
>• Adds a Security Checks section to the welcome comment, queues and
launches two new security check-runs during PR open/sync, and blocks
auto-merge with an explanatory PR comment when changed_files match
suspicious path prefixes.
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-8644dc42c86db802123c2ba72847dca72589fe19f330ecc70621af895a72fc8a'>webhook_server/libs/handlers/pull_request_handler.py</a>
<hr/>
</details>
</blockquote>
<blockquote>
<details>
<summary><strong>runner_handler.py</strong> <code>Implement
suspicious-path and committer-identity security check runners</code>
<code>+114/-0</code></summary>
<br/>
>Implement suspicious-path and committer-identity security check runners
>
><pre>
>• Adds runner methods to evaluate changed files against configured
prefixes and to compare PR author vs last committer (including an
explicit "unknown" case). Each runner publishes detailed
check-run outputs and sets success/failure accordingly.
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-0cb54c95cafda12d8d169c7b03ac484738f4cf925c22f6e6b8b8c5db0730ce42'>webhook_server/libs/handlers/runner_handler.py</a>
<hr/>
</details>
</blockquote>
<blockquote>
<details>
<summary><strong>constants.py</strong> <code>Define security check names
and default suspicious path prefixes</code>
<code>+14/-0</code></summary>
<br/>
>Define security check names and default suspicious path prefixes
>
><pre>
>• Introduces constants for the two new check-run names, registers them
as non-overridable built-in checks, and defines the default suspicious
path prefix list used for detection.
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-9a2d73fb31266bc568369ee81f15b1ebb12d9703f412a0ab65cf7c5a5b98060f'>webhook_server/utils/constants.py</a>
<hr/>
</details>
</blockquote>
</details>
<details>
<summary><strong>Tests</strong> (2)</summary>
<blockquote>
<details>
<summary><strong>test_pull_request_handler.py</strong> <code>Extend PR
handler tests to account for new security runners</code>
<code>+9/-0</code></summary>
<br/>
>Extend PR handler tests to account for new security runners
>
><pre>
>• Updates the webhook mock with security-related attributes and patches
the new runner methods in existing workflow tests. Ensures PR processing
test scaffolding stays compatible with the new queued/started tasks.
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-ba922f135da60a85cf895a8d3fb3154c635c21019e6b7b6ab07c92caa9cbc163'>webhook_server/tests/test_pull_request_handler.py</a>
<hr/>
</details>
</blockquote>
<blockquote>
<details>
<summary><strong>test_security_checks.py</strong> <code>Add dedicated
tests for security checks and auto-merge override</code>
<code>+459/-0</code></summary>
<br/>
>Add dedicated tests for security checks and auto-merge override
>
><pre>
>• Adds coverage for suspicious path detection outcomes, committer
identity match/mismatch/unknown, and auto-merge blocking behavior
(including comment posting). Also asserts security constants and default
suspicious path list are wired into BUILTIN_CHECK_NAMES.
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-d7e0086d532052be0150224126f9b67dd174e7e039409d47316dd027f508a8c8'>webhook_server/tests/test_security_checks.py</a>
<hr/>
</details>
</blockquote>
</details>
<details>
<summary><strong>Other</strong> (2)</summary>
<blockquote>
<details>
<summary><strong>config.yaml</strong> <code>Document security-checks
settings and defaults in example config</code>
<code>+14/-0</code></summary>
<br/>
>Document security-checks settings and defaults in example config
>
><pre>
>• Adds a new security-checks section with default suspicious path
prefixes and a committer identity toggle. Provides inline commentary
describing the intent of these checks.
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-e3ac27ce128a0ddae53723bc8c3133257530a13c00f97c9edfeef152ebc3b8ce'>examples/config.yaml</a>
<hr/>
</details>
</blockquote>
<blockquote>
<details>
<summary><strong>schema.yaml</strong> <code>Add JSON schema for
security-checks configuration</code> <code>+24/-0</code></summary>
<br/>
>Add JSON schema for security-checks configuration
>
><pre>
>• Introduces a security-checks schema definition (suspicious-paths list
and committer-identity-check boolean) and wires it into the root schema.
Documents behavioral effects (check-run failure and auto-merge
blocking).
></pre>
>
><a
href='https://github.com/myk-org/github-webhook-server/pull/1109/files#diff-0eaf85d7f2a5888c61710a31c06434f63fe254f177f3df114332204780388f67'>webhook_server/config/schema.yaml</a>
<hr/>
</details>
</blockquote>
</details>
<img
src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg"
height="10%" alt="Grey Divider">
<a href="https://www.qodo.ai"><img
src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg"
width="80" alt="Qodo Logo"></a>1 parent ef8d7e6 commit 79427a2
14 files changed
Lines changed: 1228 additions & 3 deletions
File tree
- examples
- webhook_server
- config
- libs
- handlers
- tests
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
139 | 154 | | |
140 | 155 | | |
141 | 156 | | |
| |||
286 | 301 | | |
287 | 302 | | |
288 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
71 | 99 | | |
72 | 100 | | |
73 | 101 | | |
| |||
213 | 241 | | |
214 | 242 | | |
215 | 243 | | |
| 244 | + | |
| 245 | + | |
216 | 246 | | |
217 | 247 | | |
218 | 248 | | |
| |||
631 | 661 | | |
632 | 662 | | |
633 | 663 | | |
| 664 | + | |
| 665 | + | |
634 | 666 | | |
635 | 667 | | |
636 | 668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
662 | 663 | | |
663 | 664 | | |
664 | 665 | | |
665 | | - | |
| 666 | + | |
666 | 667 | | |
667 | 668 | | |
668 | 669 | | |
| |||
953 | 954 | | |
954 | 955 | | |
955 | 956 | | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
956 | 984 | | |
957 | 985 | | |
958 | 986 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
427 | 429 | | |
428 | 430 | | |
429 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
430 | 440 | | |
431 | 441 | | |
432 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
| 177 | + | |
174 | 178 | | |
175 | 179 | | |
176 | 180 | | |
| |||
362 | 366 | | |
363 | 367 | | |
364 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
365 | 427 | | |
366 | 428 | | |
367 | 429 | | |
| |||
0 commit comments