selftest

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package selftest signs and verifies the X-Scout-Scan header that Scout puts on every outbound scan request. Sentinel (or any app) can verify it to tag Scout traffic as a self-test rather than a real attacker.

Header format:

X-Scout-Scan: v1;ts=<unix seconds>;scan=<scan id>;sig=<hex hmac>

The signature is HMAC-SHA256 over the version, timestamp, scan ID, method, host and path, so a captured header cannot be replayed against another endpoint or reused after the allowed clock skew.

Index

Constants

View Source
const DefaultMaxSkew = 5 * time.Minute

DefaultMaxSkew is how far a header timestamp may drift from the verifier's clock.

View Source
const Header = "X-Scout-Scan"

Header is the self-test header name.

Variables

View Source
var (
	ErrMissing   = errors.New("selftest: header missing")
	ErrMalformed = errors.New("selftest: header malformed")
	ErrExpired   = errors.New("selftest: timestamp outside allowed skew")
	ErrSignature = errors.New("selftest: signature mismatch")
)

Verification errors.

Functions

func NewKey

func NewKey() []byte

NewKey returns a random 32-byte signing key.

func Sign

func Sign(r *http.Request, key []byte, scanID string, now time.Time)

Sign sets the self-test header on r.

Types

type Info

type Info struct {
	ScanID string
	Time   time.Time
}

Info is what a valid header tells the verifier.

func Verify

func Verify(r *http.Request, key []byte, now time.Time, maxSkew time.Duration) (Info, error)

Verify checks the self-test header on an incoming request. Host is taken from r.Host, which is what the signer saw as the URL host.

type Transport

type Transport struct {
	Base   http.RoundTripper
	Key    []byte
	ScanID string
	Now    func() time.Time
}

Transport signs every request it sends. It clones the request so callers' requests are never mutated.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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