Skip to content

Commit

Permalink
fix: ensure HTTP requests use proxy env vars
Browse files Browse the repository at this point in the history
Updated all instances of `http.Transport` to include the `Proxy` field set to `http.ProxyFromEnvironment`. This ensures that the application respects proxy configuration defined by the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables.

### Changes:
- Modified `http.Transport` initialization across the codebase to use:
  ```go
  Proxy: http.ProxyFromEnvironment
  ```
- Ensured TLS configurations remain intact by preserving `TLSClientConfig`.

### Why:
- Previously, HTTP requests bypassed proxy settings due to missing configuration in the transport layer.
- This fix enables compatibility with proxied environments, aligning with standard Go behavior.

### Impact:
- All HTTP and HTTPS traffic now adheres to proxy settings.
- Domains listed in `NO_PROXY` bypass the proxy as expected.

### Verification:
- Tested with proxy environment variables set (`HTTP_PROXY`, `HTTPS_PROXY`).
- Verified requests route through the proxy and `NO_PROXY` works as intended.
  • Loading branch information
ncsc-ie-devs authored Nov 24, 2024
1 parent fe4f01d commit 2be0dcc
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/csaf_aggregator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (c *config) httpClient(p *provider) util.Client {

hClient.Transport = &http.Transport{
TLSClientConfig: &tlsConfig,
Proxy: http.ProxyFromEnvironment,
}

client := util.Client(&hClient)
Expand Down
2 changes: 2 additions & 0 deletions cmd/csaf_checker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func (p *processor) fullClient() util.Client {

hClient.Transport = &http.Transport{
TLSClientConfig: &tlsConfig,
Proxy: http.ProxyFromEnvironment,
}

client := util.Client(&hClient)
Expand Down Expand Up @@ -460,6 +461,7 @@ func (p *processor) basicClient() *http.Client {
if p.cfg.Insecure {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Proxy: http.ProxyFromEnvironment,
}
return &http.Client{Transport: tr}
}
Expand Down
1 change: 1 addition & 0 deletions cmd/csaf_downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (d *downloader) httpClient() util.Client {

hClient.Transport = &http.Transport{
TLSClientConfig: &tlsConfig,
Proxy: http.ProxyFromEnvironment,
}

client := util.Client(&hClient)
Expand Down
1 change: 1 addition & 0 deletions cmd/csaf_downloader/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (f *forwarder) httpClient() util.Client {

hClient.Transport = &http.Transport{
TLSClientConfig: &tlsConfig,
Proxy: http.ProxyFromEnvironment,
}

client := util.Client(&hClient)
Expand Down
1 change: 1 addition & 0 deletions cmd/csaf_uploader/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (p *processor) httpClient() *http.Client {

client.Transport = &http.Transport{
TLSClientConfig: &tlsConfig,
Proxy: http.ProxyFromEnvironment,
}

return &client
Expand Down

0 comments on commit 2be0dcc

Please sign in to comment.