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

Ensure Prefix matching requires trailing slash #817

Merged
merged 2 commits into from
Jul 11, 2023

Conversation

sjberman
Copy link
Contributor

@sjberman sjberman commented Jul 5, 2023

Problem: When using a prefix path match, a path such as /foobar would match for the prefix /foo, which should not happen. Prefixes need a "/" delimiter between path segments.

Solution: In order to allow just the prefix without a trailing slash, as well as more path segments using a slash delimiter, we now create two location blocks. One uses exact matching for the configured prefix path, and the other uses prefix matching with a trailing slash.

Testing: Conformance test now passes

Closes #796

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

@sjberman sjberman requested a review from a team as a code owner July 5, 2023 21:11
@github-actions github-actions bot added the bug Something isn't working label Jul 5, 2023
Copy link
Member

@ciarams87 ciarams87 left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers_test.go Outdated Show resolved Hide resolved
internal/nginx/config/servers_test.go Outdated Show resolved Hide resolved
@sjberman
Copy link
Contributor Author

Now that all conformance tests pass, I can remove continue-on-error if we want. That way we can actually get visibility into the tests from the PR page.

Copy link
Contributor

@pleshakov pleshakov left a comment

Choose a reason for hiding this comment

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

a few comments/suggestions based on the new code. looks good otherwise

Now that all conformance tests pass, I can remove continue-on-error if we want. That way we can actually get visibility into the tests from the PR page.

👍 ,
for tracking/auditing purposes, could we merge it in a separate commit? also, it will help to simplify reverting it in case we need to

internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers.go Outdated Show resolved Hide resolved
internal/nginx/config/servers_test.go Outdated Show resolved Hide resolved
internal/nginx/config/servers_test.go Outdated Show resolved Hide resolved
Problem: When using a prefix path match, a path such as /foobar would match for the prefix /foo, which should not happen. Prefixes need a "/" delimiter between path segments.

Solution: In order to allow just the prefix without a trailing slash, as well as more path segments using a slash delimiter, we now create two location blocks. One uses exact matching for the configured prefix path, and the other uses prefix matching with a trailing slash.
Copy link
Contributor

@pleshakov pleshakov left a comment

Choose a reason for hiding this comment

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

👍 🚀

@sjberman sjberman merged commit 9bcfef0 into nginxinc:main Jul 11, 2023
@sjberman sjberman deleted the bug/prefix-matching branch July 11, 2023 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Incorrect prefix path matching
3 participants