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

fix: support regex_uri with unsafe_uri in proxy-rewrite #9813

Merged
merged 6 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apisix/plugins/proxy-rewrite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ 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
monkeyDluffy6017 marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -345,6 +346,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
Expand Down
57 changes: 57 additions & 0 deletions t/plugin/proxy-rewrite3.t
Original file line number Diff line number Diff line change
Expand Up @@ -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