-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Problem with path matching and URI manipulation when involving double slashes #4743
Comments
As for problem (2), I have tested the behavior of Nginx with the following config:
And here are the corresponding error logs (since no upstream is defined):
|
Instead of cleaning path implicitly within path matchers, how about enhancing the rewrite handler to let users do it explicitly if needed? For example, as a possible solution, we can add an attribute type Rewrite struct {
...
// Strips the given prefix from the beginning of the URI path.
StripPathPrefix string `json:"strip_path_prefix,omitempty"`
// Strips the given suffix from the end of the URI path.
StripPathSuffix string `json:"strip_path_suffix,omitempty"`
// Performs substring replacements on the URI.
URISubstring []substrReplacer `json:"uri_substring,omitempty"`
// Performs regular expression replacements on the URI path.
PathRegexp []*regexReplacer `json:"path_regexp,omitempty"`
+ // Normalize the URI path by decoding the text encoded in the “%XX” form,
+ // resolving references to relative path components “.” and “..”, and
+ // merging multiple slashes into a single slash.
+ NormalizePath bool `json:"normalize_path,omitempty"`
logger *zap.Logger
} Take the problem (2) for example, the corresponding Caddyfile might look like this:
As for the original problem with
|
Thanks Russell -- as discussed in Slack, I wonder if a good solution for this would be an exported function in the Edit: actually, maybe |
@RussellLuo I've been thinking on this long and hard for a while. Track #4948 where I am hopefully resolving this. |
@RussellLuo This is now fixed in #4948. If the prefix (or suffix, or substring) pattern in the rewrite config contains |
Problem
1. Path matcher containing double slashes won't match any request
Caddyfile:
Neither of the following requests will match
handle_path
:2. Normal
handle_path
can match but can't strip prefix from requests containing double slashesCaddyfile:
As shown below, the second request containing double slashes will be forwarded to the upstream without being stripped:
Cause
I think the above problems are explainable, since "path cleaning" was introduced after the fix #4407:
Possible solution
If the problems mentioned above are not the normal behaviors as expected by Caddy, I think maybe we should also introduce "path cleaning" while doing path matching (besides cleaning the source path, we should also clean the target path) and URI manipulation.
The text was updated successfully, but these errors were encountered: