diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 656de9cf6..caf796cab 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -1132,11 +1132,14 @@ OpenAI shape can't carry. GET, POST, PUT, PATCH and DELETE `proxyIdentity`: every name lanGuard reads as forwarded (`forwardHeaders`: `Forwarded`, `X-Forwarded-For`, `X-Real-IP`, `Cf-Connecting-IP`, `True-Client-IP`, `Tailscale-User-Login`), any - `X-Forwarded-*`, `Cf-*` and `Tailscale-*` (Tailscale Serve's user - login, name and picture), `Via`, `X-Client-IP` and + `X-Forwarded-*`, `Cf-*`, `Tailscale-*` (Tailscale Serve's user + login, name and picture) and `X-HC-*` (a LazyCat box's ingress: the + box account signed in, its role and device), `Via`, `X-Client-IP` and `X-Original-Forwarded-For`. The Codex passthrough and relay to the ChatGPT backend (`copyHeaders`) and the MCP proxy drop the same; see `TestNativeAnyDropsProxyIdentity` and `TestPassthroughDropsProxyIdentity`. + A provider's `PassHeaders` still passes on the names it lists, these + too: the user chose them. `Sign` puts in the provider's key as it takes one, and magpie's User-Agent goes in (`stampUA`). The answer's hop headers, `Set-Cookie`, `Alt-Svc` and HSTS don't come back (`nativeAnswerDropped`). diff --git a/internal/gateway/native.go b/internal/gateway/native.go index 00250a08f..cb2cf92e9 100644 --- a/internal/gateway/native.go +++ b/internal/gateway/native.go @@ -313,9 +313,12 @@ func nativeHeaderDropped(k string) bool { // proxyIdentity says k is what a proxy or tunnel in front of magpie says // of the caller: its address (every forwardHeaders entry, X-Forwarded-*, // Cloudflare's Cf-*) or who it is (Tailscale Serve's Tailscale-User-Login, -// the user's email, -Name and -Profile-Pic). It is for magpie to judge a -// request by (proxied), never for a vendor or a server magpie passes the -// request on to. +// the user's email, -Name and -Profile-Pic; a LazyCat box's X-HC-*, the +// box account a signed-in browser or app is, its role, its device and +// when it signed in, which the box's ingress adds to every request it +// passes an app, the gateway's client routes too). It is for magpie to +// judge a request by (proxied), never for a vendor or a server magpie +// passes the request on to. func proxyIdentity(k string) bool { k = http.CanonicalHeaderKey(k) if slices.ContainsFunc(forwardHeaders, func(h string) bool { return http.CanonicalHeaderKey(h) == k }) { @@ -325,7 +328,7 @@ func proxyIdentity(k string) bool { case "Forwarded", "Via", "X-Real-Ip", "True-Client-Ip", "X-Client-Ip", "X-Original-Forwarded-For": return true } - return strings.HasPrefix(k, "X-Forwarded-") || strings.HasPrefix(k, "Cf-") || strings.HasPrefix(k, "Tailscale-") + return strings.HasPrefix(k, "X-Forwarded-") || strings.HasPrefix(k, "Cf-") || strings.HasPrefix(k, "Tailscale-") || strings.HasPrefix(k, "X-Hc-") } // nativeAnswerDropped are the vendor's answer headers that don't come diff --git a/internal/gateway/proxy_identity_test.go b/internal/gateway/proxy_identity_test.go index 7334e0997..c21ce45c6 100644 --- a/internal/gateway/proxy_identity_test.go +++ b/internal/gateway/proxy_identity_test.go @@ -14,11 +14,17 @@ import ( // identityHeaders are what a proxy or tunnel in front of magpie says of // the caller: where it is, and with Tailscale Serve who (the user's -// email, name and picture). +// email, name and picture). A LazyCat box's ingress (lzc-ingress, in +// front of every app on the box) says who too: the box account signed +// in, its role and groups, the device and the sign-in's ticket, as the +// box's own docs and a request to a probe app on a box (lzcos 1.6.2) +// name them. var identityHeaders = []string{ "Forwarded", "X-Forwarded-For", "X-Forwarded-Host", "X-Forwarded-Proto", "X-Real-IP", "Via", "Cf-Connecting-IP", "Cf-Ipcountry", "True-Client-IP", "Tailscale-User-Login", "Tailscale-User-Name", "Tailscale-User-Profile-Pic", + "X-Forwarded-By", "X-HC-User-ID", "X-HC-User-Role", "X-HC-User-Groups", "X-HC-User-Ticket", "X-HC-Source", + "X-HC-Login-Time", "X-HC-Device-ID", "X-HC-Device-PeerID", "X-HC-Device-Version", "X-HC-Original-Host", } // identityHeadersOn is a request's headers: every identity header, and