checkRequestPath refuses an API path that would route somewhere other than the segments it was built from (BUG-3645). Every builder escapes its dynamic segments with url.PathEscape, so a workspace or ref carrying '/', '?' or '#' stays inside its segment. This is the backstop for a builder that does
(path string)
| 21 | // url.Values.Encode or url.QueryEscape) and which is what a '?' smuggled into |
| 22 | // a segment leaves behind. |
| 23 | func checkRequestPath(path string) error { |
| 24 | if strings.ContainsRune(path, '#') { |
| 25 | return fmt.Errorf("refusing request: path %q contains '#'", path) |
| 26 | } |
| 27 | p, query, hasQuery := strings.Cut(path, "?") |
| 28 | if hasQuery && strings.ContainsRune(query, '/') { |
| 29 | return fmt.Errorf("refusing request: path %q has a '/' after its '?'", path) |
| 30 | } |
| 31 | if p == "" { |
| 32 | return nil |
| 33 | } |
| 34 | for _, seg := range strings.Split(strings.TrimPrefix(p, "/"), "/") { |
| 35 | switch seg { |
| 36 | case "": |
| 37 | return fmt.Errorf("refusing request: path %q has an empty segment", path) |
| 38 | case ".", "..": |
| 39 | return fmt.Errorf("refusing request: path %q has a %q segment", path, seg) |
| 40 | } |
| 41 | } |
| 42 | return nil |
| 43 | } |
no outgoing calls