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 ¶
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 ¶
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 Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator is an immutable Host/Origin decision primitive.
func New ¶
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 ¶
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.