-
Notifications
You must be signed in to change notification settings - Fork 11.4k
feat: TLS_INSECURE_SKIP_VERIFY env #2668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,9 @@ func InitHttpClient() { | |
| ForceAttemptHTTP2: true, | ||
| Proxy: http.ProxyFromEnvironment, // Support HTTP_PROXY, HTTPS_PROXY, NO_PROXY env vars | ||
| } | ||
| if common.TLSInsecureSkipVerify { | ||
| transport.TLSClientConfig = common.InsecureTLSConfig | ||
| } | ||
|
|
||
| if common.RelayTimeout == 0 { | ||
| httpClient = &http.Client{ | ||
|
|
@@ -102,13 +105,17 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) { | |
|
|
||
| switch parsedURL.Scheme { | ||
| case "http", "https": | ||
| transport := &http.Transport{ | ||
| MaxIdleConns: common.RelayMaxIdleConns, | ||
| MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost, | ||
| ForceAttemptHTTP2: true, | ||
| Proxy: http.ProxyURL(parsedURL), | ||
| } | ||
| if common.TLSInsecureSkipVerify { | ||
| transport.TLSClientConfig = common.InsecureTLSConfig | ||
| } | ||
| client := &http.Client{ | ||
| Transport: &http.Transport{ | ||
| MaxIdleConns: common.RelayMaxIdleConns, | ||
| MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost, | ||
| ForceAttemptHTTP2: true, | ||
| Proxy: http.ProxyURL(parsedURL), | ||
| }, | ||
| Transport: transport, | ||
| CheckRedirect: checkRedirect, | ||
| } | ||
| client.Timeout = time.Duration(common.RelayTimeout) * time.Second | ||
|
|
@@ -137,17 +144,19 @@ func NewProxyHttpClient(proxyURL string) (*http.Client, error) { | |
| return nil, err | ||
| } | ||
|
|
||
| client := &http.Client{ | ||
| Transport: &http.Transport{ | ||
| MaxIdleConns: common.RelayMaxIdleConns, | ||
| MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost, | ||
| ForceAttemptHTTP2: true, | ||
| DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { | ||
| return dialer.Dial(network, addr) | ||
| }, | ||
| transport := &http.Transport{ | ||
| MaxIdleConns: common.RelayMaxIdleConns, | ||
| MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost, | ||
| ForceAttemptHTTP2: true, | ||
| DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { | ||
| return dialer.Dial(network, addr) | ||
| }, | ||
| CheckRedirect: checkRedirect, | ||
| } | ||
| if common.TLSInsecureSkipVerify { | ||
| transport.TLSClientConfig = common.InsecureTLSConfig | ||
| } | ||
|
|
||
| client := &http.Client{Transport: transport, CheckRedirect: checkRedirect} | ||
|
Comment on lines
+147
to
+159
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: The ContextDialer interface (package golang.org/x/net/proxy) is: type ContextDialer interface { Purpose: a Dialer that supports context-aware dialing (cancellation/deadlines). It complements the older Dialer interface (Dial(network, addr string) (net.Conn, error)); custom Dialers should implement ContextDialer when possible. The package’s Dial function will use DialContext when the configured Dialer implements ContextDialer. Examples of implementers include net.Dialer and the package’s Direct dialer. [1][2] Sources:
🏁 Script executed: # Find the file to understand context around the code
fd -n "http_client.go" -t f
# Search for imports related to proxy in the file
rg "import|proxy" service/http_client.go -A 2 -B 2Repository: QuantumNous/new-api Length of output: 182 🌐 Web query:
💡 Result: Short answer: golang.org/x/net/proxy.SOCKS5 creates and returns an internal socks.Dialer (from golang.org/x/net/internal/socks). If you pass a non-nil forward Dialer and it implements proxy.ContextDialer, SOCKS5 sets the internal Dialer.ProxyDial to call forward.DialContext(ctx,...). If the forward Dialer does not implement ContextDialer, SOCKS5 sets ProxyDial to a wrapper that calls dialContext(ctx, forward, ...). The code is in proxy/socks5.go. [1][2] Sources:
🌐 Web query:
💡 Result: The SOCKS5 function (golang.org/x/net/proxy.SOCKS5) sets the internal socks.Dialer.ProxyDial to call the forward Dialer’s DialContext if the provided forward implements proxy.ContextDialer; otherwise it wraps the non-context Dialer with the package helper dialContext. See the source:
Sources: Use the dialer's ContextDialer interface if available to properly handle context cancellation and deadlines. The 🔧 Proposed fix transport := &http.Transport{
MaxIdleConns: common.RelayMaxIdleConns,
MaxIdleConnsPerHost: common.RelayMaxIdleConnsPerHost,
ForceAttemptHTTP2: true,
- DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
- return dialer.Dial(network, addr)
- },
+ }
+ if contextDialer, ok := dialer.(proxy.ContextDialer); ok {
+ transport.DialContext = contextDialer.DialContext
+ } else {
+ transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
+ return dialer.Dial(network, addr)
+ }
}
if common.TLSInsecureSkipVerify {
transport.TLSClientConfig = common.InsecureTLSConfig
}🤖 Prompt for AI Agents |
||
| client.Timeout = time.Duration(common.RelayTimeout) * time.Second | ||
| proxyClientLock.Lock() | ||
| proxyClients[proxyURL] = client | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 3240
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 984
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 1245
🏁 Script executed:
Repository: QuantumNous/new-api
Length of output: 825
Add a warning log when TLS insecure skip verification is enabled.
The code correctly applies insecure TLS configuration across all transport instances. However, there is currently no warning logged in
common/init.gowhenTLSInsecureSkipVerifyis enabled via the environment variable. Since TLS verification bypass is a significant security setting, operators should be explicitly notified. Add a warning log similar to the SESSION_SECRET warning pattern already in the codebase (lines 52-54 ofcommon/init.go).🤖 Prompt for AI Agents