Some checks failed
check / check (push) Failing after 2m31s
A receiver URL was a bare v4 UUID and nothing else: anyone who learned it could store events and, because inbound headers are forwarded to targets almost verbatim, choose what the downstream service received. Entrypoints gain an optional scheme/secret pair. GitHub's X-Hub-Signature-256 (HMAC-SHA256 hex over the raw body) and GitLab's X-Gitlab-Token (plain shared token) are supported; both compare with hmac.Equal. With nothing configured an entrypoint behaves exactly as before, which is also where every pre-existing row lands after AutoMigrate adds the columns. Verification runs after the capped body read and before the first write, so a rejected request leaves no event row, no delivery row and no delivery task. A configuration the receiver cannot apply — unknown scheme, or one half of the pair missing — is refused with a 500 rather than falling back to unverified. The secret is credential-bearing and is stored in the clear because HMAC needs the key itself. It is excluded from JSON, kept out of templates by a new handlers.EntrypointView projection, and absent from every log line including the rejection path. The UI sets and rotates it through one form that never renders the stored value. Under the GitLab scheme the signature header is the secret rather than a digest over the request, so an accepted request's headers are cloned and the configured scheme's credential header dropped before they are serialized onto the event. Stored headers are persisted verbatim in the per-webhook database and replayed onto every outbound delivery, so keeping the token would put it in every backup and hand every target operator the means to forge signed requests to the entrypoint it authenticates. Stripping sits once above the first write rather than at each egress, and is driven by the scheme's own description with stripping as the default: a scheme added later is covered unless it declares its header a digest, as GitHub's HMAC over the body does. An entrypoint holding one half of the pair now renders as misconfigured rather than as unverified, and the scheme selector follows the stored scheme so such a row no longer marks two options selected.
72 lines
2.8 KiB
Go
72 lines
2.8 KiB
Go
package database
|
|
|
|
// SignatureScheme names the way an entrypoint authenticates inbound
|
|
// requests. A scheme fixes both the header the signature arrives in
|
|
// and the algorithm used to check it, so an operator cannot pair one
|
|
// sender's header with another sender's comparison.
|
|
type SignatureScheme string
|
|
|
|
// Signature scheme values. The empty scheme means the entrypoint
|
|
// performs no inbound verification: it is the default, and it is the
|
|
// state every entrypoint created before this column existed migrates
|
|
// to, so an existing deployment keeps accepting the requests it
|
|
// accepted before.
|
|
const (
|
|
SignatureSchemeNone SignatureScheme = ""
|
|
SignatureSchemeGitHub SignatureScheme = "github"
|
|
SignatureSchemeGitLab SignatureScheme = "gitlab"
|
|
)
|
|
|
|
// Entrypoint represents an inbound URL endpoint that feeds into a webhook
|
|
type Entrypoint struct {
|
|
BaseModel
|
|
|
|
WebhookID string `gorm:"type:uuid;not null" json:"webhookId"`
|
|
|
|
// Path is the URL path for this entrypoint.
|
|
Path string `gorm:"uniqueIndex;not null" json:"path"`
|
|
|
|
Description string `json:"description"`
|
|
Active bool `gorm:"default:true" json:"active"`
|
|
|
|
// SignatureScheme selects how inbound requests to this
|
|
// entrypoint are authenticated. Empty means unauthenticated,
|
|
// which is what a UUID-only entrypoint has always been.
|
|
SignatureScheme SignatureScheme `gorm:"default:''" json:"signatureScheme"`
|
|
|
|
// SignatureSecret is the secret shared with the sender.
|
|
//
|
|
// It is stored in the clear because HMAC verification needs the
|
|
// key itself: a hash of it cannot recompute the sender's digest.
|
|
// It is therefore a live credential, and json:"-" keeps it out of
|
|
// any handler that marshals the model, the way APIKey.Key and
|
|
// Target.Config are kept out. handlers.EntrypointView is the
|
|
// matching barrier for the HTML path.
|
|
SignatureSecret string `gorm:"default:''" json:"-"`
|
|
|
|
// Relations
|
|
Webhook Webhook `json:"webhook,omitzero"`
|
|
}
|
|
|
|
// SignatureConfigured reports whether this entrypoint verifies
|
|
// inbound requests. Both halves must be present: a scheme without a
|
|
// secret, or a secret without a scheme, is a broken configuration
|
|
// rather than a configured one, and signature.Verify fails those
|
|
// closed rather than treating them as "off".
|
|
func (e *Entrypoint) SignatureConfigured() bool {
|
|
return e.SignatureScheme != SignatureSchemeNone &&
|
|
e.SignatureSecret != ""
|
|
}
|
|
|
|
// SignatureHalfConfigured reports whether exactly one half of the
|
|
// scheme/secret pair is present. The receiver refuses such a row on
|
|
// every request, so the UI must not describe it as unverified. It
|
|
// reports the state without exposing the secret, which is why it
|
|
// lives here rather than in the display projection.
|
|
func (e *Entrypoint) SignatureHalfConfigured() bool {
|
|
hasScheme := e.SignatureScheme != SignatureSchemeNone
|
|
hasSecret := e.SignatureSecret != ""
|
|
|
|
return hasScheme != hasSecret
|
|
}
|