mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-04 06:53:36 +00:00
rewrite: preserve non-canonical path encoding after uri replace (#7907)
Some checks failed
Tests / test (./cmd/caddy/caddy, ~1.26.0, macos-14, 0, 1.26, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.26.0, ubuntu-latest, 0, 1.26, linux) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.26.0, windows-latest, True, 1.26, windows) (push) Has been cancelled
Tests / test (s390x on IBM Z) (push) Has been cancelled
Tests / goreleaser-check (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, aix) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, darwin) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, dragonfly) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, freebsd) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, illumos) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, linux) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, netbsd) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, openbsd) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, solaris) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, windows) (push) Has been cancelled
Lint / lint (push) Has been cancelled
Lint / lint-1 (push) Has been cancelled
Lint / lint-2 (push) Has been cancelled
Lint / govulncheck (push) Has been cancelled
Lint / dependency-review (push) Has been cancelled
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Some checks failed
Tests / test (./cmd/caddy/caddy, ~1.26.0, macos-14, 0, 1.26, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy, ~1.26.0, ubuntu-latest, 0, 1.26, linux) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.26.0, windows-latest, True, 1.26, windows) (push) Has been cancelled
Tests / test (s390x on IBM Z) (push) Has been cancelled
Tests / goreleaser-check (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, aix) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, darwin) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, dragonfly) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, freebsd) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, illumos) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, linux) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, netbsd) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, openbsd) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, solaris) (push) Has been cancelled
Cross-Build / build (~1.26.0, 1.26, windows) (push) Has been cancelled
Lint / lint (push) Has been cancelled
Lint / lint-1 (push) Has been cancelled
Lint / lint-2 (push) Has been cancelled
Lint / govulncheck (push) Has been cancelled
Lint / dependency-review (push) Has been cancelled
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
changePath cleared RawPath whenever it equalled url.Path, which discarded a valid non-canonical percent-encoding produced by a replacement. This compare `RawPath` against the default escaping of Path instead.
This commit is contained in:
parent
c5b66cf8ea
commit
c96bca1269
2 changed files with 24 additions and 2 deletions
|
|
@ -513,12 +513,21 @@ func changePath(req *http.Request, newVal func(pathOrRawPath string) string) {
|
|||
} else {
|
||||
req.URL.Path = newVal(req.URL.Path)
|
||||
}
|
||||
// RawPath is only set if it's different from the normalized Path (std lib)
|
||||
if req.URL.RawPath == req.URL.Path {
|
||||
// RawPath is only needed if it is a valid, non-canonical encoding of Path;
|
||||
// (see #6578). Mirror net/url.URL.setPath by comparing against the default
|
||||
// escaping of Path instead.
|
||||
if req.URL.RawPath == defaultEscapedPath(req.URL.Path) {
|
||||
req.URL.RawPath = ""
|
||||
}
|
||||
}
|
||||
|
||||
// defaultEscapedPath returns the canonical percent-encoding of p, matching
|
||||
// what net/url.URL.EscapedPath() produces when RawPath is empty. It mirrors
|
||||
// the comparison net/url.URL.setPath uses to decide whether RawPath is needed.
|
||||
func defaultEscapedPath(p string) string {
|
||||
return (&url.URL{Path: p}).EscapedPath()
|
||||
}
|
||||
|
||||
// queryOps describes the operations to perform on query keys: add, set, rename and delete.
|
||||
type queryOps struct {
|
||||
// Renames a query key from Key to Val, without affecting the value.
|
||||
|
|
|
|||
|
|
@ -351,6 +351,19 @@ func TestRewrite(t *testing.T) {
|
|||
input: newRequest(t, "GET", "/foo/findme%2Fbar"),
|
||||
expect: newRequest(t, "GET", "/foo/replaced%2Fbar"),
|
||||
},
|
||||
{
|
||||
rule: Rewrite{URISubstring: []substrReplacer{{Find: "%28", Replace: "("}}},
|
||||
input: newRequest(t, "GET", "/hello/%28%29"),
|
||||
expect: newRequest(t, "GET", "/hello/(%29"),
|
||||
},
|
||||
{
|
||||
rule: Rewrite{URISubstring: []substrReplacer{
|
||||
{Find: "%28", Replace: "("},
|
||||
{Find: "%29", Replace: ")"},
|
||||
}},
|
||||
input: newRequest(t, "GET", "/hello/%28%29"),
|
||||
expect: newRequest(t, "GET", "/hello/()"),
|
||||
},
|
||||
|
||||
{
|
||||
rule: Rewrite{PathRegexp: []*regexReplacer{{Find: "/{2,}", Replace: "/"}}},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue