Skip to content
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

fix appsec/tls issues by cloning http transport #3213

Merged
merged 4 commits into from
Sep 6, 2024
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
13 changes: 10 additions & 3 deletions pkg/apiclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
transport, baseURL := createTransport(config.URL)
if transport != nil {
t.Transport = transport
} else {
// can be httpmock.MockTransport
if ht, ok := http.DefaultTransport.(*http.Transport); ok {
t.Transport = ht.Clone()
}
}

t.URL = baseURL
Expand All @@ -96,8 +101,8 @@
tlsconfig.Certificates = []tls.Certificate{*Cert}
}

if ht, ok := http.DefaultTransport.(*http.Transport); ok {
ht.TLSClientConfig = &tlsconfig
if t.Transport != nil {
t.Transport.(*http.Transport).TLSClientConfig = &tlsconfig
}

c := &ApiClient{client: t.Client(), BaseURL: baseURL, UserAgent: config.UserAgent, URLPrefix: config.VersionPrefix, PapiURL: config.PapiURL}
Expand All @@ -124,6 +129,7 @@
client.Transport = transport
} else {
if ht, ok := http.DefaultTransport.(*http.Transport); ok {
ht = ht.Clone()
tlsconfig := tls.Config{InsecureSkipVerify: InsecureSkipVerify}
tlsconfig.RootCAs = CaCertPool

Expand Down Expand Up @@ -165,7 +171,8 @@
tlsconfig.Certificates = []tls.Certificate{*Cert}
}

http.DefaultTransport.(*http.Transport).TLSClientConfig = &tlsconfig
client.Transport = http.DefaultTransport.(*http.Transport).Clone()
client.Transport.(*http.Transport).TLSClientConfig = &tlsconfig

Check warning on line 175 in pkg/apiclient/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiclient/client.go#L174-L175

Added lines #L174 - L175 were not covered by tests
}
} else if client.Transport == nil && transport != nil {
client.Transport = transport
Expand Down