Add optional inbound webhook signature verification (closes #67) (#228)
Some checks failed
check / check (push) Superseded by a newer commit; never tested
Some checks failed
check / check (push) Superseded by a newer commit; never tested
The receiver had no inbound authentication of any kind: /webhook/{uuid}
was mounted behind a rate limiter alone, so the only thing protecting an
entrypoint was the secrecy of a v4 UUID in a URL path. Inbound headers are
forwarded almost verbatim to the target, so anyone who learned the URL
also chose the headers the downstream service received.
Adds an optional per-entrypoint secret with two schemes: github
(X-Hub-Signature-256, HMAC-SHA256 hex over the raw body) and gitlab
(X-Gitlab-Token, a plain shared token). Comparison is constant-time, the
HMAC is computed over the raw body before any parsing, and rejection
happens before persistence -- an unauthenticated request creates no event
row. An entrypoint with no secret behaves exactly as before, including
every row that predates this change.
The scheme's credential header is stripped from the header map before it
is marshalled into Event.Headers, so the GitLab token reaches neither the
event store nor any delivery target. SchemeInfo.HeaderIsDigest defaults to
false meaning strip, so a scheme added later is protected unless its
header is positively declared a digest.
This commit was merged in pull request #228.
This commit is contained in:
@@ -34,6 +34,8 @@ func marshalModel(t *testing.T, v any) string {
|
||||
// - APIKey.Key is a bearer token outright.
|
||||
// - Setting.Value holds the session encryption key.
|
||||
// - User.Password holds the Argon2 hash, and was already tagged.
|
||||
// - Entrypoint.SignatureSecret is the secret its senders sign with,
|
||||
// stored in the clear because HMAC verification needs the key.
|
||||
func TestModelsDoNotMarshalTheirSecrets(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -72,6 +74,14 @@ func TestModelsDoNotMarshalTheirSecrets(t *testing.T) {
|
||||
Password: marker,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "entrypoint signature secret",
|
||||
model: database.Entrypoint{
|
||||
Description: keptField,
|
||||
SignatureScheme: database.SignatureSchemeGitHub,
|
||||
SignatureSecret: marker,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
@@ -105,3 +115,24 @@ func TestWebhookMarshalsNoTargetConfig(t *testing.T) {
|
||||
assert.NotContains(t, encoded, marker)
|
||||
assert.Contains(t, encoded, keptField)
|
||||
}
|
||||
|
||||
// TestWebhookMarshalsNoEntrypointSecret covers the same nested case
|
||||
// for the entrypoint's inbound signature secret, which reaches a
|
||||
// marshalled webhook through the Entrypoints association.
|
||||
func TestWebhookMarshalsNoEntrypointSecret(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const marker = "QQENTRYPOINTMARKERQQ"
|
||||
|
||||
encoded := marshalModel(t, database.Webhook{
|
||||
Name: keptField,
|
||||
Entrypoints: []database.Entrypoint{{
|
||||
Path: "some-uuid",
|
||||
SignatureScheme: database.SignatureSchemeGitLab,
|
||||
SignatureSecret: marker,
|
||||
}},
|
||||
})
|
||||
|
||||
assert.NotContains(t, encoded, marker)
|
||||
assert.Contains(t, encoded, keptField)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user