From ef0f6cdee42c3445efe5d70c9c3b399dc2e186fb Mon Sep 17 00:00:00 2001 From: spacewander Date: Mon, 20 Feb 2023 16:05:19 +0800 Subject: [PATCH] fix(proxy-rewrite): escape args part if it's not from user conf Signed-off-by: spacewander --- apisix/core/utils.lua | 8 ++- apisix/plugins/proxy-rewrite.lua | 23 ++++--- t/plugin/proxy-rewrite3.t | 111 +++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 10 deletions(-) diff --git a/apisix/core/utils.lua b/apisix/core/utils.lua index f72996b78d99..01c8b34c8503 100644 --- a/apisix/core/utils.lua +++ b/apisix/core/utils.lua @@ -293,6 +293,7 @@ do local _ctx local n_resolved local pat = [[(?= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed + + + +=== TEST 22: hit with CRLF +--- request +GET /hello%3f0z=700%26a=c%20HTTP/1.1%0D%0AHost:google.com%0d%0a%0d%0a +--- http_config + server { + listen 8125; + location / { + content_by_lua_block { + ngx.say(ngx.var.host) + ngx.say(ngx.var.request_uri) + } + } + } +--- response_body +test.xxxx.com +/hello%3F0z=700&a=c%20HTTP/1.1%0D%0AHost:google.com%0D%0A%0D%0A + + + +=== TEST 23: set route with uri +--- 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": { + "uri": "/$uri/remain", + "host": "test.xxxx.com" + } + }, + "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 24: hit with CRLF +--- request +GET /hello%3f0z=700%26a=c%20HTTP/1.1%0D%0AHost:google.com%0d%0a%0d%0a +--- http_config + server { + listen 8125; + location / { + content_by_lua_block { + ngx.say(ngx.var.host) + ngx.say(ngx.var.request_uri) + } + } + } +--- response_body +test.xxxx.com +//hello%253F0z=700&a=c%20HTTP/1.1%0D%0AHost:google.com%0D%0A%0D%0A/remain