Help us shape the future of Go! Take the 2026 Go Developer Survey

whauth

package
v1.152.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package whauth decides whether a request to a webhook source came from its sender (#1870). It holds no state and writes nothing: the receiver hands it the source, the request's headers, the path token if there was one, and the body, and it answers with nil or with the reason the request is refused.

Every comparison of a secret, or of something computed from one, is constant-time.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingSignature = errors.New("the signature header is missing")
	ErrBadSignature     = errors.New("the signature does not match")
	ErrMissingTimestamp = errors.New("the timestamp header is missing")
	ErrMissingID        = errors.New("the delivery id header is missing")
	ErrBadTimestamp     = errors.New("the timestamp is not a Unix time in seconds or milliseconds")
	ErrStaleTimestamp   = errors.New("the timestamp is outside the tolerance window")
	ErrMissingToken     = errors.New("the token is missing")
	ErrBadToken         = errors.New("the token does not match")
	ErrExpiredToken     = errors.New("the token has expired")
	ErrBadCredentials   = errors.New("the basic credentials do not match")
	ErrUnknownMode      = errors.New("the source's auth mode is not recognized")
)

Reasons a request is refused. They are what the source's page lists beside a rejected request, so they name what was wrong without echoing what was sent.

Functions

This section is empty.

Types

type Request

type Request struct {
	Header http.Header
	// PathToken is the segment after the source name, /hooks/{name}/{token},
	// and empty when the request had none.
	PathToken string
	Body      []byte
}

Request is what verification reads from one request.

type Verifier added in v1.152.1

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

Verifier verifies requests for one source. Its signed-bytes template, header pattern and body paths are compiled once, when the source is loaded, so nothing about them is parsed per request (#2223).

func Compile added in v1.152.1

func Compile(src whsource.Source) (*Verifier, error)

Compile builds the verifier for a source with its defaults applied. It refuses a source whose settings do not compile, which Validate refuses too. A mode it does not know compiles to a verifier that refuses every request: a form's source has none, and is never posted to.

func (*Verifier) Verify added in v1.152.1

func (v *Verifier) Verify(req Request, now time.Time) error

Verify reports whether req is authentic at now.

Jump to

Keyboard shortcuts

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