Skip to content

Commit c1b343b

Browse files
committed
server: better hostname validation
This change is harder to test, but we could test that function directly idk.
1 parent ca00a1c commit c1b343b

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎fakestorage/server.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"net/http/httptest"
2121
"net/http/httputil"
2222
"net/textproto"
23-
"regexp"
2423
"strings"
2524
"sync"
2625

@@ -271,11 +270,11 @@ func (s *Server) buildMuxer() {
271270

272271
// publicHostMatcher matches incoming requests against the currently specified server publicHost.
273272
func (s *Server) publicHostMatcher(r *http.Request, rm *mux.RouteMatch) bool {
274-
if strings.Contains(s.publicHost, ":") {
273+
if strings.Contains(s.publicHost, ":") || !strings.Contains(r.Host, ":") {
275274
return r.Host == s.publicHost
276275
}
277-
matched, _ := regexp.MatchString("^"+regexp.QuoteMeta(s.publicHost), r.Host)
278-
return matched
276+
idx := strings.IndexByte(r.Host, ':')
277+
return r.Host[:idx] == s.publicHost
279278
}
280279

281280
// Stop stops the server, closing all connections.

0 commit comments

Comments
 (0)