Skip to content

v1.11.0

Choose a tag to compare

@tirthpatell tirthpatell released this 23 Aug 18:32
· 8 commits to main since this release
41fa548

What's changed

Security hardening for URL construction, ID validation, and configuration handling.

This release compiles against existing code — nothing exported was removed or changed — but several runtime behaviors are stricter. Read "Breaking behavior" before upgrading.

Breaking behavior

1. BaseURL must use HTTPS

Plaintext http:// is now rejected at NewClient and on every request, unless the host is a loopback address (localhost, 127.0.0.1, ::1, *.localhost).

If you point the client at a proxy or gateway that terminates TLS elsewhere, set the new opt-out:

config := &threads.Config{
    BaseURL:              "http://gateway.internal:8080",
    AllowInsecureBaseURL: true, // access tokens are sent in cleartext
}

Note that net.ParseIP does not accept shorthand forms such as 127.1; those need the opt-out too.

2. NewClient and UpdateConfig no longer mutate the Config you pass

Both now apply defaults to a private copy. Code that read defaults back off its own struct after construction will see zero values:

cfg := &threads.Config{ClientID: "...", ClientSecret: "...", RedirectURI: "..."}
client, _ := threads.NewClient(cfg)
len(cfg.Scopes)   // was 5, now 0
cfg.HTTPTimeout   // was 30s, now 0

Use client.GetConfig() to read the effective configuration.

3. Mutating Config.RetryConfig after construction no longer affects the client

The client copies it. To change retry behavior, set it before NewClient, or call UpdateConfig.

4. Responses larger than 16 MiB are rejected

Configurable via Config.MaxResponseBodySize. Oversized responses return ErrResponseTooLarge and are not retried.

5. Resource IDs are validated before use in URL paths

PostID, UserID, ContainerID, and LocationID must consist of unreserved URL characters (A-Z a-z 0-9 - . _ ~). IDs containing /, ?, #, or similar are rejected with a ValidationError rather than being sent.

Security fixes

  • Path injection via IDs. Request URLs are now built with net/url instead of string concatenation, so an ID cannot inject //host, ?, or # and redirect a request or append parameters. IDs taken from token claims are validated too.
  • Credentials could be sent to the wrong host. Configuration and its transport settings are now stored as one immutable unit, so a concurrent UpdateConfig can no longer pair an old ClientSecret with a newly configured BaseURL. Previously this was reproducible under load.
  • Unbounded response buffering. A hostile or malfunctioning server could previously force the client to buffer an arbitrarily large response body into memory.
  • Credential leakage into logs. HTTP header values are no longer logged at all (names only) — RequestOptions.Headers accepts arbitrary headers, so no name-based filter is safe. URL userinfo is redacted, alongside the existing query-parameter redaction.

Fixes

  • Configuration reads are race-free: UpdateConfig no longer races with in-flight requests.
  • Request logging uses the configuration snapshot the request started with, so a mid-flight UpdateConfig cannot split one request's log lines across two loggers.
  • GetMe and carousel publish recovery now return AuthenticationError for an invalid token-derived user ID, matching sibling methods.
  • Fixed a double slash in request paths when BaseURL carried a trailing slash.

Added

  • Config.AllowInsecureBaseURL — opt out of the HTTPS requirement.
  • Config.MaxResponseBodySize — response body limit (default 16 MiB).
  • ErrResponseTooLarge — sentinel for errors.Is.

Internal

  • Integration tests delete published posts via t.Cleanup, so cleanup survives failures and early returns. The suite now runs after merge to main, weekly, and on demand rather than on every PR.

Full changelog: v1.10.0...v1.11.0