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(router) do not match another API with a longer URI #2664

Merged
merged 1 commit into from
Jun 30, 2017

Conversation

thibaultcha
Copy link
Member

@thibaultcha thibaultcha commented Jun 30, 2017

When matching URIs, we iterate over a list of APIs, and not a list of
URIs (for various, performance reasons, although a refactor of the
router is scheduled with some performance improvements later on).
This list of APIs is sorted per URI length. But an API can have more
than one URI. As such, the router can potentially evaluate an API with a
very long URI, and a much shorter one that matches the request URI,
instead of a following API which would be an exact match for that API.

To fix this, we sort our deserialized list of URIs to iterate on in the
select method, and if we do have a match, we conserve the URI that was
matched, to check if it belongs to the right API at API match time.

Fix #2662

p0pr0ck5
p0pr0ck5 previously approved these changes Jun 30, 2017
Copy link
Contributor

@p0pr0ck5 p0pr0ck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -605,6 +605,25 @@ describe("Router", function()
assert.same(use_case[#use_case], api_t.api)
end)
end)

it("does not falsly match another API which has a longer [uri]", function()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"falsely" (alternatively, "incorrectly")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, brackets around uri?

@p0pr0ck5 p0pr0ck5 added pr/ready This PR is considered ready and can be merged at anytime (given it received no subsequent changes) and removed pr/status/please review labels Jun 30, 2017
@thibaultcha
Copy link
Member Author

thibaultcha commented Jun 30, 2017

The brackets are in all the test titles for this suite ever since it was written.

When matching URIs, we iterate over a list of APIs, and not a list of
URIs (for various, performance reasons, although a refactor of the
router is scheduled with some performance improvements later on).
This list of APIs is sorted per URI length. But an API can have more
than one URI. As such, the router can potentially evaluate an API with a
very long URI, and a much shorter one that matches the request URI,
instead of a following API which would be an exact match for that API.

To fix this, we sort our deserialized list of URIs to iterate on in the
select method, and if we do have a match, we conserve the URI that was
matched, to check if it belongs to the right API at API match time.

Fix #2662
@thibaultcha thibaultcha force-pushed the fix/router-uris-length-between-apis branch from f47c855 to 4dbf014 Compare June 30, 2017 23:32
@thibaultcha thibaultcha merged commit 37578b1 into master Jun 30, 2017
@thibaultcha thibaultcha deleted the fix/router-uris-length-between-apis branch June 30, 2017 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready This PR is considered ready and can be merged at anytime (given it received no subsequent changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kong doesn't match the longest uri when multiple uris are defined on an api
2 participants