feat(web): forward end-user client IP to bunyip-api #361
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/BUNYIP-311-web-forward-client-ip"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
bunyip-web is an SSR BFF: the browser talks only to it (through Traefik) and it calls bunyip-api server-to-server, so bunyip-api saw the BFF process as the peer and lost the end-user IP for logging, rate-limiting, and audit. This adds the missing second hop of the trust chain (Traefik to bunyip-web to bunyip-api).
A per-request middleware (
client_ip::forward_client_ip) resolves the end-user IP from the inbound X-Forwarded-For / X-Real-IP, honoured ONLY when bunyip-web's own socket peer is inside itsTRUSTED_PROXY_CIDR; otherwise it forwards nothing rather than fabricate an IP. The resolved IP is scoped into a task-local so all three outbound API send paths (JSONsend, streamingget_stream, multipartpost_form) attach it as X-Forwarded-For at one choke point, instead of threading it through every handler call site.servenow usesinto_make_service_with_connect_infoso the middleware can read the socket peer.bunyip-api then reads that header as the external client when bunyip-web's address is in bunyip-api's
TRUSTED_PROXY_CIDR. compose.yml wires both hops (WEB_TRUSTED_PROXY_CIDR for the web service, TRUSTED_PROXY_CIDR for the api service) and docs/client-ip-forwarding.md plus .env.example document the two-hop trust chain and the required CIDR entries on each service.#BUNYIP-311