Skip to content

Commit

Permalink
Routing: Fix encoding.
Browse files Browse the repository at this point in the history
When using encoding, some characters got encoded a few times, so the
upstream request was not correct.

Is impossible to get it 100% perfect, because some chars (`?/#`) are
hard to get it right when using ngx.var.uri, but we need to use
ngx.var.uri.

After discussing it with support/product, this is the best way to handle
it.

Reported by [email protected]
Fix: https://issues.redhat.com/browse/THREESCALE-5117

Signed-off-by: Eloy Coto <[email protected]>
  • Loading branch information
eloycoto committed Aug 16, 2021
1 parent 4bc0663 commit 16aea8b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gateway/src/apicast/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function _M:rewrite_request()

local uri = self.uri
if uri.path then
ngx.req.set_uri(ngx.unescape_uri(prefix_path(uri.path)))
ngx.req.set_uri(prefix_path(uri.path))
end

if uri.query then
Expand Down
56 changes: 56 additions & 0 deletions t/apicast-policy-routing.t
Original file line number Diff line number Diff line change
Expand Up @@ -2416,3 +2416,59 @@ operations is an empty array instead of nil
[200, 200]
--- no_error_log
[error]


=== TEST 35: Path encoding
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"policy_chain": [
{
"name": "apicast.policy.routing",
"configuration": {
"rules": [
{
"url": "http://test:$TEST_NGINX_SERVER_PORT/",
"replace_path": "{{uri | remove_first: '/test'}}",
"condition": {
"operations": [
{
"match": "path",
"op": "matches",
"value": "^(/test/.*|/test/?)"
}
]
}
},

{
"url": "http://test:$TEST_NGINX_SERVER_PORT/",
"condition": {
"operations": []
}
}
]
}
}
]
}
}
]
}
--- upstream
location ~ / {
content_by_lua_block {
ngx.say(ngx.var.request_uri)
}
}
--- request eval
["GET /test/foo+foo", "GET /test/foo%2Bfoo", "GET /test/foo%2Ffoo", "GET /test/foo%20foo" ]
--- response_body eval
["/foo+foo\n", "/foo+foo\n", "/foo/foo\n", "/foo%20foo\n"]
--- error_code eval
[200, 200, 200, 200]
--- no_error_log
[error]

0 comments on commit 16aea8b

Please sign in to comment.