Project case study
Trust the peer before the header
Establishing visitor identity through two explicit proxy boundaries, with synthetic tests and privacy-conscious logging.
Problem
The Go API’s socket peer is Caddy, rather than the browser. Future request budgets need a trustworthy visitor identity, but a header name cannot establish who supplied its value. Blindly trusting a forwarded address would let a caller choose an identity and undermine later rate limiting.
This is a study of identity plumbing implemented in Ask Habib. It does not claim that the future rate limiter or chat service is already running.
Two explicit boundaries
The deployment accepts a Cloudflare visitor-address header only across configured peers. Caddy first checks that the connection came from the exact tunnel connector address. It strips the identity header for other peers. The API then checks that its socket peer is the exact configured Caddy address before considering that header.
The checks use exact peers rather than trusting an entire private subnet. Other forwarding headers are ignored. The API requires one valid address, rejects duplicate or malformed values, and normalises IPv4-mapped IPv6 addresses. An absent trusted identity stays absent; an arbitrary request does not get to supply a replacement.
Verification without retaining visitor addresses
Integration tests send synthetic visitor identities through trusted and untrusted paths. They exercise both Caddy’s stripping behaviour and the API’s peer checks, including malformed and duplicate headers. Local tests use Podman; release CI repeats the container checks on native Linux AMD64.
A temporary, expiring diagnostic response supported a private comparison between Cloudflare’s view of the requester and the API’s derived identity. It was disabled after verification. Normal application logs record whether a trusted identity was available, without retaining raw visitor addresses. Caddy’s runtime error logging also excludes the request object, which could otherwise contain addresses and headers during a backend failure.
A public forged-header probe was rejected before it reached the API. That observation is narrower than proof of which intermediary rejected it. The synthetic integration tests provide separate evidence for the application’s own boundary enforcement.
Tradeoffs
Exact peer addresses make the trust relationship easy to inspect, but network configuration changes must update the matching application settings. A compromised trusted proxy would still be inside the boundary. Network placement and credential handling therefore remain part of the model.
An address is also an imperfect basis for future budgets: shared networks can group several people, and address changes can separate one person’s requests. Later rate limiting must account for that limitation. This work establishes the provenance of an input; it does not solve every abuse or authentication problem.
Result
Ask Habib has a tested path for obtaining visitor identity, fails closed when the trusted input is unavailable, and leaves normal logs free of raw addresses. The ingress study describes the surrounding network route, while ADR-003 records the ingress choice.