Skip to content

Commit 52849af

Browse files
committed
move proxy req sanitizing past auth to give rejector chance for reverse proxying
1 parent cfb59c3 commit 52849af

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

handler/handler.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"net"
1212
"net/http"
1313
"strconv"
14-
"strings"
1514
"sync"
1615

1716
"github.com/SenseUnit/dumbproxy/auth"
@@ -209,13 +208,6 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
209208
return
210209
}
211210

212-
method := strings.ToUpper(req.Method)
213-
if (req.URL.Host == "" || req.URL.Scheme == "" && method != "CONNECT") && req.ProtoMajor < 2 ||
214-
req.Host == "" && req.ProtoMajor == 2 {
215-
http.Error(wr, auth.BAD_REQ_MSG, http.StatusBadRequest)
216-
return
217-
}
218-
219211
ctx := req.Context()
220212
username, ok := s.auth.Validate(ctx, wr, req)
221213
localAddr := getLocalAddr(req.Context())
@@ -225,6 +217,12 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
225217
return
226218
}
227219

220+
if (req.URL.Host == "" || req.URL.Scheme == "" && req.Method != "CONNECT") && req.ProtoMajor < 2 ||
221+
req.Host == "" && req.ProtoMajor == 2 {
222+
http.Error(wr, auth.BAD_REQ_MSG, http.StatusBadRequest)
223+
return
224+
}
225+
228226
var ipHints *string
229227
if s.userIPHints {
230228
hintValues := req.Header.Values(HintsHeaderName)
@@ -237,7 +235,7 @@ func (s *ProxyHandler) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
237235
ctx = ddto.FilterParamsToContext(ctx, req, username)
238236
req = req.WithContext(ctx)
239237
delHopHeaders(req.Header)
240-
switch method {
238+
switch req.Method {
241239
case "CONNECT":
242240
s.HandleTunnel(wr, req, username)
243241
case "GETRANDOM":

0 commit comments

Comments
 (0)