Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-proxy-relay-header-hygiene.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **The egress proxy no longer forwards agent-asserted identity headers.** Proxy-Authorization, Proxy-Connection, Forwarded, X-Forwarded-* and X-Hive-* headers on an agent request are now stripped by the plain-HTTP forward, the MITM relay and the sandbox read relay before the request reaches an origin.
42 changes: 42 additions & 0 deletions src/crux/proxy/agent_header_hygiene.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package proxy

import (
"net/http"
"strings"
)

// stripAgentHopIdentityHeaders removes, from a request an agent sent, every
// header that asserts something about the hop or the caller rather than about
// the request itself (#18993):
//
// - Proxy-Authorization and Proxy-Connection address THIS proxy. The identity
// they carry is the one the proxy already decided whether to believe, and
// in the Basic form the password field is whatever the agent put there.
// - X-Forwarded-* and Forwarded describe the client a reverse proxy saw. An
// origin that trusts them (rate limiting, audit, allowlists) would record
// the address or scheme the agent chose instead of the real one.
// - X-Hive-* is the hive's own trust namespace: the dashboard reads
// X-Hive-User and X-Hive-Role as set by its auth layer. An agent request
// carrying them is an attempt to speak with the hive's voice, and no hop
// past this proxy has any business receiving one from an agent.
//
// Names are matched on their canonical form so a hand-written lower-case
// header (`x-hive-role:`) is removed exactly as the canonical one is.
func stripAgentHopIdentityHeaders(h http.Header) {
for name := range h {
if agentHopIdentityHeader(name) {
delete(h, name)
}
}
}

// agentHopIdentityHeader reports whether a header name is one
// stripAgentHopIdentityHeaders removes.
func agentHopIdentityHeader(name string) bool {
canon := http.CanonicalHeaderKey(name)
switch canon {
case "Proxy-Authorization", "Proxy-Connection", "Forwarded":
return true
}
return strings.HasPrefix(canon, "X-Forwarded-") || strings.HasPrefix(canon, "X-Hive-")
}
Loading
Loading