webhooksig

package
v2.22.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package webhooksig signs and verifies webhook requests the way the services that send them do: GitHub, Stripe, Slack, and senders that follow Standard Webhooks.

Index

Constants

View Source
const (
	// MaxEventLength bounds an event name a webhook takes or a log keeps.
	MaxEventLength = 120
	// MaxEvents bounds how many events a webhook names.
	MaxEvents = 50
)

Variables

View Source
var (
	ErrMismatch = errors.New("the signature does not match the signing secret")
	ErrStale    = errors.New("the signature was made more than 5 minutes before or after the request arrived")
)

Senders lists every format, in the order a person chooses among them.

Functions

func CheckSecret

func CheckSecret(s Sender, secret string) error

CheckSecret reports whether secret has the form the sender's signing secrets take.

func Event

func Event(header http.Header, body []byte) string

Event names what a request is about, as its sender labels it: an event header, with GitHub's action after a dot, or else the type or event the body names, as Stripe and Standard Webhooks senders do, or the type of the event Slack wraps. It is empty when the request names none.

func Events

func Events(written []string) ([]string, error)

Events returns the events a webhook takes as written: trimmed, once each, in the order written, and nil when none is named.

func IsGitHubPing

func IsGitHubPing(header http.Header) bool

IsGitHubPing reports whether a request is the ping GitHub sends when a webhook is created.

func NewSecret

func NewSecret() string

NewSecret returns a random signing secret for a sender, such as GitHub, that takes whatever secret it is given.

func Sign

func Sign(s Sender, secret string, body []byte, now time.Time) (http.Header, error)

Sign returns the headers that carry the sender's signature over body, made with secret at now.

func StandardKey

func StandardKey(secret string) ([]byte, error)

StandardKey is the key a Standard Webhooks signing secret holds: whsec_ followed by a base64 key of 24 to 64 bytes.

func StandardSignature

func StandardSignature(key []byte, id string, timestamp int64, body []byte) string

StandardSignature signs one message as Standard Webhooks specifies: an HMAC-SHA256 over the message identifier, the timestamp, and the body.

func Takes

func Takes(events []string, event string) bool

Takes reports whether a webhook taking events takes a request about event: every request when it names none, else one about an event it names or one under it, so issues takes issues.opened.

func Verify

func Verify(s Sender, secret string, header http.Header, body []byte, received time.Time) error

Verify checks that a request carries a valid signature by the sender over body, made with secret within 5 minutes of received.

Types

type Sender

type Sender string

Sender names a format of signed webhook requests.

const (
	GitHub   Sender = "github"
	Stripe   Sender = "stripe"
	Slack    Sender = "slack"
	Standard Sender = "standard"
)

func Parse

func Parse(name string) (Sender, error)

Parse returns the sender name names, or an error for a name this package does not know.

func (Sender) Valid

func (s Sender) Valid() bool

Valid reports whether s names a format this package knows.

Jump to

Keyboard shortcuts

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