webhook

package
v1.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package webhook handles inbound webhook receivers — GitHub PR / push events + operator-defined generic webhooks. Every receiver verifies an HMAC-SHA256 signature against either a per-source secret (GitHub) or a per-row secret (generic), then queues a scan job via the same code path as POST /api/v1/scans.

The HMAC verification is constant-time. Signature format follows GitHub's "sha256=" + hex convention for both source types.

Index

Constants

View Source
const (
	// MaxBodyBytes caps inbound payloads at 1 MB. GitHub events sit
	// well under that; the limit prevents a malicious sender from
	// pinning daemon memory.
	MaxBodyBytes = 1 << 20

	// SignaturePrefix is the "sha256=" tag GitHub puts in the header
	// before the hex digest. Generic receivers use the same shape
	// for parity.
	SignaturePrefix = "sha256="
)
View Source
const SlackReplayWindow = 5 * time.Minute

SlackReplayWindow is the maximum age of an inbound request, rejecting anything older to mitigate replay attacks.

View Source
const SlackSignaturePrefix = "v0="

SlackSignaturePrefix is the version-prefix Slack puts on the signature header. v0 is the only spec'd value as of 2026.

Variables

This section is empty.

Functions

func SignBody

func SignBody(secret string, body []byte) string

SignBody is the helper test code (and the v1.4 settings UI "test this webhook" button) uses to produce a valid header for a body.

func VerifySignature

func VerifySignature(secret, header string, body []byte) bool

VerifySignature is the constant-time HMAC-SHA256 check shared by both receivers. The header is expected as "sha256=<hex>" (GitHub convention); empty/malformed headers fail.

func VerifySlackSignature added in v1.8.0

func VerifySlackSignature(secret string, headerSig string, timestamp string, body []byte) bool

VerifySlackSignature implements Slack's HMAC-SHA256-over- (v0:timestamp:body) recipe. Returns false on any structural error (missing/empty headers, stale timestamp, malformed hex). secret is the workspace signing-secret.

Types

type Buf

type Buf struct {
	// contains filtered or unexported fields
}

Buf is the trimmed payload buffer wrapper. Used by tests + integration code that needs to inspect the verified body.

func (*Buf) Bytes

func (b *Buf) Bytes() []byte

func (*Buf) Len

func (b *Buf) Len() int

func (*Buf) String

func (b *Buf) String() string

type Config

type Config struct {
	GitHubSecret       string
	SlackSigningSecret string
	JiraSecret         string
	LinearSecret       string
}

Config carries the operator-controlled inbound-secrets. v1.4 settings page wires this from the providers table; the CLI flag path is the v1.3 fallback.

type PRMapping added in v1.8.0

type PRMapping struct {
	Repo        string
	PRNumber    int
	CommentID   int64
	Fingerprint string
}

PRMapping holds one row in the github_pr_mapping table. The outbound github-pr notifier (or its v1.8.x adapter) constructs these alongside its post + persists them via PersistPRMapping.

type Receiver

type Receiver struct {
	// contains filtered or unexported fields
}

Receiver is the HTTP handler bundle for both inbound paths.

func New

func New(st *store.Store, cfg Config) *Receiver

New constructs the receiver. nil cfg is fine — both inbound paths will then 403 every request (no secret = no verify = no trust).

func (*Receiver) Mount

func (rc *Receiver) Mount(r chi.Router)

Mount installs /webhooks/{...} routes on r. No auth middleware here — the routes do their own signature verification.

func (*Receiver) PersistPRMapping added in v1.8.0

func (rc *Receiver) PersistPRMapping(ctx context.Context, m PRMapping) error

PersistPRMapping inserts the (repo, pr, comment_id, fingerprint) tuple. Idempotent via the composite PK ON CONFLICT DO NOTHING.

func (*Receiver) WithEvents added in v1.6.0

func (rc *Receiver) WithEvents(p *events.Producer) *Receiver

WithEvents installs the v1.6 SSE producer so accepted webhooks publish webhook.received events. Returns the receiver for chaining.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL