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: Improve http.Client usage for security and performance #1910

Merged
merged 2 commits into from
Feb 18, 2025

Conversation

jentfoo
Copy link
Contributor

@jentfoo jentfoo commented Feb 6, 2025

Proposed Changes

This change switches us from maintaining a tls config which we then on-demand initialize an http.Client with to instead maintain and reuse an http.Client instance. This enables us to utilize the connection pooling which occurs within the http.Transport to reduce ssl handshakes and thus reduce latency.

In addition this change provides us a central place to configure out http.Client (httputil). Allowing us to easily set configuration options to reduce the security risks of using an unconfigured http.Client. Notably timeouts to reduce DoS risks, and control around following redirects to prevent blind SSRF's.

This PR 3/4 addresses #1891. After it's merged a small change will be made in the service to fully utilize the API being introduced in the SDK here.

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

@jentfoo jentfoo self-assigned this Feb 6, 2025
@jentfoo jentfoo force-pushed the jent/http.Client_handling branch from f8ee52c to da0f385 Compare February 6, 2025 22:52
This change switches us from maintaining a tls config which we then on-demand initialize an `http.Client` with to instead maintain and reuse an `http.Client` instance.
This enables us to utilize the connection pooling which occurs within the `http.Transport` to reduce ssl handshakes and thus reduce latency.

In addition this change provides us a central place to configure out `http.Client` (`httputil`). Allowing us to easily set configuration options to reduce the security risks of using an unconfigured `http.Client`. Notably timeouts to reduce DoS risks, and control around following redirects to prevent blind SSRF's.

This change will provide significant benefit without making API changes.  A future PR will update the service and also cleanup some of the API.
@jentfoo jentfoo force-pushed the jent/http.Client_handling branch from 06093c7 to c7026b8 Compare February 7, 2025 21:36
@jentfoo jentfoo marked this pull request as ready for review February 7, 2025 21:55
@jentfoo jentfoo requested review from a team as code owners February 7, 2025 21:55
@jentfoo jentfoo added this pull request to the merge queue Feb 18, 2025
Merged via the queue into main with commit e6a53a3 Feb 18, 2025
22 checks passed
@jentfoo jentfoo deleted the jent/http.Client_handling branch February 18, 2025 15:55
jentfoo added a commit that referenced this pull request Feb 18, 2025
This PR follows #1910 by updating `service` to utilize the new `httputil` helper for constructing a client which wont follow redirects, and has sensible timeouts.

The prior auth API was marked as deprecated. There is no remaining use within this repo, so it may be able to be removed.

Merging this should fully resolve #1891.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants