whauth

package
v1.136.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 14 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")
	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")
	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

func Verify

func Verify(src whsource.Source, req Request, now time.Time) error

Verify reports whether req is authentic for src at now.

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.

Jump to

Keyboard shortcuts

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