Repository navigation
fix(webhook): drop unhandled events before the repository lookup - #27
Merged
Merged
Conversation
The plugin registered its repository hooks for push, pull_request and check_run, but only ever handled the first two. GitHub sends check_run once per CI job per state, so every one of those deliveries paid for a repository lookup plus an HMAC verification before landing in handleWebhookEvent's default branch — and a hook created before this change stays subscribed, so narrowing the subscription alone is not enough. Gate the event type in receiveWebhook, before the lookup, and stop requesting check_run when creating hooks from now on. Existing tests that used an unhandled event to prove signature verification ran now use pull_request, since that is the first event type that reaches dispatch.
This was referenced Oct 19, 2026
pikann
approved these changes
Oct 19, 2026
pikann
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
As suggested in Paca-AI/paca#606 — this belongs here rather than in the core's
api_trigger.createWebhookregistered every linked repository forpush,pull_requestandcheck_run, buthandleWebhookEventonly ever acts on the first two. GitHub sendscheck_runonce per CI job per state, so a repo with ~10 jobs turns one push into dozens of deliveries, and every one of them paid for:github_repositorieslookup, and…before landing in the
default:case that logsunhandled event typeand returns. That is the same delivery flood that motivated #606 on the core side, and here it is entirely self-inflicted: the plugin asked for an event it does not handle.It is also not fixable by narrowing the subscription alone — hooks created by earlier versions stay subscribed to
check_rununtil someone deletes and recreates them, so the receiver has to be cheap on its own.What
receiveWebhooknow checks the event type before the repository lookup and the HMAC work, and answers204(unchanged contract, so GitHub never retries) for anything that is notpull_request/push. The check is the same closed sethandleWebhookEventdispatch already had, just moved in front of the expensive part.createWebhookno longer subscribes tocheck_run, so new links stop the traffic at the source.No behaviour change for
pull_requestorpush: same signature requirement, same storage, same emitted events.Tests
TestHandlesWebhookEvent— the closed set, includingcheck_run,check_suite,workflow_run, empty.TestReceiveWebhook_IgnoresUnhandledEventType— a correctly signedcheck_rundelivery against a linked repo answers204, logs the drop, and never reacheshandleWebhookEvent. Fails without the gate (expected the unhandled event to be dropped before dispatch, with the log showingwebhook received+unhandled event type).ScopesRepositoryLookupToURLProject,RejectsMissingSecret) used an unhandled event (workflow_run) purely as a vehicle to prove signature verification ran, and usedunhandled event typeas the positive dispatch signal. They now sendpull_requestand asserthandling pull_request event, which is logged at the same point and stays reachable. Their intent and assertions are otherwise unchanged.go test -race ./...green,golangci-lint run→0 issues.Not in this PR
Action-level narrowing (e.g. "only
opened/synchronize, notlabeled") has no home yet: a plugin trigger's config is opaque to the core, which dispatches purely oneventTopic, so per-automation filtering cannot be decided here. Options worth discussing separately: extra topics per action, or a trigger-filter hook in the plugin SDK. Notegithub.pr_updatedis already emitted (with anactionfield) but not declared as a trigger inplugin.json— declaring it would let automations bind GitHub PR activity without a coreapi_trigger+ public proxy at all.