hooksig

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 9 Imported by: ? 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

Signatures of the events services post to webhooks: the schemes services sign with, a table the verifier reads in its order, alpha's generic one among them (X-Webhook-Signature-V2 over a timestamp and the body, X-Webhook-Signature over the body alone); the secret of a webhook and the one before it while a rotation overlaps; and the lines a person writing a sender follows

Index

Constants

View Source
const (
	// Whatever scheme the event comes signed in, as alpha checks: the first of the table whose headers it carries decides
	Auto      = "auto"
	Standard  = "standard"
	Icebath   = "icebath"
	Linear    = "linear"
	GitHub    = "github"
	GitLab    = "gitlab"
	Generic   = "generic"
	GenericV1 = "generic-v1"
)

Names a webhook picks its scheme by

View Source
const (
	SignatureV2Header = "X-Webhook-Signature-V2"
	TimestampHeader   = "X-Webhook-Timestamp"
	SignatureV1Header = "X-Webhook-Signature"
	IcebathHeader     = "X-Icebath-Signature-256"
)

Headers of the generic scheme and of icebath's own events

View Source
const Window = 5 * time.Minute

How far a signed timestamp may be from the listener's clock before the event counts as sent again by someone who saw it: alpha's 300 seconds, either way

Variables

View Source
var Schemes = []Scheme{
	{Name: Standard, Title: "Svix and Standard Webhooks", About: "webhook-id, webhook-timestamp and webhook-signature, or svix- ones", /* contains filtered or unexported fields */},
	{Name: Icebath, Title: "icebath's own", About: "X-Icebath-Signature-256 as icebath's shell hooks and tests sign", Written: true,
		Replayable: true,
		// contains filtered or unexported fields
	},
	{Name: Linear, Title: "Linear", About: "linear-signature, the hex HMAC of the body", /* contains filtered or unexported fields */},
	{Name: GitHub, Title: "GitHub", About: "X-Hub-Signature-256, sha256= and the hex HMAC of the body", /* contains filtered or unexported fields */},
	{Name: GitLab, Title: "GitLab", About: "X-Gitlab-Token, the secret itself", Replayable: true, /* contains filtered or unexported fields */},
	{Name: Generic, Title: "Generic, with a timestamp", About: "X-Webhook-Signature-V2 over X-Webhook-Timestamp and the body", Written: true, /* contains filtered or unexported fields */},
	{Name: GenericV1, Title: "Generic, the body alone", About: "X-Webhook-Signature over the body, open to being sent again",
		Replayable: true, Written: true,
		// contains filtered or unexported fields
	},
}

The schemes, in the order the verifier asks whether an event carries each, as alpha does: Svix and Standard Webhooks, icebath's own, Linear, GitHub, GitLab, then the generic one with a timestamp, then the generic one of the body alone

Functions

func Names

func Names() []string

Every name a webhook may pick, Auto first

func Sign

func Sign(scheme string, header http.Header, body []byte, secret string, now time.Time) bool

Sets the headers a sender of the scheme sets for the body at the time, as icebath signs its tests and what it carries; false for a name no scheme has, Auto signing as the generic scheme with a timestamp, which no one who saw the event can send again

Types

type Refusal

type Refusal struct {
	Reason string
	Scheme string
}

Why an event's signature was refused, a sentence a sender reads, and the scheme it was checked in, empty when none

func (*Refusal) Error

func (r *Refusal) Error() string

type Request

type Request struct {
	Header http.Header
	Body   []byte
	Now    time.Time
}

One event posted to a webhook: its headers and its body as they came, and the time it is judged at

type Scheme

type Scheme struct {
	// Word a webhook names it by, and what a person calls it and what signs that way
	Name, Title, About string
	// It signs the body alone, with no time, so an event seen once can be sent again and still match
	Replayable bool
	// The scheme is icebath's own, for senders a person writes: a webhook of it is shown the lines such a sender follows
	Written bool
	// contains filtered or unexported fields
}

One way services sign what they post

func Named

func Named(name string) (Scheme, bool)

The scheme of the name, Auto among them; false for a name no scheme has

func (Scheme) Sender

func (s Scheme) Sender(address string) []string

Lines a person follows to post to the address signed in the scheme: the exact headers and what each holds for a scheme a person writes a sender of, where to give the secret for a service's own; none for Auto

type Secrets

type Secrets struct {
	Current, Previous string
	PreviousUntil     time.Time
}

Secrets a webhook takes: its own, and the one it had before a rotation, taken too until the overlap ends

type Verdict

type Verdict struct {
	Scheme     string
	Previous   bool
	Replayable bool
}

What a signature that matched proved: the scheme it came in, that it was signed with the secret before a rotation, and that the scheme signs the body alone, so whoever saw the event could send it again

func Verify

func Verify(r Request, scheme string, secrets Secrets) (Verdict, error)

Whether the event's signature matches one of the secrets in the scheme the webhook takes, Auto taking the first of the table whose headers the event carries and no other, as alpha does: a timestamped generic signature with no timestamp is refused, never checked as one of the body alone. A scheme the webhook names takes events signed that way alone. The secret before a rotation is taken until the overlap ends. Refused with a Refusal saying why

Jump to

Keyboard shortcuts

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