Skip to content

Commit

Permalink
Merge pull request #14 from istresearch/dev/PE-154
Browse files Browse the repository at this point in the history
Add safety to prevent singleton http defaultclient issues with mtls keypairs
  • Loading branch information
jeremyist authored Jan 9, 2024
2 parents 4d0ec37 + e9dbeb0 commit 1536072
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions services/webhooks/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,19 @@ func (s *service) Call(session flows.Session, request *http.Request) (*flows.Web
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)

httpClient = http.DefaultClient
httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{cert},
// Because defaultclient can be used across routines and be reused multiple times, we need to
// explicitly create one just for mTLS.
// Todo: Do we want to cache the clients based on the keypair used on a given connection?
httpClient = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{cert},
},
},
CheckRedirect: s.httpClient.CheckRedirect,
Jar: s.httpClient.Jar,
Timeout: s.httpClient.Timeout,
}
}

Expand Down

0 comments on commit 1536072

Please sign in to comment.