This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b71d8fb7 fix(): support regex_uri with unsafe_uri in proxy-rewrite 
(#9813)
2b71d8fb7 is described below

commit 2b71d8fb7e55b6c40207ce818f9a29d13ca4c063
Author: Ashish Tiwari <[email protected]>
AuthorDate: Fri Jul 14 12:21:24 2023 +0530

    fix(): support regex_uri with unsafe_uri in proxy-rewrite (#9813)
---
 apisix/plugins/proxy-rewrite.lua |  7 ++++-
 t/plugin/proxy-rewrite3.t        | 57 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/apisix/plugins/proxy-rewrite.lua b/apisix/plugins/proxy-rewrite.lua
index 0766463fb..087686edf 100644
--- a/apisix/plugins/proxy-rewrite.lua
+++ b/apisix/plugins/proxy-rewrite.lua
@@ -279,9 +279,12 @@ function _M.rewrite(conf, ctx)
     local separator_escaped = false
     if conf.use_real_request_uri_unsafe then
         upstream_uri = ctx.var.real_request_uri
-    elseif conf.uri ~= nil then
+    end
+
+    if conf.uri ~= nil then
         separator_escaped = true
         upstream_uri = core.utils.resolve_var(conf.uri, ctx.var, 
escape_separator)
+
     elseif conf.regex_uri ~= nil then
         if not str_find(upstream_uri, "?") then
             separator_escaped = true
@@ -345,6 +348,8 @@ function _M.rewrite(conf, ctx)
         else
             ctx.var.upstream_uri = upstream_uri
         end
+    else
+        ctx.var.upstream_uri = upstream_uri
     end
 
     if conf.headers then
diff --git a/t/plugin/proxy-rewrite3.t b/t/plugin/proxy-rewrite3.t
index 98f27de74..55afe14cc 100644
--- a/t/plugin/proxy-rewrite3.t
+++ b/t/plugin/proxy-rewrite3.t
@@ -942,3 +942,60 @@ GET /test/plugin/proxy/rewrite/world HTTP/1.1
     }
 --- response_body
 /world/plugin_proxy_rewrite
+
+
+
+=== TEST 40: use regex uri with unsafe allowed
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                      "plugins": {
+                          "proxy-rewrite": {
+                              "regex_uri": [
+                                  "/hello/(.+)",
+                                  "/hello?unsafe_variable=$1"
+                              ],
+                              "use_real_request_uri_unsafe": true
+                           }
+                        },
+                      "upstream": {
+                          "nodes": {
+                              "127.0.0.1:8125": 1
+                          },
+                          "type": "roundrobin"
+                      },
+                      "uri": "/hello/*"
+                 }]]
+                 )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+
+
+
+=== TEST 41: hit
+--- request
+GET /hello/%ED%85%8C%EC%8A%A4%ED%8A%B8 HTTP/1.1
+--- http_config
+    server {
+        listen 8125;
+        location / {
+            content_by_lua_block {
+                ngx.say(ngx.var.request_uri)
+            }
+        }
+    }
+--- response_body
+/hello?unsafe_variable=%ED%85%8C%EC%8A%A4%ED%8A%B8

Reply via email to