Repository navigation
fix: require GitHub webhook secret like other VCS providers - #13999
Conversation
Co-authored-by: Cursor <[email protected]>
🟢 Tier S · Ready to merge
GitHub webhook events at Latest changes: The handler now folds the empty-secret check into the signature check (
📂 Walkthrough · 6
Reviewed the commits since |
|
| _APP_VCS_GITHUB_CLIENT_SECRET= | ||
| _APP_VCS_GITHUB_PRIVATE_KEY=disabled | ||
| _APP_VCS_GITHUB_WEBHOOK_SECRET= | ||
| _APP_VCS_GITHUB_WEBHOOK_SECRET=github-webhook-secret |
There was a problem hiding this comment.
Public webhook secret
If a repository-based Compose deployment does not override this value, it forwards a publicly known secret to the public GitHub webhook endpoint. Anyone who knows the value can produce a valid signature and send forged installation, push, or pull-request events for processing. The repository guide also requires credentials not to be hardcoded. How this was verified: The Compose configuration forwards the checked-in secret, and the public endpoint accepts events after comparing their signature against an HMAC keyed by that secret.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: .env
Line: 186
Comment:
**Public webhook secret**
If a repository-based Compose deployment does not override this value, it forwards a publicly known secret to the public GitHub webhook endpoint. Anyone who knows the value can produce a valid signature and send forged installation, push, or pull-request events for processing. The repository guide also requires credentials not to be hardcoded. **How this was verified:** The Compose configuration forwards the checked-in secret, and the public endpoint accepts events after comparing their signature against an HMAC keyed by that secret.
**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| return ['event' => $event, 'commit' => $commit]; | ||
| } | ||
|
|
||
| public function testGitHubEventWithInvalidSignature(): void |
There was a problem hiding this comment.
Missing-secret rejection remains untested
This test runs with a configured webhook secret, so both requests exercise invalid-signature rejection rather than the new missing-secret guard. The test would still pass if the endpoint again accepted unsigned events when no secret is set, leaving the main security regression undetected. Add an endpoint-level check with the server secret unset.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/VCSGitHub/VCSGitHubConsoleClientTest.php
Line: 683
Comment:
**Missing-secret rejection remains untested**
This test runs with a configured webhook secret, so both requests exercise invalid-signature rejection rather than the new missing-secret guard. The test would still pass if the endpoint again accepted unsigned events when no secret is set, leaving the main security regression undetected. Add an endpoint-level check with the server secret unset.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Co-authored-by: Cursor <[email protected]>
| 'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_ID'], | ||
| 'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_SECRET'], | ||
| 'webhookSecret' => ['required' => false, 'envVariable' => '_APP_VCS_GITHUB_WEBHOOK_SECRET'], | ||
| 'webhookSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_WEBHOOK_SECRET'], |
There was a problem hiding this comment.
GitHub disappears from Console
When the GitHub webhook secret is empty, this required flag makes the factory exclude GitHub from the provider list returned to the Console. GitHub authorization and repository listing can still work, but the Console no longer shows GitHub as an available provider. The intended change is to reject webhook deliveries, not to hide the provider.
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/config/vcs.php
Line: 31
Comment:
**GitHub disappears from Console**
When the GitHub webhook secret is empty, this required flag makes the factory exclude GitHub from the provider list returned to the Console. GitHub authorization and repository listing can still work, but the Console no longer shows GitHub as an available provider. The intended change is to reject webhook deliveries, not to hide the provider.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| 'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_ID'], | ||
| 'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_SECRET'], | ||
| 'webhookSecret' => ['required' => false, 'envVariable' => '_APP_VCS_GITHUB_WEBHOOK_SECRET'], | ||
| 'webhookSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_WEBHOOK_SECRET'], |
There was a problem hiding this comment.
Test mirrors configuration
This changes the hand-written test fixture to copy the production required flag, but none of the tests using this fixture checks whether GitHub is considered configured. The repository requires tests to check observable behavior rather than mirror configuration. That requirement must be satisfied before merging; this change adds no coverage of the behavior affected by the flag.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Vcs/FactoryTest.php
Line: 223
Comment:
**Test mirrors configuration**
This changes the hand-written test fixture to copy the production `required` flag, but none of the tests using this fixture checks whether GitHub is considered configured. The repository requires tests to check observable behavior rather than mirror configuration. That requirement must be satisfied before merging; this change adds no coverage of the behavior affected by the flag.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
| $valid = !empty($secretKey) && $vcs->validateWebhookEvent($payload, $signature, $secretKey); | ||
| Span::add('vcs.github.event.signature.valid', $valid); | ||
|
|
||
| if (!$valid) { | ||
| throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, "Invalid webhook payload signature. Please make sure the webhook secret has same value in your GitHub app and in the _APP_VCS_GITHUB_WEBHOOK_SECRET environment variable"); | ||
| throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, 'Invalid webhook payload signature. Please make sure the webhook secret has same value in your GitHub app and in the _APP_VCS_GITHUB_WEBHOOK_SECRET environment variable'); |
There was a problem hiding this comment.
Missing secret looks like invalid signature
When _APP_VCS_GITHUB_WEBHOOK_SECRET is empty, the endpoint now reports an invalid signature instead of saying the server secret is not configured. An operator troubleshooting a failed webhook cannot tell from this error whether the secret is missing or differs from the one in the GitHub App.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/VCS/Http/GitHub/Events/Create.php
Line: 78-82
Comment:
**Missing secret looks like invalid signature**
When `_APP_VCS_GITHUB_WEBHOOK_SECRET` is empty, the endpoint now reports an invalid signature instead of saying the server secret is not configured. An operator troubleshooting a failed webhook cannot tell from this error whether the secret is missing or differs from the one in the GitHub App.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
What does this PR do?
POST /v1/vcs/github/eventsskipped signature validation when_APP_VCS_GITHUB_WEBHOOK_SECRETwas empty, which is the default. Any unsigned payload was accepted and processed as a genuine GitHub event.GitHub was the only VCS provider with an optional webhook secret. This PR makes it behave exactly like Gitea, GitLab and Bitbucket:
app/config/vcs.php:webhookSecretis nowrequired: truefor GitHub. Without it,Factory::isConfigured('github')returns false, so GitHub is disabled the same way the other providers are.$valid = !empty($secretKey) && validateWebhookEvent(...)), so a missing secret is rejected with the same403 general_access_forbiddenas a bad signature..envsets a test value for_APP_VCS_GITHUB_WEBHOOK_SECRET, like Gitea's. The e2e push helper always signs its payload. The Factory unit tests use a test-only env var so they no longer depend on the container's environment.Upgrade note (breaking for some self-hosted setups): instances that use GitHub without a webhook secret will see the GitHub integration disabled after upgrading. To restore it, set a webhook secret in the GitHub App settings and the same value in
_APP_VCS_GITHUB_WEBHOOK_SECRET. This needs to go in the release notes.Test Plan
testCreateEventWithInvalidSignaturechecks that unsigned events and events signed with the wrong secret both get a 403.composer lintpasses on the changed files.Related PRs and Issues
Checklist