mayankmurari opened a new issue, #13753:
URL: https://github.com/apache/apisix/issues/13753
### Description
I need to remove (or clear) the `X-Forwarded-Host` header for a specific API
route before it reaches the upstream service. Despite trying every available
approach, APISIX always sends the original `Host` header value as
`X-Forwarded-Host` to the upstream.
## What I've Tried
### 1. `proxy-rewrite` with `headers.remove`
```json
{
"plugins": {
"proxy-rewrite": {
"headers": {
"remove": ["X-Forwarded-Host"]
}
}
}
}
```
**Result:** `X-Forwarded-Host` still sent to upstream with original value.
### 2. `proxy-rewrite` with `headers.set` (empty string)
```json
{
"plugins": {
"proxy-rewrite": {
"headers": {
"set": {
"X-Forwarded-Host": ""
}
}
}
}
}
```
**Result:** `X-Forwarded-Host` still sent to upstream with original value.
Not overridden to empty string.
### 3. `proxy-rewrite` with `host` field
```json
{
"plugins": {
"proxy-rewrite": {
"host": "my-upstream.example.com"
}
}
}
```
**Result:** `X-Forwarded-Host` unchanged.
### 4. Upstream `pass_host: rewrite` with `upstream_host`
```json
{
"upstream": {
"pass_host": "rewrite",
"upstream_host": "my-upstream.example.com",
"nodes": { "my-upstream.example.com:443": 1 },
"scheme": "https"
}
}
```
**Result:** `X-Forwarded-Host` still sent with the APISIX ingress hostname.
### 5. `serverless-pre-function` setting `ngx.var.var_x_forwarded_host`
```json
{
"plugins": {
"serverless-pre-function": {
"phase": "before_proxy",
"functions": [
"return function(conf, ctx) ngx.var.var_x_forwarded_host = '' end"
]
}
}
}
```
**Result:** Plugin accepted (no errors), but `X-Forwarded-Host` still sent
with original value.
### 6. Custom plugin in `before_proxy` phase
Created a custom Lua plugin that runs in the `before_proxy` phase and sets
`ngx.var.var_x_forwarded_host = ''`.
**Result:** Plugin accepted, but `X-Forwarded-Host` still sent with original
value.
## Expected Behavior
At least one of the following should work:
- `proxy-rewrite` with `headers.remove: ["X-Forwarded-Host"]` should prevent
the header from being sent upstream
- `proxy-rewrite` with `headers.set: { "X-Forwarded-Host": "" }` should
override the header value
- `serverless-pre-function` with `ngx.var.var_x_forwarded_host = ''` in
`before_proxy` phase should clear the Nginx variable before `proxy_set_header`
uses it
- A custom plugin in `before_proxy` phase should be able to modify
`var_x_forwarded_host`
## Actual Behavior
None of the above approaches have any effect on the `X-Forwarded-Host`
header. The upstream always receives `X-Forwarded-Host` set to the APISIX
ingress hostname.
### Environment
**APISIX Version:** 3.17.0
**Deployment:** Kubernetes with APISIX Ingress Controller
**OS:** Linux (K8s pods)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]