Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: guard Notion downloads and REST auth redirects (#21545)

buua436256edaf959b9
diff --git a/internal/syncer/connector/notion.go b/internal/syncer/connector/notion.go
index d2de01c3da..c3f709296b 100644
--- a/internal/syncer/connector/notion.go
+++ b/internal/syncer/connector/notion.go
@@ -35,6 +35,7 @@ import (
const (
defaultNotionBatchSize = 32
defaultNotionFileMaxBytes = 100 * 1024 * 1024
+ notionRequestTimeout = 60 * time.Second
notionAPIBaseURL = "https://api.notion.com/v1"
notionVersion = "2022-06-28"
)
@@ -70,7 +71,7 @@ func NewNotionConnector(config map[string]any) (*NotionConnector, error) {
batchSize: batchSize,
fileMaxBytes: fileMaxBytes,
recursiveLookup: true,
- httpClient: &http.Client{Timeout: 60 * time.Second},
+ httpClient: &http.Client{Timeout: notionRequestTimeout},
indexedPages: map[string]bool{},
pagePathCache: map[string]string{},
}, nil
@@ -545,13 +546,18 @@ func (c *NotionConnector) file(ctx context.Context, rawURL string) ([]byte, erro
if c.downloadFile != nil {
return c.downloadFile(ctx, rawURL)
}
- request, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil)
- if err != nil {
- return nil, err
+ timeout := notionRequestTimeout
+ if c.httpClient != nil && c.httpClient.Timeout > 0 {
+ timeout = c.httpClient.Timeout
}
- response, err := c.httpClient.Do(request)
+ response, err := connectorRequest(ctx, connectorRequestOptions{
+ Method: http.MethodGet,
+ RawURL: rawURL,
+ Timeout: timeout,
+ Base: c.httpClient,
+ })
if err != nil {
- return nil, err
+ return nil, connectorUnsafeErr(err)
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
diff --git a/internal/syncer/connector/notion_test.go b/internal/syncer/connector/notion_test.go
index cd802c8904..9558b19c5e 100644
--- a/internal/syncer/connector/notion_test.go
+++ b/internal/syncer/connector/notion_test.go
@@ -202,6 +202,7 @@ func TestNotionConnectorFileRejectsOversizedBody(t *testing.T) {
}))
defer server.Close()
+ withConnectorLoopbackTestHook(t)
connector := newTestNotionConnector(t)
connector.fileMaxBytes = 4
_, err := connector.file(t.Context(), server.URL)
@@ -210,6 +211,43 @@ func TestNotionConnectorFileRejectsOversizedBody(t *testing.T) {
}
}
+func TestNotionConnectorFileRejectsPrivateURL(t *testing.T) {
+ previous := connectorAllowLoopbackForTest
+ connectorAllowLoopbackForTest = false
+ t.Cleanup(func() { connectorAllowLoopbackForTest = previous })
+
+ requests := make(chan struct{}, 1)
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ requests <- struct{}{}
+ _, _ = io.WriteString(w, "internal response")
+ }))
+ defer server.Close()
+
+ connector := newTestNotionConnector(t)
+ _, err := connector.file(t.Context(), server.URL)
+ if err == nil {
+ t.Fatal("file accepted a private URL, want SSRF rejection")
+ }
+ select {
+ case <-requests:
+ t.Fatal("private URL received a request, want none")
+ default:
+ }
+}
+
+func TestNotionConnectorFileRejectsPrivateRedirect(t *testing.T) {
+ withConnectorLoopbackTestHook(t)
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, "http://169.254.169.254/latest/meta-data/", http.StatusFound)
+ }))
+ defer server.Close()
+
+ connector := newTestNotionConnector(t)
+ if _, err := connector.file(t.Context(), server.URL); err == nil {
+ t.Fatal("file followed a redirect to a private metadata address, want SSRF rejection")
+ }
+}
+
func TestNotionConnectorOpenPruneReturnsPageAndAttachmentIDs(t *testing.T) {
connector := newTestNotionConnector(t)
connector.rootPageID = "page-1"
diff --git a/internal/syncer/connector/rest_api.go b/internal/syncer/connector/rest_api.go
index ba13175bcc..c9c5c84c5e 100644
--- a/internal/syncer/connector/rest_api.go
+++ b/internal/syncer/connector/rest_api.go
@@ -635,15 +635,20 @@ func (c *RestAPIConnector) fetchPageOnce(ctx context.Context, params map[string]
}
}
currentAuth := c.basicAuth
- previousNetloc := connectorNetloc(currentURL)
+ previousOrigin := connectorOrigin(currentURL)
+ sensitiveHeaders := make([]string, 0, len(c.authHeaders))
+ for name := range c.authHeaders {
+ sensitiveHeaders = append(sensitiveHeaders, name)
+ }
resp, err := connectorRequest(ctx, connectorRequestOptions{
- Method: currentMethod,
- RawURL: currentURL,
- Body: bodyBytes,
- Headers: currentHeaders,
- Timeout: restAPIRequestTimeout,
- MaxRedirects: restAPIMaxRedirects,
+ Method: currentMethod,
+ RawURL: currentURL,
+ Body: bodyBytes,
+ Headers: currentHeaders,
+ SensitiveHeaders: sensitiveHeaders,
+ Timeout: restAPIRequestTimeout,
+ MaxRedirects: restAPIMaxRedirects,
Prepare: func(req *http.Request, hop connectorRequestHop) error {
if hop.Method == http.MethodPost && req.Header.Get("Content-Type") == "" {
req.Header.Set("Content-Type", "application/json")
@@ -680,11 +685,11 @@ func (c *RestAPIConnector) fetchPageOnce(ctx context.Context, params map[string]
return wait, true
},
NextHop: func(nextURL string, status int, hop connectorRequestHop) connectorRequestHop {
- nextNetloc := connectorNetloc(nextURL)
- if nextNetloc != "" && nextNetloc != previousNetloc {
+ nextOrigin := connectorOrigin(nextURL)
+ if nextOrigin != "" && nextOrigin != previousOrigin {
currentAuth = nil
}
- previousNetloc = nextNetloc
+ previousOrigin = nextOrigin
if status == http.StatusMovedPermanently || status == http.StatusFound || status == http.StatusSeeOther {
hop.Method = http.MethodGet
hop.Body = nil
diff --git a/internal/syncer/connector/rest_api_test.go b/internal/syncer/connector/rest_api_test.go
index 0218db06c5..9f2ce4fade 100644
--- a/internal/syncer/connector/rest_api_test.go
+++ b/internal/syncer/connector/rest_api_test.go
@@ -650,6 +650,35 @@ func TestRestAPIFetchPageRedirectStripsAuth(t *testing.T) {
}
}
+func TestRestAPIFetchPageRedirectStripsCustomAuthHeader(t *testing.T) {
+ withRestAPITestHooks(t)
+ var gotHeader string
+ final := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ gotHeader = r.Header.Get("X-Tenant-Credential")
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(`{}`))
+ }))
+ defer final.Close()
+ redirector := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, final.URL, http.StatusFound)
+ }))
+ defer redirector.Close()
+
+ c := mustRestAPIConnector(t, map[string]any{
+ "url": redirector.URL,
+ "content_fields": "title",
+ "auth_type": "api_key_header",
+ "auth_config": map[string]any{"header_name": "X-Tenant-Credential"},
+ "credentials": map[string]any{"api_key": "tenant-secret"},
+ })
+ if _, err := c.fetchPage(t.Context(), nil); err != nil {
+ t.Fatalf("fetchPage: %v", err)
+ }
+ if gotHeader != "" {
+ t.Fatalf("cross-origin custom auth header=%q want stripped", gotHeader)
+ }
+}
+
func TestRestAPISyncSessionPagination(t *testing.T) {
withRestAPITestHooks(t)
var requests atomic.Int32
diff --git a/internal/syncer/connector/ssrf.go b/internal/syncer/connector/ssrf.go
index 38e64a8fec..1c79ddeb7b 100644
--- a/internal/syncer/connector/ssrf.go
+++ b/internal/syncer/connector/ssrf.go
@@ -233,12 +233,16 @@ type connectorRequestHop struct {
// connectorRequestOptions configures connectorRequest. Zero values use safe
// defaults: Validate falls back to assertConnectorURLSafe and MaxRedirects to 10.
type connectorRequestOptions struct {
- Method string
- RawURL string
- Body []byte
- Headers map[string]string
- Timeout time.Duration
- MaxRedirects int
+ Method string
+ RawURL string
+ Body []byte
+ Headers map[string]string
+ // SensitiveHeaders are additional credential header names to remove when
+ // a redirect crosses to a different origin. This covers auth schemes with
+ // tenant-configured header names.
+ SensitiveHeaders []string
+ Timeout time.Duration
+ MaxRedirects int
// Base, when non-nil, provides the starting transport so custom TLS/CA
// settings are preserved; otherwise a default pinned transport is used.
Base *http.Client
@@ -291,7 +295,7 @@ func (e *connectorUnsafeURLError) Unwrap() error { return e.Err }
// - The hop is sent through a transport that dials exactly the validated IP,
// so a DNS change after validation cannot rebind the connection.
// - Sensitive headers (Authorization etc.) are dropped when a redirect
-// crosses to a different netloc, mirroring http.Client's default.
+// crosses to a different origin, mirroring http.Client's default.
// - 301/302/303 downgrade the next hop to GET with an empty body.
//
// Connector-specific behavior is expressed through the Prepare, CheckRedirect,
@@ -304,7 +308,7 @@ func connectorRequest(ctx context.Context, opts connectorRequestOptions) (*http.
opts.MaxRedirects = 10
}
hop := connectorRequestHop{Method: opts.Method, URL: opts.RawURL, Body: opts.Body, Headers: opts.Headers}
- previousNetloc := connectorNetloc(hop.URL)
+ previousOrigin := connectorOrigin(hop.URL)
var via []*http.Request
for redirects := 0; ; redirects++ {
hostname, pinIP, err := opts.Validate(hop.URL)
@@ -332,7 +336,24 @@ func connectorRequest(ctx context.Context, opts connectorRequestOptions) (*http.
return nil, err
}
}
- transport := newConnectorPinnedTransport(opts.Base, hostname, pinIP, opts.Timeout)
+ proxyURL, err := connectorProxyURL(opts.Base, req)
+ if err != nil {
+ return nil, fmt.Errorf("resolve connector proxy: %w", err)
+ }
+ originalURL := *req.URL
+ if req.Host == "" {
+ req.Host = req.URL.Host
+ }
+ requestURI := req.URL.RequestURI()
+ pinnedHost := connectorPinnedHost(req.URL, pinIP)
+ req.URL.Host = pinnedHost
+ if proxyURL != nil && req.URL.Scheme == "http" && (proxyURL.Scheme == "http" || proxyURL.Scheme == "https") {
+ // net/http normally builds an HTTP proxy's absolute request target
+ // from Request.Host. Use an opaque absolute URI so the proxy connects
+ // to the validated IP while the Host header retains the origin name.
+ req.URL.Opaque = "//" + pinnedHost + requestURI
+ }
+ transport := newConnectorPinnedTransport(opts.Base, hostname, pinIP, opts.Timeout, proxyURL)
client := &http.Client{
Transport: transport,
Timeout: opts.Timeout,
@@ -346,6 +367,7 @@ func connectorRequest(ctx context.Context, opts connectorRequestOptions) (*http.
for attempt := 1; ; attempt++ {
resp, err = client.Do(req)
if err != nil {
+ req.URL = &originalURL
transport.CloseIdleConnections()
return nil, err
}
@@ -363,6 +385,10 @@ func connectorRequest(ctx context.Context, opts connectorRequestOptions) (*http.
}
break
}
+ req.URL = &originalURL
+ if resp.Request != nil {
+ resp.Request.URL = &originalURL
+ }
if !connectorIsRedirect(resp.StatusCode) {
resp.Body = &connectorCloseIdleBody{body: resp.Body, transport: transport}
return resp, nil
@@ -380,9 +406,9 @@ func connectorRequest(ctx context.Context, opts connectorRequestOptions) (*http.
if err != nil {
return nil, err
}
- nextNetloc := connectorNetloc(nextURL)
- if nextNetloc != "" && nextNetloc != previousNetloc {
- hop.Headers = connectorStripAuthHeaders(hop.Headers)
+ nextOrigin := connectorOrigin(nextURL)
+ if nextOrigin != "" && nextOrigin != previousOrigin {
+ hop.Headers = connectorStripAuthHeaders(hop.Headers, opts.SensitiveHeaders...)
// 307/308 preserve the request method and body; never forward a
// request body (which may carry credentials, e.g. a Seafile or
// Moodle token exchange) to a different origin.
@@ -390,7 +416,7 @@ func connectorRequest(ctx context.Context, opts connectorRequestOptions) (*http.
return nil, fmt.Errorf("redirect to a different origin is not allowed for a request with a body")
}
}
- previousNetloc = nextNetloc
+ previousOrigin = nextOrigin
if resp.StatusCode == http.StatusMovedPermanently || resp.StatusCode == http.StatusFound || resp.StatusCode == http.StatusSeeOther {
hop.Method = http.MethodGet
hop.Body = nil
@@ -404,25 +430,57 @@ func connectorRequest(ctx context.Context, opts connectorRequestOptions) (*http.
}
}
-// newConnectorPinnedTransport builds a transport that dials exactly pinIP for
-// every connection, so the hop is connected to the address validated by the
-// SSRF guard regardless of later DNS changes. When base provides an
-// *http.Transport (custom TLS/CA), it is cloned and reused; otherwise a default
-// transport is used. Environment proxies are deliberately ignored: HTTP_PROXY /
-// HTTPS_PROXY would route the connection through a proxy host instead of pinIP.
-func newConnectorPinnedTransport(base *http.Client, hostname string, pinIP net.IP, timeout time.Duration) *http.Transport {
+// connectorProxyURL resolves the configured proxy before the request target is pinned.
+func connectorProxyURL(base *http.Client, req *http.Request) (*url.URL, error) {
+ proxy := http.ProxyFromEnvironment
+ if base != nil && base.Transport != nil {
+ transport, ok := base.Transport.(*http.Transport)
+ if !ok {
+ return nil, nil
+ }
+ proxy = transport.Proxy
+ }
+ if proxy == nil {
+ return nil, nil
+ }
+ return proxy(req)
+}
+
+// connectorPinnedHost returns the validated IP combined with the origin port.
+func connectorPinnedHost(reqURL *url.URL, pinIP net.IP) string {
+ port := reqURL.Port()
+ if port == "" {
+ if reqURL.Scheme == "https" {
+ port = "443"
+ } else {
+ port = "80"
+ }
+ }
+ return net.JoinHostPort(pinIP.String(), port)
+}
+
+// newConnectorPinnedTransport builds a transport that pins direct connections
+// to pinIP or dials the selected proxy while keeping pinIP as the proxy target.
+// When base provides an *http.Transport (custom TLS/CA), it is cloned and
+// reused; otherwise a default transport is used.
+func newConnectorPinnedTransport(base *http.Client, hostname string, pinIP net.IP, timeout time.Duration, proxyURL *url.URL) *http.Transport {
dialer := &net.Dialer{Timeout: timeout, KeepAlive: 30 * time.Second}
dial := func(ctx context.Context, network, addr string) (net.Conn, error) {
+ if proxyURL != nil {
+ return dialer.DialContext(ctx, network, addr)
+ }
_, port, err := net.SplitHostPort(addr)
if err != nil {
port = "443"
}
return dialer.DialContext(ctx, network, net.JoinHostPort(pinIP.String(), port))
}
+ proxy := func(*http.Request) (*url.URL, error) { return proxyURL, nil }
if base != nil {
if t, ok := base.Transport.(*http.Transport); ok {
clone := t.Clone()
clone.DialContext = dial
+ clone.Proxy = proxy
if clone.TLSClientConfig == nil {
clone.TLSClientConfig = &tls.Config{ServerName: hostname, MinVersion: tls.VersionTLS12}
} else {
@@ -435,7 +493,7 @@ func newConnectorPinnedTransport(base *http.Client, hostname string, pinIP net.I
}
}
return &http.Transport{
- Proxy: nil,
+ Proxy: proxy,
DialContext: dial,
TLSHandshakeTimeout: timeout,
ResponseHeaderTimeout: timeout,
@@ -472,10 +530,17 @@ var connectorAuthSensitiveHeaders = map[string]struct{}{
"private-token": {}, // GitLab credential header
}
-func connectorStripAuthHeaders(headers map[string]string) map[string]string {
+func connectorStripAuthHeaders(headers map[string]string, additional ...string) map[string]string {
out := make(map[string]string, len(headers))
+ sensitiveHeaders := make(map[string]struct{}, len(connectorAuthSensitiveHeaders)+len(additional))
+ for name := range connectorAuthSensitiveHeaders {
+ sensitiveHeaders[name] = struct{}{}
+ }
+ for _, name := range additional {
+ sensitiveHeaders[strings.ToLower(strings.TrimSpace(name))] = struct{}{}
+ }
for k, v := range headers {
- if _, sensitive := connectorAuthSensitiveHeaders[strings.ToLower(k)]; sensitive {
+ if _, sensitive := sensitiveHeaders[strings.ToLower(k)]; sensitive {
continue
}
out[k] = v
@@ -483,12 +548,27 @@ func connectorStripAuthHeaders(headers map[string]string) map[string]string {
return out
}
-func connectorNetloc(rawURL string) string {
+func connectorOrigin(rawURL string) string {
parsed, err := url.Parse(rawURL)
- if err != nil {
+ if err != nil || parsed.Scheme == "" || parsed.Hostname() == "" {
return ""
}
- return parsed.Host
+
+ scheme := strings.ToLower(parsed.Scheme)
+ host := strings.TrimSuffix(strings.ToLower(parsed.Hostname()), ".")
+ port := parsed.Port()
+ if port == "" {
+ switch scheme {
+ case "http":
+ port = "80"
+ case "https":
+ port = "443"
+ default:
+ return ""
+ }
+ }
+
+ return scheme + "://" + net.JoinHostPort(host, port)
}
func connectorResolveURL(base, location string) (string, error) {
diff --git a/internal/syncer/connector/ssrf_test.go b/internal/syncer/connector/ssrf_test.go
index 739ac05f48..3c95d05aab 100644
--- a/internal/syncer/connector/ssrf_test.go
+++ b/internal/syncer/connector/ssrf_test.go
@@ -18,10 +18,13 @@ package connector
import (
"context"
+ "crypto/tls"
"io"
"net"
"net/http"
"net/http/httptest"
+ "net/http/httptrace"
+ "net/url"
"strconv"
"strings"
"sync/atomic"
@@ -192,6 +195,160 @@ func TestConnectorRequestPinsRedirectHopAgainstDNSRebinding(t *testing.T) {
}
}
+func TestConnectorRequestUsesProxyWithPinnedHTTPTarget(t *testing.T) {
+ withConnectorLoopbackTestHook(t)
+
+ type observedRequest struct {
+ urlHost string
+ }
+ observed := make(chan observedRequest, 1)
+ proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ observed <- observedRequest{urlHost: r.URL.Host}
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer proxy.Close()
+ proxyURL, err := url.Parse(proxy.URL)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ const rawURL = "http://docs.example.test:8123/file"
+ base := &http.Client{Transport: &http.Transport{Proxy: func(req *http.Request) (*url.URL, error) {
+ if req.URL.Host != "docs.example.test:8123" {
+ t.Errorf("proxy selection saw rewritten host %q", req.URL.Host)
+ }
+ return proxyURL, nil
+ }}}
+ hostHeader := make(chan string, 1)
+ trace := &httptrace.ClientTrace{WroteHeaderField: func(key string, values []string) {
+ if strings.EqualFold(key, "Host") && len(values) > 0 {
+ hostHeader <- values[0]
+ }
+ }}
+ ctx := httptrace.WithClientTrace(context.Background(), trace)
+ resp, err := connectorRequest(ctx, connectorRequestOptions{
+ Method: http.MethodGet,
+ RawURL: rawURL,
+ Timeout: webdavRequestTimeout,
+ Base: base,
+ Validate: func(string) (string, net.IP, error) {
+ return "docs.example.test", net.ParseIP("203.0.113.9"), nil
+ },
+ })
+ if err != nil {
+ t.Fatalf("connectorRequest: %v", err)
+ }
+ resp.Body.Close()
+
+ got := <-observed
+ if got.urlHost != "203.0.113.9:8123" {
+ t.Errorf("proxy target URL host = %q, want pinned IP", got.urlHost)
+ }
+ select {
+ case got := <-hostHeader:
+ if got != "docs.example.test:8123" {
+ t.Errorf("HTTP Host header = %q, want original host", got)
+ }
+ case <-time.After(time.Second):
+ t.Fatal("HTTP request did not write the origin Host header")
+ }
+ if resp.Request.URL.String() != rawURL {
+ t.Errorf("response request URL = %q, want original URL %q", resp.Request.URL, rawURL)
+ }
+}
+
+func TestConnectorRequestUsesHTTPSConnectToPinnedIPAndPreservesOrigin(t *testing.T) {
+ withConnectorLoopbackTestHook(t)
+
+ type observedRequest struct {
+ host string
+ serverName string
+ }
+ observed := make(chan observedRequest, 1)
+ target := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ serverName := ""
+ if r.TLS != nil {
+ serverName = r.TLS.ServerName
+ }
+ observed <- observedRequest{host: r.Host, serverName: serverName}
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer target.Close()
+ targetURL, err := url.Parse(target.URL)
+ if err != nil {
+ t.Fatal(err)
+ }
+ targetPort := targetURL.Port()
+
+ connectTarget := make(chan string, 1)
+ proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodConnect {
+ http.Error(w, "CONNECT required", http.StatusMethodNotAllowed)
+ return
+ }
+ connectTarget <- r.Host
+ clientConn, rw, err := w.(http.Hijacker).Hijack()
+ if err != nil {
+ t.Errorf("hijack proxy connection: %v", err)
+ return
+ }
+ defer clientConn.Close()
+ targetConn, err := net.Dial("tcp", r.Host)
+ if err != nil {
+ t.Errorf("dial CONNECT target %q: %v", r.Host, err)
+ return
+ }
+ defer targetConn.Close()
+ if _, err := io.WriteString(rw, "HTTP/1.1 200 Connection Established\r\n\r\n"); err != nil {
+ t.Errorf("write CONNECT response: %v", err)
+ return
+ }
+ if err := rw.Flush(); err != nil {
+ t.Errorf("flush CONNECT response: %v", err)
+ return
+ }
+ go func() {
+ _, _ = io.Copy(targetConn, rw)
+ }()
+ _, _ = io.Copy(clientConn, targetConn)
+ }))
+ defer proxy.Close()
+ proxyURL, err := url.Parse(proxy.URL)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ rawURL := "https://docs.example.test:" + targetPort + "/file"
+ base := &http.Client{Transport: &http.Transport{
+ Proxy: func(req *http.Request) (*url.URL, error) { return proxyURL, nil },
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // Test certificate only.
+ }}
+ resp, err := connectorRequest(context.Background(), connectorRequestOptions{
+ Method: http.MethodGet,
+ RawURL: rawURL,
+ Timeout: webdavRequestTimeout,
+ Base: base,
+ Validate: func(string) (string, net.IP, error) {
+ return "docs.example.test", net.ParseIP("127.0.0.1"), nil
+ },
+ })
+ if err != nil {
+ t.Fatalf("connectorRequest: %v", err)
+ }
+ resp.Body.Close()
+
+ if got := <-connectTarget; got != "127.0.0.1:"+targetPort {
+ t.Errorf("CONNECT target = %q, want validated IP and port", got)
+ }
+ got := <-observed
+ if got.host != "docs.example.test:"+targetPort {
+ t.Errorf("TLS request Host = %q, want original host", got.host)
+ }
+ if got.serverName != "docs.example.test" {
+ t.Errorf("TLS SNI = %q, want original hostname", got.serverName)
+ }
+}
+
func TestConnectorRequestRejectsCrossOriginBodyRedirect(t *testing.T) {
withConnectorLoopbackTestHook(t)
diff --git a/internal/syncer/connector/zotero.go b/internal/syncer/connector/zotero.go
index d5dd6dcb27..2053c5ca64 100644
--- a/internal/syncer/connector/zotero.go
+++ b/internal/syncer/connector/zotero.go
@@ -460,7 +460,7 @@ func (c *ZoteroConnector) getPinnedURL(ctx context.Context, rawURL string, autho
client = http.DefaultClient
}
httpClient := *client
- httpClient.Transport = newConnectorPinnedTransport(client, hostname, pinIP, zoteroRequestTimeout)
+ httpClient.Transport = newConnectorPinnedTransport(client, hostname, pinIP, zoteroRequestTimeout, nil)
httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}