Repository navigation
Remove dot segments from absolute redirect locations - #2648
Merged
yhirose merged 2 commits intoOct 26, 2026
Merged
Conversation
Owner
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolve_relative_locationremoves.and..segments when it merges a relative-pathLocationwith the request path. ALocationthat starts with/, or an absolute URI, is passed toparse_urlunchanged, though, and its path is requested as is. So a redirect to/dir/../target?x=1requests/dir/../target?x=1, and so doeshttp://host:port/dir/./../target. A server that doesn't normalize the path itself (cpp-httplib's own router doesn't) answers 404. RFC 3986 section 5.2.2 appliesremove_dot_segmentsto the target path of every reference that has a path, not only relative ones (examples/./g->http://a/gand/../g->http://a/gin section 5.4.2). Browsers and curl request/targethere.The change moves the existing dot-segment loop into
detail::remove_dot_segmentswithout changing its behaviour.resolve_relative_locationnow calls it, andClientImpl::redirectapplies it to the parsed path when the path starts with/. Relative locations are handled as before, so theresolve_relative_locationexpectations stay the same.New tests:
RedirectTest.RemoveDotSegments: the RFC 3986 section 5.2.4 examples, plus/./g,/../g,/..,/a/b/..and a path without dot segments.RedirectTest.AbsoluteLocationIsNormalized: redirects to/dir/../target?x=1and tohttp://localhost:<port>/dir/./../targetmust reach/target. Against the current header, both get 404, because the server receives the unnormalized path.make testbuilds without warnings. The test binary passes 1051 tests with--gtest_filter=-*Online*.git clang-formatreports no changes.