--- title: "Go net/http path handling with CONNECT" section: "Network Services" sectionSlug: "network-services-pentesting" sourcePath: "src/network-services-pentesting/pentesting-web/golang.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/network-services-pentesting/pentesting-web/golang.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0" --- # Go `net/http` path handling with `CONNECT` ## Historical `ServeMux` behavior In the referenced version of Go's `net/http` package, `ServeMux.Handler` canonicalizes the URL path for ordinary HTTP methods. It calls `cleanPath` and redirects the client when the clean result differs from the supplied path. This removes `.` and `..` segments and repeated slashes.[[1]](#references) For example, ordinary requests for `/flag/`, `/../flag`, or `/flag/.` can be redirected to the canonical `/flag` path, depending on the registered handler and trailing-slash behavior.[[1]](#references) The historical implementation treats `CONNECT` specially and does not run its path through this canonicalization branch. Consequently, middleware or routing logic that assumes every request has already received a cleaned path may interpret a `CONNECT` target differently from another method. Whether this produces a security bypass depends on the Go version, handler registrations, proxies, and authorization checks in the application.[[1]](#references) Use curl's `--path-as-is` option to prevent curl from normalizing the target before sending it.[[2]](#references) For example: ```bash curl --path-as-is -X CONNECT http://gofs.web.jctf.pro/../flag ``` Compare the response with requests using a normal method and a canonical path. A different response is only an indicator; confirm that the discrepancy crosses an authorization boundary before reporting it. ## References - [1] [Go source - historical `ServeMux.Handler` handling of `CONNECT`](https://github.com/golang/go/blob/9bb97ea047890e900dae04202a231685492c4b18/src/net/http/server.go#L2354-L2364) - [2] [curl manual - `--path-as-is`](https://curl.se/docs/manpage.html#--path-as-is)