Skip to content

Commit

Permalink
Policy: Routing fix URL encoding.
Browse files Browse the repository at this point in the history
This commit fixes an issue when a special character uses some encoding.
The value to the upstream API if the routing policy was used, is also
encoded, so something like "/foo/test space" should land in APICast as:

`/foo/test%20space/`

And the path to the Upstream API should contain `test%20space`, but
because `ngx.req.set_uri` mark the URL to be encoded again, the URL that
will be received in the Upstream API will be `/test%2520space/`

This commit keeps the URL encoding correctly across all the flow.

Fix THREESCALE-5454

Signed-off-by: Eloy Coto <[email protected]>
  • Loading branch information
eloycoto committed Jun 30, 2020
1 parent edbc881 commit 674bdea
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed issues with HTTPS_PROXY and large bodies [THREESCALE-3863](https://issues.jboss.org/browse/THREESCALE-3863) [PR #1191](https://github.com/3scale/APIcast/pull/1191)
- Fixed issues with path routing and query args [THREESCALE-5149](https://issues.redhat.com/browse/THREESCALE-5149) [PR #1190](https://github.com/3scale/APIcast/pull/1190)
- Fixed issue with IPCheck policy when forwarder-for value contains port [THREESCALE-5258](https://issues.redhat.com/browse/THREESCALE-5258) [PR #1192](https://github.com/3scale/APIcast/pull/1192)
- Fixed issues with URL encode on routing policy [THREESCALE-5454](https://issues.redhat.com/browse/THREESCALE-5454) [PR #1208](https://github.com/3scale/APIcast/pull/1208)


### Added
Expand Down
3 changes: 1 addition & 2 deletions gateway/src/apicast/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ function _M:rewrite_request()
end

local uri = self.uri

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

if uri.query then
Expand Down
69 changes: 69 additions & 0 deletions t/apicast-policy-routing.t
Original file line number Diff line number Diff line change
Expand Up @@ -2125,3 +2125,72 @@ GET /?user_key=value
could not find upstream for service: 42
--- no_error_log
[error]


=== TEST 32: URL is not double encoded.
--- configuration
{
"services": [
{
"id": 42,
"backend_version": 1,
"backend_authentication_type": "service_token",
"backend_authentication_value": "token-value",
"proxy": {
"policy_chain": [
{
"name": "apicast.policy.routing",
"configuration": {
"rules": [
{
"url": "http://test:$TEST_NGINX_SERVER_PORT/second/",
"owner_id": 4,
"condition": {
"operations": [
{
"match": "liquid",
"liquid_value": "test",
"op": "==",
"value": "test"
}
]
}
}
]
}
},
{
"name": "apicast.policy.apicast"
}
],
"proxy_rules": [
{
"pattern": "/foo",
"http_method": "GET",
"metric_system_name": "test",
"delta": 1
}
]
}
}
]
}
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.say("OK")
}
}
--- upstream
location / {
content_by_lua_block {
ngx.say(ngx.var.uri);
}
}
--- request
GET /foo/test%20space?user_key=foo
--- response_body
/second/foo/test space
--- error_code: 200
--- no_error_log
[error]

0 comments on commit 674bdea

Please sign in to comment.