-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
bug: URI encoding issue #5654
Comments
pls show the config of route |
{ |
Based on this configuration, what do you want to achieve and what are the expected results?
there is some confusion here, I cannot got it. |
I am facing this error |
@tzssangglass Simply we are trying to reroute an URL to an internal server by replacing ( deleting ) endpoint prefix E.g /api/groups/... -> my.internal.server/groups/.... so we have used I'm calling this endpoint |
The regex pattern is |
Here are the steps I took to reproduce it on master branch
master_process on;
worker_processes 2;
error_log logs/error.log warn;
pid logs/nginx.pid;
worker_rlimit_nofile 20480;
events {
accept_mutex off;
worker_connections 10620;
}
worker_shutdown_timeout 3;
http {
server {
listen 1980;
access_log off;
location / {
content_by_lua_block {
ngx.say("uri: ", ngx.var.uri)
}
}
}
}
curl --location --request PUT 'http://127.0.0.1:9080/apisix/admin/routes/1' \
--header 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
--header 'Content-Type: application/json' \
--data-raw '{
"plugins": {
"proxy-rewrite": {
"regex_uri": ["^/api/(.*)","/$1"]
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/api/groups/*"
}'
$curl http://127.0.0.1:9080/api/groups/%3CNumber%3E
uri: /groups/<Number> Is this what you want? |
you can refer to: https://github.com/apache/apisix/blob/master/docs/en/latest/FAQ.md#how-to-strip-route-prefix-for-path-matching to learn how to strip route prefix |
No this is not, we already managed to strip the route prefix by using the regex. The issue is the gateway server decoding the route and not encoding it again, what I want is when submitting this request I need to get this
NOT that: |
This is the regex Regex is matched and the url redirected to the proper server, but url is decoded!! Not encoded, and my application server is rejecting such characters |
ok, I've had a look around and I don't think it's a bug. Nginx will escape the so I recommend not using %3C in the uri. refer to: https://juejin.cn/post/6844903512485134343#heading-5 cc @tokers |
I think it's a bug. I also had this issue when using apisix to route request to backend gerrit code-review server. Instead, when I use nginx to route, things are ok, the %2F is not auto decoded and keep original. |
cc @tokers @spacewander PLAT |
I also got this problem while trying to proxy
So how to achieve this using apisix? And it is possible to have a switch about the normalization in the future? |
That's to say, using |
I think the APISIX should encode the special character '%' before decoding it to keep the special '%' in its original format. |
Why APISIX? |
@tokers Cause APISIX will decode it but the encoding work should be respected cause the APISIX is the middle-man not the final-man. |
cc @spacewander @membphis, do you have any options about this? |
This behavior breaks the client's behavior. |
People want APISIX to use a specific URL escape rule to solve some edge problems, like whether |
I'm not sure what circumastances will break the client's behavior. But I think APISIX should at least leave a chance to intercept the request or to reencode it back to its original format.
|
It's unfair to ask APISIX to use specific escape rule to solve some edge problems, but how about leaving the original request along with its orignal style and forwarding it to the backend? I think the middle-steps do whatever might be necessary. |
I still cannot agree it, this makes the URI handling more complicated and error-prone. Just like @spacewander said, the URI encoding/decoding rules are not so standard across platforms. |
I agree with @tokers and @spacewander 's opinion |
Consider solved. Feel free to reopen it if needed. |
Then, why should APISIX decode the encoded-paramters instead of keeping it as origin? |
In my circumastance, I have to setup a |
@cloorc apisix/apisix/plugins/proxy-rewrite.lua Line 182 in bf3e232
|
Thanks! I agree it looks unfriendly but it is not my real purpose. If it makes some guys uncomfortable, I should appologize anyway. Back to this issue, I have to post my real consideration, although it might be a little fierce. BTW, no threats should to anyone, both maintainers and users and anyone cared about this project. |
Issue description
I created a route
/api/v1/groups/*
and made a URI Override
Regexp: /api(/v1/groups/.*)
now, I am trying this url
127.0.0.1:9080/api/v1/groups/
and facing this issue
HTTP Status 400 – Bad Request
submitted request
https://mydomain.com/api/v1/groups/%3CNumber%3E
forwarded request
127.0.0.1:9080/api/v1/groups/
Environment
apisix version
): 2.5uname -a
): 60-Ubuntu SMPnginx -V
oropenresty -V
): openresty/1.19.9.1curl http://127.0.0.1:9090/v1/server_info
to get the info from server-info API): "3.4.0"luarocks --version
): 3.4.0Steps to reproduce
//
Actual result
HTTP Status 400 – Bad Request
Error log
//
Expected result
No response
The text was updated successfully, but these errors were encountered: