-
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
kong.service.request.set_raw_query() doesn't work reliably #10080
Comments
We have planed an investigation into this issue. |
Hi @shanexguo I am working on this to find a long term solution. It appears that the problem occurs (as per my older investigation in the issue you have linked) when the nginx variable In order to unblock you and also understand whether this would fit your use case, could you test the following code?
|
Just an update on my investigation and a summary of what appears to be happening:
The problem is that after Later, when we access
Fixing this in the pdk should be easy enough, I will follow up with some update soon |
Avoid accessing ngx.var.args and fetch the raw query string from the request_uri. Accessing ngx.var.args was causing issue #10080. We might want to restrict access to happen solely via ngx.var.* in the future and/or to implement some index refreshing logic in lua-kong-nginx-module but right now this is the easiest way to avoid the problem in the pdk.
Many thanks for the update. It would be awesome if we can call the PDK API
to both read, update, and set the query parameters. For now, we are using
various workarounds in our plugin code to avoid this issue. These
bind-aid type of codes are pretty ugly :)
Thanks,
…On Tue, Jan 24, 2023 at 10:32 AM Samuele Illuminati < ***@***.***> wrote:
Just an update on my investigation and a summary of what appears to be
happening:
- get_raw_query() returns: ngx.var.args
- set_raw_query() invokes: ngx.req.set_uri_args()
- We patch the ngx.var metatable
<https://github.com/Kong/lua-kong-nginx-module/blob/master/lualib/resty/kong/var.lua#L153-L187>
to improve performance of get and set on ngx.var.* variables.
The problem is that after args has been indexed once, if
ngx.req.set_uri_args() is called, it modifies the value of args without
accessing the metatable, i.e. without using our patched index.
Later, when we access ngx.var.args to populate upstream_uri
<https://github.com/Kong/kong/blob/e95b730952cf2bcd77dcc442a04b497a6ab49ffa/kong/runloop/handler.lua#L1310>,
we read through our patched index (which remained outdated) and find the
inconsistent value. This means that after any access to ngx.var.args ,
any subsequent call to ngx.req.set_uri_args() will be ineffective.
ngx.req.set_uri_args("foo=bar") --> args is not yet indexed --> this works
a = ngx.var.args --> does a get(), indexes the variable
ngx.req.set_uri_args("upd=val") --> this is ineffective
print(ngx.var.args) --> prints "foo=bar"
Fixing this in the pdk should be easy enough, I will follow up with some
update soon
—
Reply to this email directly, view it on GitHub
<#10080 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXINGJCCYEELYIPQDR666PLWT7YYPANCNFSM6AAAAAATTE62RM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate our index whenever the function is called. fix for Kong/kong#10080
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate our index whenever the function is called. fix for Kong/kong#10080
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate our index whenever the function is called. fix for Kong/kong#10080
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate our index whenever the function is called. fix for Kong/kong#10080
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate our index whenever the function is called. fix for Kong/kong#10080
totally agree @shanexguo , the fix is in progress, what I provided was just a temporary workaround. Glad you are not blocked by this. |
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate our index whenever the function is called. fix for Kong/kong#10080
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate our index whenever the function is called. fix for Kong/kong#10080
set_uri_args modifies the $args variable without accessing our patched metatable. For it to work we need to invalidate the index whenever this function is called. fix for Kong/kong#10080
Which Kong release version will this fix be included? Thanks
…On Mon, Jan 30, 2023, 01:50 Datong Sun ***@***.***> wrote:
Closed #10080 <#10080> as completed
via #10181 <#10181>.
—
Reply to this email directly, view it on GitHub
<#10080 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXINGJG76TFQ5F5VVVRQEBTWU5QEFANCNFSM6AAAAAATTE62RM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This fix will be part of Kong 3.2.0. |
Is there an existing issue for this?
Kong version (
$ kong version
)3.0+
Current Behavior
When we tried to use the Kong API to manipulate the incoming HTTP request query parameters, e.g. in the plugin "access" function, like below:
We noticed that the set_raw_query() method doesn't work. I've found an existing bug report on the same issue, see the link below:
#9492
We don't like calling ngx.var.args to achieve the same goal, as it invokes yet another API. Plus, we've found that even this API doesn't work if the original HTTP request doesn't have any query parameters.
Our conclusion, after experimenting with both API, is that they don't work reliably for all situations. We want it to work consistently as specified below:
Expected Behavior
The above 3 steps should always work in the Kong plugin access phase.
Steps To Reproduce
Anything else?
No response
The text was updated successfully, but these errors were encountered: