Skip to content
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

help request: How to use proxy-pass plugin with regex_uri attributes when the url is encoded #9638

Closed
yujinchoi-94 opened this issue Jun 12, 2023 · 4 comments · Fixed by #9813
Assignees

Comments

@yujinchoi-94
Copy link

Description

Hi, I have to call an upstream server with encoded string.

For example,
I want to make a request like this.

curl -X GET "{apisix-server-address}/rest/alimi/alimianswer/1234/N/%ED%85%8C%EC%8A%A4%ED%8A%B8"

(%ED%85%8C%EC%8A%A4%ED%8A%B8 is encoded string)

I've found out that the apisix uses decoded URI coming from nginx through this
So, i've tried using use_real_request_uri_unsafe option, but it doesn't work with regex_uri.

Is there any way to call the upstream server with encoded string?


Here's my configuration.

- name: proxy-rewrite
  enable: true
	config:
		regex_uri:
			- /rest/alimi/alimianswer/(.+)/(.+)/(.+)
			- /cv/v1/emergency/answer?emerNtceSeq=$1&confirmYn=$2&answerCtnt=$3
    use_real_request_uri_unsafe: true

When I used the above configuration, the log result were like this

10.205.164.68 - - [12/Jun/2023:04:42:21 +0000] .... "GET /rest/alimi/alimianswer/1234/N/%ED%85%8C%EC%8A%A4%ED%8A%B8 HTTP/1.1" 400 808 0.077 "-" "curl/7.79.1" - - - "http://{upstream-server}"

What I want is to call the upstream server with below url

http://{upstream-server}/cv/v1/emergency/answer?emerNtceSeq=1234&confirmYn=N&answerCtnt=%ED%85%8C%EC%8A%A4%ED%8A%B8

Environment

  • APISIX version (run apisix version):
    • /usr/local/openresty//luajit/bin/luajit /usr/local/apisix/apisix/cli/apisix.lua version 3.2.0
  • Operating system (run uname -a):
    • Linux dev-apisix-6d55c4cfd5-nqw9x 5.4.226-129.415.amzn2.x86_64 #1 SMP Fri Dec 9 12:54:21 UTC 2022 x86_64 GNU/Linux
  • OpenResty / Nginx version (run openresty -V or nginx -V):
    • openresty -V nginx version: openresty/1.21.4.1
    • nginx -V nginx version: openresty/1.21.4.1
  • 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):
@Revolyssup
Copy link
Contributor

@yujinchoi-94 You dont need to use use_real_request_uri_unsafe here since you are passing the uri in regex_uri. You can remove it and it should work

@yujinchoi-94
Copy link
Author

yujinchoi-94 commented Jun 12, 2023

@Revolyssup
When i removed use_real_request_uri_unsafe attributes, encoded string is changed like below log.
Encoded string(%ED%85%8C%EC%8A%A4%ED%8A%B8) becomes\xED\x85\x8C\xEC\x8A\xA4\xED\x8A\xB8

Log
10.205.164.68 - - [12/Jun/2023:06:47:11 +0000] ... "GET /rest/alimi/alimianswer/1234/N/%ED%85%8C%EC%8A%A4%ED%8A%B8 HTTP/1.1" 400 808 0.330 "-" "curl/7.79.1" - - - "{upstream-server}/cv/v1/emergency/answer?emerNtceSeq=1234&confirmYn=N&answerCtnt=\xED\x85\x8C\xEC\x8A\xA4\xED\x8A\xB8"

@Revolyssup
Copy link
Contributor

Revolyssup commented Jun 12, 2023

ncoded string is changed like belo

Yep you're right. What you're trying to do is currently not supported because the support for allowing encoded string is only available currently with use_real_request_uri_unsafe and this field only supports proxying to real request.
Basically the issue is that two different concerns real_request and unsafe_uri are cobbed together in one field.
What your use case requires is just unsafe_uri along with a regex field.
Or at least regex_uri should internally have the unsafe field.
I will create a fix for this.

@Sn0rt
Copy link
Contributor

Sn0rt commented Jul 6, 2023

/assign @Sn0rt pls take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
3 participants