bug: proxy-rewrite silently drops duplicate keys in headers.add due to JSON object limitation
Current Behavior
When configuring headers.add in the proxy-rewrite plugin with multiple values for the same header name, only the last value is forwarded to upstream. All earlier values are silently dropped with no warning, error log, or validation message.
This is caused by a fundamental JSON limitation: duplicate keys in an object are undefined behavior by spec. In practice, Lua's cjson parser (used by APISIX/OpenResty) only retains the last occurrence of a duplicate key when deserializing the plugin config.
For example, the following config:
"headers": {
"add": {
"foo": "bar2",
"foo": "bar3"
}
}
Results in only foo: bar3 being added. The value bar2 is lost entirely at config parsing time, before the plugin even executes.
Expected Behavior
Either:
- The schema should support multi-value headers via an array syntax, e.g. "foo": ["bar1", "bar2"], so users can express the intent without relying on duplicate JSON keys.
- Or, the admin API should reject configs with duplicate keys and return a validation error, rather than silently accepting and dropping values.
Error Logs
No error logs are produced.
Steps to Reproduce
- Create a route with the following config:
curl -X PUT 'http://127.0.0.1:9180/apisix/admin/routes/1' \
-H 'X-API-KEY: <admin_key>' \
-H 'Content-Type: application/json' \
-d '{
"uri": "/anything",
"plugins": {
"proxy-rewrite": {
"headers": {
"add": {
"foo": "bar2",
"foo": "bar3"
}
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": { "httpbin.org:80": 1 }
}
}'
- Send a test request:
curl -X GET -H 'foo: bar1' 'http://127.0.0.1:9080/anything'
- Observe the echoed headers in the response — only foo: bar3 is present. foo: bar2 is missing with no error.
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 423
Connection: keep-alive
Date: Mon, 06 Apr 2026 04:09:23 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/3.15.0
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Foo": "bar1,bar3",
"Host": "127.0.0.1",
"User-Agent": "curl/7.81.0",
"X-Amzn-Trace-Id": "<redacted>",
"X-Forwarded-Host": "127.0.0.1:9080"
},
"json": null,
"method": "GET",
"origin": "127.0.0.1, <redacted>",
"url": "http://127.0.0.1:9080/anything"
}
Environment
- APISIX version (run
apisix version): 3.15.0 - Operating system (run
uname -a): Ubuntu - OpenResty / Nginx version (run
openresty -Vornginx -V): - etcd version, if relevant (run
curl http://127.0.0.1:9090/v1/server_info): - APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run
luarocks --version):
https://github.com/apache/apisix/issues/11587#issuecomment-4196804266 - possible workaround
This isn't something APISIX can detect or fix on its side — duplicate keys in a JSON object are undefined behavior per RFC 8259, and the JSON parser (lua-cjson, invoked in apisix/admin/init.lua before schema validation) collapses them to the last value before the Admin API or the plugin ever sees the config. Rejecting duplicate keys would require a custom JSON scanner over the raw request body, which no JSON-based API I'm aware of does.
The practical way to express multi-value headers today is a comma-joined value like "add": {"foo": "bar2,bar3"}, which is semantically equivalent for comma-list headers per RFC 9110 — your own httpbin output ("Foo": "bar1,bar3") shows the append semantics work. Supporting array syntax like "foo": ["bar2", "bar3"] in headers.add would be a reasonable feature request though — the schema in apisix/plugins/proxy-rewrite.lua currently only allows string/number values. I'd suggest closing this as a bug and reframing the array-value support as a feature request so it can be discussed on its own merits.