HTTP Headers
You can configure the Forwarded, X-Forwarded-* and X-Real-IP headers of outbound requests with these options:
- Set headers:
forwarded.set_outbound.forwarded: sets theForwardedheader per RFC 7239 specifications, using the parametersfor,by,host, andprotoforwarded.set_outbound.x-forwarded: setsX-Forwarded-Forheader to chain of IP addresses from the original client to the last proxy serverforwarded.set_outbound.x-real-ip: sets theX-Real-IPheader to the original client IP address
- Preserve headers of the inbound request (use only if you trust the request source):
forwarded.preserve_inbound.forwarded: preserves the inboundForwardedheaderforwarded.preserve_inbound.x-forwarded: preserves the inboundX-Forwarded-Forheaderforwarded.preserve_inbound.x-real-ip: preserves the inboundX-Real-IPheader
caution
Only preserve inbound headers if you trust the source of the inbound request to avoid spoofed headers.
Here's an example configuration:
- Environment variables
- HCL
- JSON
- TOML
- YAML
GATE_HEADERS_FORWARDED_SET_OUTBOUND_FORWARDED=true
GATE_HEADERS_FORWARDED_SET_OUTBOUND_X_FORWARDED=true
GATE_HEADERS_FORWARDED_SET_OUTBOUND_X_REAL_IP=true
GATE_HEADERS_FORWARDED_PRESERVE_INBOUND_FORWARDED=true
GATE_HEADERS_FORWARDED_PRESERVE_INBOUND_X_FORWARDED=true
GATE_HEADERS_FORWARDED_PRESERVE_INBOUND_X_REAL_IP=true
gate = {
headers = {
forwarded = {
set_outbound = {
forwarded = true
x-forwarded = true
x-real-ip = true
}
preserve_inbound = {
forwarded = true
x-forwarded = true
x-real-ip = true
}
}
}
}
{
"gate": {
"headers": {
"forwarded": {
"set_outbound": {
"forwarded": true,
"x-forwarded": true,
"x-real-ip": true
},
"preserve_inbound": {
"forwarded": true,
"x-forwarded": true,
"x-real-ip": true
}
}
}
}
}
[gate.headers]
forwarded.set_outbound.forwarded = true
forwarded.set_outbound.x-forwarded = true
forwarded.set_outbound.x-real-ip = true
forwarded.preserve_inbound.forwarded = true
forwarded.preserve_inbound.x-forwarded = true
forwarded.preserve_inbound.x-real-ip = true
gate:
headers:
forwarded:
set_outbound:
forwarded: true
x-forwarded: true
x-real-ip: true
preserve_inbound:
forwarded: true
x-forwarded: true
x-real-ip: true
To debug issues with the configuration of HTTP headers, use log level trace.
Disable Via headers
By default, Gate adds a Via header to all response.
You can disable this behaviour with the following option:
- Environment variables
- HCL
- JSON
- TOML
- YAML
GATE_HEADERS_VIA_DISABLED=true
gate = {
headers = {
via = {
disabled = true
}
}
// ...
}
{
"gate": {
"headers": {
"via": {
"disabled": true
}
}
// ...
[gate.headers]
via.disabled = true
gate:
headers:
via:
disabled: true
Some request headers should only ever be set by a trusted hop between Gate and your upstream, never by a client. Gate can remove such headers from every inbound request, so a client cannot spoof them:
- The headers are removed before URL matching, request signature verification and all plugins, so neither the plugins nor the upstream see them. A plugin can still set a header with one of these names.
- Don't list a header that is a signed component of your request signatures.
- Names are case-insensitive, and every value of a multi-valued header is removed. Only request headers are affected, not request trailers.
- Propagation headers you list (for example
baggageortraceparent) are removed before trace-context extraction. - In
ext_authmode, Gate always tells Envoy to remove every listed header. If yourext_authzfilter setsallowed_headers, include every listed header there too, so the plugins can't see them either. - Not supported in
aws_lambda_authmode: a non-empty list is a configuration error there. - Connection-level headers (
Connection,Upgrade,Host,Content-Length,Transfer-Encoding,TE,Trailer,Keep-Alive,Proxy-Connection) and HTTP/2 pseudo-headers can't be listed.
- Environment variables
- HCL
- JSON
- TOML
- YAML
Use a comma-separated list with no spaces around the commas:
GATE_HEADERS_REMOVE_INBOUND=X-Internal-Hop,X-Internal-Trusted
gate = {
headers = {
remove_inbound = ["X-Internal-Hop", "X-Internal-Trusted"]
}
// ...
}
{
"gate": {
"headers": {
"remove_inbound": ["X-Internal-Hop", "X-Internal-Trusted"]
}
// ...
[gate.headers]
remove_inbound = ["X-Internal-Hop", "X-Internal-Trusted"]
gate:
headers:
remove_inbound:
- X-Internal-Hop
- X-Internal-Trusted