-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(request-transformer): unpredictable overriding result from rename header to existing header caused by pairs disorder #9442
fix(request-transformer): unpredictable overriding result from rename header to existing header caused by pairs disorder #9442
Conversation
To prevent such issues from happening, would it not make sense to have all headers tables have this metatable:
That way, the normalization to lower case would happen automatically. |
It's a good idea but needs changes in the PDK(more like a patch on the original OpenResty's I feel it is better to open another PR for this change, and doing another lower case here is not very harmful, WDYT? |
Need a change log entry. |
238e138
to
1fda03c
Compare
1fbb32f
to
36d23ea
Compare
… header to existing header caused by pairs disorder
36d23ea
to
c48e5e1
Compare
c48e5e1
to
f88f2c6
Compare
Summary
This PR fixes a bug in the
request-transformer
plugin, where the rename header cannot override an already existing header steadily.If a header
A-header
already exists with a valueA-value
in the request, and therequest-transformer
plugin is configured to renameB-header
(with a valueB-value
) toA-header
(with different format, like all chars are capitalized), then the upstream request will contain anA-header
with possiblyA-value
orB-value
. This unpredictable behaviour may caused bypairs
function disorder behaviour(Again!).The code flow is as follows:
A
header
table is fetched byngx.req.get_headers
and used later for storing upstream request headerskong/kong/plugins/request-transformer/access.lua
Line 186 in c33d745
Then the rename header list will be iterated
kong/kong/plugins/request-transformer/access.lua
Lines 200 to 209 in c33d745
Note that in this code block, the
new_name
will be directly used for setting value in the table, and the headers fetched byngx.req.get_headers()
are in lower case, so ifnew_name
is an upper-case, then two keys with different format will exist in theheader
table.And that will lead to the unpredictable iterating sequence in setting headers:
kong/kong/plugins/request-transformer/access.lua
Line 247 in c33d745
kong/kong/pdk/service/request.lua
Lines 422 to 427 in c33d745
Full changelog
Issue reference
Fix FTI-4319 and #9418