From 4f0e63e991ad68a250c20240adfb13a6811f7a2e Mon Sep 17 00:00:00 2001 From: Jessika Duquette Date: Tue, 17 Nov 2026 11:20:05 -0500 Subject: [PATCH] Deprecate repo, remove hardcoded webhook secret, treat org events as private - README.md: add a deprecation notice. The repo is unmaintained and will be archived; Google uses the GitHub Events Platform (GEP) instead. - event/event.go: read the webhook HMAC secret from GITHUB_WEBHOOK_SECRET and reject every request when it is unset, instead of using a hardcoded constant. - event/event.go: classify *github.OrganizationEvent as private, like *github.MembershipEvent, so org membership and invitation payloads aren't published to the public-only topic. --- README.md | 14 ++++++++++++++ event/event.go | 17 +++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a35e49f..66d2378 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ +> [!WARNING] +> **Deprecated: this repository is no longer maintained and will be archived +> (made read-only).** Don't deploy it or build on it. +> +> Google now ingests GitHub webhook events through the GitHub Events Platform +> (GEP). Googlers should use GEP (go/github-events-platform) instead of this +> bridge. The open-source code behind GEP is +> [abcxyz/github-metrics-aggregator](https://github.com/abcxyz/github-metrics-aggregator). +> +> Earlier versions of this code hardcoded a webhook secret. Don't reuse it. +> If you deployed this code, rotate your GitHub webhook secret. The final +> version reads the secret from the `GITHUB_WEBHOOK_SECRET` environment +> variable and rejects every request if it isn't set. + # GitHub Webhook to Google Cloud PubSub Bridge This does exactly what it says it does. diff --git a/event/event.go b/event/event.go index b02d2a3..93f601d 100644 --- a/event/event.go +++ b/event/event.go @@ -4,6 +4,7 @@ package event import ( "fmt" "net/http" + "os" "strings" "time" @@ -11,10 +12,10 @@ import ( ) const ( - // secretToken is the secret we currently use from GitHub that lets us verify - // that they actually sent us the request. It's a shared secret between us & - // GitHub. - secretToken = "wkp5H9YShwQkWmV" + // secretTokenEnv names the environment variable holding the webhook secret + // shared with GitHub. There is no default: if it is unset or empty, every + // request is rejected. + secretTokenEnv = "GITHUB_WEBHOOK_SECRET" signatureHeader = "X-Hub-Signature" ) @@ -37,7 +38,11 @@ type Event struct { // ParseFromRequest returns a parsed Event from the incoming HTTP webhook payload. func ParseFromRequest(r *http.Request, received time.Time) (*Event, error) { - payload, err := github.ValidatePayload(r, []byte(secretToken)) + secret := os.Getenv(secretTokenEnv) + if secret == "" { + return nil, fmt.Errorf("%s is not set; refusing to accept webhooks", secretTokenEnv) + } + payload, err := github.ValidatePayload(r, []byte(secret)) if err != nil { return nil, fmt.Errorf("error validating payload: %v", err) } @@ -84,7 +89,7 @@ func parseRepository(wht string, payload []byte) (*RepoInfo, error) { switch ev := ev.(type) { case *github.OrganizationEvent: return &RepoInfo{ - IsPrivate: false, + IsPrivate: true, Name: "", OwnerName: "", OrganizationName: ev.GetOrganization().GetLogin(),