Skip to content

Commit cd70ced

Browse files
authored
Merge pull request #18 from bbrowning/http2-url-reconstruct
Fix nil req.URL crash for gRPC/HTTP2 requests in MITM mode
2 parents a2eef3c + f6a1522 commit cd70ced

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

internal/proxy/proxy.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net"
99
"net/http"
10+
"net/url"
1011
"os"
1112
"strconv"
1213
"strings"
@@ -396,12 +397,28 @@ func New(cfg Config) *http.Server {
396397
return nil, nil
397398
}
398399
if req.URL == nil {
399-
log.Printf("DEFENSIVE_CHECK: DoFunc received request with nil URL from client=%s", clientIP(ctx))
400-
return req, goproxy.NewResponse(req,
401-
goproxy.ContentTypeText,
402-
http.StatusBadRequest,
403-
"Malformed request",
404-
)
400+
// goproxy doesn't properly reconstruct req.URL from HTTP/2 pseudo-headers in MITM mode.
401+
// This commonly happens with gRPC clients (e.g., dolt's eventsapi).
402+
// Log diagnostics and attempt reconstruction from available fields.
403+
log.Printf("DEFENSIVE_CHECK: DoFunc req.URL is nil - Method=%q Host=%q RequestURI=%q Proto=%q from client=%s",
404+
req.Method, req.Host, req.RequestURI, req.Proto, clientIP(ctx))
405+
406+
// Try to reconstruct URL from Host and RequestURI (populated from HTTP/2 pseudo-headers)
407+
if req.Host != "" && req.RequestURI != "" {
408+
req.URL = &url.URL{
409+
Scheme: "https", // MITM tunnel is always HTTPS
410+
Host: req.Host,
411+
Path: req.RequestURI,
412+
}
413+
log.Printf("DEFENSIVE_CHECK: Reconstructed URL from Host+RequestURI: %s", req.URL.String())
414+
} else {
415+
log.Printf("DEFENSIVE_CHECK: Cannot reconstruct URL - missing Host or RequestURI")
416+
return req, goproxy.NewResponse(req,
417+
goproxy.ContentTypeText,
418+
http.StatusBadRequest,
419+
"Malformed request",
420+
)
421+
}
405422
}
406423

407424
// Source IP filtering for plain HTTP proxy requests.

0 commit comments

Comments
 (0)