mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 15:59:57 +00:00
TUN-1977: Validate OriginConfig has valid URL, and use scheme to determine if a HTTPOriginService is expecting HTTP or Unix
This commit is contained in:
@@ -23,8 +23,8 @@ func IsLBProbeRequest(req *http.Request) bool {
|
||||
return strings.HasPrefix(req.UserAgent(), lbProbeUserAgentPrefix)
|
||||
}
|
||||
|
||||
func createRequest(stream *h2mux.MuxedStream, url string) (*http.Request, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, url, h2mux.MuxedStreamReader{MuxedStream: stream})
|
||||
func createRequest(stream *h2mux.MuxedStream, url *url.URL) (*http.Request, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, url.String(), h2mux.MuxedStreamReader{MuxedStream: stream})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unexpected error from http.NewRequest")
|
||||
}
|
||||
|
@@ -138,7 +138,7 @@ func (s *StreamHandler) serveRequest(stream *h2mux.MuxedStream) error {
|
||||
return fmt.Errorf("cannot map tunnel hostname %s to origin", tunnelHostname)
|
||||
}
|
||||
|
||||
req, err := createRequest(stream, originService.OriginAddr())
|
||||
req, err := createRequest(stream, originService.URL())
|
||||
if err != nil {
|
||||
s.writeErrorStatus(stream, statusBadRequest)
|
||||
return errors.Wrap(err, "cannot create request")
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -46,16 +45,12 @@ func TestServeRequest(t *testing.T) {
|
||||
|
||||
message := []byte("Hello cloudflared")
|
||||
httpServer := httptest.NewServer(&mockHTTPHandler{message})
|
||||
url, err := url.Parse(httpServer.URL)
|
||||
assert.NoError(t, err)
|
||||
|
||||
reverseProxyConfigs := []*pogs.ReverseProxyConfig{
|
||||
{
|
||||
TunnelHostname: testTunnelHostname,
|
||||
Origin: &pogs.HTTPOriginConfig{
|
||||
URL: &pogs.HTTPURL{
|
||||
URL: url,
|
||||
},
|
||||
URLString: httpServer.URL,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -103,9 +98,7 @@ func TestServeBadRequest(t *testing.T) {
|
||||
{
|
||||
TunnelHostname: testTunnelHostname,
|
||||
Origin: &pogs.HTTPOriginConfig{
|
||||
URL: &pogs.HTTPURL{
|
||||
URL: &url.URL{},
|
||||
},
|
||||
URLString: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user