hookauth

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hookauth checks that an incoming webhook comes from its service: the presets (GitHub, GitLab, Grafana, Alertmanager, Sentry, any JSON) and their signatures or tokens, compared in constant time. The hub checks a managed webhook with it (docs/hub/sources.md «Вебхуки»); a machine checks its own, unmanaged one with the same code (internal/connectors/webhook). It knows nothing of where the secret is kept.

Index

Constants

View Source
const (
	PresetGitHub       = "github"
	PresetGitLab       = "gitlab"
	PresetGrafana      = "grafana"
	PresetAlertmanager = "alertmanager"
	PresetSentry       = "sentry"
	PresetJSON         = "json"
)

Presets of the services it understands.

View Source
const (
	AuthHeader = "header"
	AuthPath   = "path"
)

How a service proves a request is its own, for the presets that let the person choose.

View Source
const Skew = 5 * time.Minute

Skew is how far a signed timestamp may be from now (Sentry, Grafana): an older request is a replay.

Variables

View Source
var Headers = []string{"Content-Type", "User-Agent", "Authorization",
	"X-Hub-Signature-256", "X-GitHub-Event", "X-GitHub-Delivery",
	"X-Gitlab-Token", "X-Gitlab-Event", "X-Gitlab-Event-UUID", "Idempotency-Key",
	"X-Grafana-Alerting-Signature", "X-Grafana-Alerting-Signature-Timestamp",
	"Sentry-Hook-Signature", "Sentry-Hook-Timestamp", "Sentry-Hook-Resource", "Request-ID",
	"X-Signature-256", "X-Signature", "X-Webhook-Signature", "X-Request-Id", "X-Delivery-Id"}

Headers are what the presets read: nothing else of a request is passed on or kept.

Functions

func Bearer

func Bearer(h http.Header, secret string) bool

Bearer checks Authorization: Bearer <secret>.

func DeliveryID

func DeliveryID(h http.Header) string

DeliveryID is the service's own id of the delivery ("Header:value"), "" when it sends none.

func Equal

func Equal(a, b string) bool

Equal compares a given secret with the kept one in constant time; an empty one is never equal.

func Fresh

func Fresh(ts string, now time.Time) bool

Fresh says a signed timestamp (unix seconds or milliseconds) is near now; an absent one is not.

func Known

func Known(preset string) bool

Known says preset is one of the presets.

func PathAuth

func PathAuth(preset, auth string) bool

PathAuth says the secret is the last part of the address (a sender that cannot sign or set a header).

func RouteToken

func RouteToken(secret, source string) string

RouteToken is the secret part of a managed webhook's address (/hook/t/<source>/<token>): derived from the secret the service signs with and the source, so it changes with the secret and opens no other source. 64 hex.

func SecretKey

func SecretKey(preset string) string

SecretKey is the name of the field that holds the secret a preset signs with: Sentry signs with its integration's own Client Secret.

func Signed

func Signed(secret string, body []byte, given string) bool

Signed checks an HMAC-SHA256 of body, given in hex or base64.

func Verify

func Verify(preset, auth, secret string, h http.Header, body []byte, path string, now time.Time) bool

Verify checks a request by the secret of its preset. path is the secret the address carried ("" for none); a preset that takes the secret in the address is proved by it alone, any other refuses an address with one. Any failure is false, without saying which part was wrong.

func VerifyHeaders

func VerifyHeaders(preset, secret string, h http.Header, body []byte, now time.Time) bool

VerifyHeaders checks the signature or the token a preset carries in its headers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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