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 for stripping paths containing magic characters. #431

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion kong/resolver/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ function _M.execute(conf)
if by_path and api.strip_path then
-- Replace `/path` with `path`, and then prefix with a `/`
-- Or replace `/path/foo` with `/foo`, and then do not prefix with `/`.
request_uri = string.gsub(request_uri, api.path, "")
local escaped_path = api.path:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", function(c) return "%" .. c end)
request_uri = string.gsub(request_uri, escaped_path, "")
if string.sub(request_uri, 0, 1) ~= "/" then
request_uri = "/"..request_uri
end
Expand Down
8 changes: 8 additions & 0 deletions spec/integration/proxy/api_resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe("Resolver", function()
{name = "tests host resolver 2", public_dns = "mockbin-auth.com", target_url = "http://mockbin.com"},
{name = "tests path resolver", target_url = "http://mockbin.com", path = "/status/"},
{name = "tests stripped path resolver", target_url = "http://mockbin.com", path = "/mockbin/", strip_path = true},
{name = "tests stripped path resolver with magic", target_url = "http://mockbin.com", path = "/mockbin-with-magic/", strip_path = true},
{name = "tests deep path resolver", target_url = "http://mockbin.com", path = "/deep/path/", strip_path = true},
{name = "tests wildcard subdomain", target_url = "http://mockbin.com/status/200", public_dns = "*.wildcard.com"},
{name = "tests wildcard subdomain 2", target_url = "http://mockbin.com/status/201", public_dns = "wildcard.*"}
Expand Down Expand Up @@ -162,6 +163,13 @@ describe("Resolver", function()
assert.equal("http://mockbin.com/request", body.url)
end)

it("should proxy and strip the path if `strip_path` is true if path has magic characters", function()
local response, status = http_client.get(spec_helper.PROXY_URL.."/mockbin-with-magic/request")
assert.equal(200, status)
local body = cjson.decode(response)
assert.equal("http://mockbin.com/request", body.url)
end)

it("should proxy when the path has a deep level", function()
local _, status = http_client.get(spec_helper.PROXY_URL.."/deep/path/status/200")
assert.equal(200, status)
Expand Down