Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -396,12 +397,28 @@ func New(cfg Config) *http.Server {
return nil, nil
}
if req.URL == nil {
log.Printf("DEFENSIVE_CHECK: DoFunc received request with nil URL from client=%s", clientIP(ctx))
return req, goproxy.NewResponse(req,
goproxy.ContentTypeText,
http.StatusBadRequest,
"Malformed request",
)
// goproxy doesn't properly reconstruct req.URL from HTTP/2 pseudo-headers in MITM mode.
// This commonly happens with gRPC clients (e.g., dolt's eventsapi).
// Log diagnostics and attempt reconstruction from available fields.
log.Printf("DEFENSIVE_CHECK: DoFunc req.URL is nil - Method=%q Host=%q RequestURI=%q Proto=%q from client=%s",
req.Method, req.Host, req.RequestURI, req.Proto, clientIP(ctx))

// Try to reconstruct URL from Host and RequestURI (populated from HTTP/2 pseudo-headers)
if req.Host != "" && req.RequestURI != "" {
req.URL = &url.URL{
Scheme: "https", // MITM tunnel is always HTTPS
Host: req.Host,
Path: req.RequestURI,
}
log.Printf("DEFENSIVE_CHECK: Reconstructed URL from Host+RequestURI: %s", req.URL.String())
} else {
log.Printf("DEFENSIVE_CHECK: Cannot reconstruct URL - missing Host or RequestURI")
return req, goproxy.NewResponse(req,
goproxy.ContentTypeText,
http.StatusBadRequest,
"Malformed request",
)
}
}

// Source IP filtering for plain HTTP proxy requests.
Expand Down