hostcheck

package
v1.0.521 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 3 Imported by: 0 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

Package hostcheck implements MCP-INSP-008: the pure, listener-independent Origin/Host validation decision primitive for inbound MCP requests.

It is a DECISION FUNCTION, not a listener. It takes already-parsed header values (the Host / :authority and the Origin) plus a configured allowlist and returns an ALLOW / REJECT decision with a stable reason. It binds no socket, performs no network or DNS I/O, and is fully unit-testable without a server. The listener-side binding + per-request/per-HTTP2-stream enforcement and the end-to-end DNS-rebinding proof are MCP-INSP-009 (PR-5) and are deliberately NOT in this package.

The reviewed V1 posture (ADR-0024 §D-9) this primitive encodes:

  • Host allowlisting is MANDATORY. A request whose Host / :authority is absent or not on the allowlist is rejected.
  • A PRESENT Origin must be well-formed and allowlisted; a present-but-invalid or non-allowlisted Origin is rejected.
  • An ABSENT Origin is allowed by default: Culvert does NOT force every non-browser client to send Origin — unless the deployment/protocol revision opts in via RequireOrigin.

Index

Constants

View Source
const (
	ReasonAllowed          = "allowed"
	ReasonHostMissing      = "host_missing"
	ReasonHostNotAllowed   = "host_not_allowlisted"
	ReasonOriginRequired   = "origin_required"
	ReasonOriginInvalid    = "origin_invalid"
	ReasonOriginNotAllowed = "origin_not_allowlisted"
)

Stable machine reasons. ReasonAllowed accompanies an Allow; the rest accompany a Reject and are part of the package contract.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AllowedHosts   []string
	AllowedOrigins []string
	RequireOrigin  bool
}

Config configures a Validator. AllowedHosts and AllowedOrigins are matched exactly (case-insensitively) after normalization. AllowedHosts entries may be "host" or "host:port". AllowedOrigins entries are full origins ("scheme://host[:port]"). RequireOrigin makes a missing Origin a rejection.

type Decision

type Decision int

Decision is the outcome of a Host/Origin check.

const (
	// Reject is the zero value so a mis-constructed or zero Result fails closed.
	Reject Decision = iota
	// Allow permits the request (host allowlisted; origin acceptable).
	Allow
)

func (Decision) String

func (d Decision) String() string

String returns the decision label (allow/reject).

type Result

type Result struct {
	Decision Decision
	Reason   string
}

Result is the decision plus a stable reason string.

func (Result) Allowed

func (r Result) Allowed() bool

Allowed reports whether the result is an ALLOW (convenience for callers).

type Validator

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

Validator is an immutable Host/Origin decision primitive.

func New

func New(cfg Config) (*Validator, error)

New validates cfg and returns an immutable Validator. An empty host allowlist is rejected: host allowlisting is mandatory, so a validator that would allow every host is a configuration error, not a permissive default.

func (*Validator) Check

func (v *Validator) Check(host string, originPresent bool, origin string) Result

Check evaluates a request.

  • host is the Host or HTTP/2 :authority value (already extracted from the request). It is MANDATORY and must be on the allowlist.
  • originPresent reports whether an Origin header was sent; origin is its value. A present Origin must be well-formed and allowlisted. An absent Origin is allowed unless the Validator was built with RequireOrigin.

Check is a pure function of its inputs and the Validator's immutable state.

Jump to

Keyboard shortcuts

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