Skip to content

fix(coderd): harden Azure identity certificate fetch#25274

Merged
jdomeracki-coder merged 1 commit into
mainfrom
harden-azure-cert-fetch
May 13, 2026
Merged

fix(coderd): harden Azure identity certificate fetch#25274
jdomeracki-coder merged 1 commit into
mainfrom
harden-azure-cert-fetch

Conversation

@jdomeracki-coder
Copy link
Copy Markdown
Contributor

Re-lands the SSRF hardening for Azure identity certificate fetching that was reverted in #25273 due to CI failures (lint, fmt).

Security improvements:

  • Restrict cert fetches to a host+port allowlist (Microsoft and DigiCert on 80/443).
  • Route requests through a dedicated http.Client that resolves the host once and dials the validated IP directly, preventing DNS rebinding.
  • Reject loopback, private (RFC 1918 / IPv6 ULA), link-local, multicast, unspecified, CGNAT, benchmarking, and IPv4-mapped IPv6 addresses.
  • Cap the certificate response body at 1 MiB.
  • Log the underlying error via slog and return a generic detail to the caller to prevent information disclosure.

CI fixes over original commit (fb3aef1):

  • bodyclose lint: use http.NewRequestWithContext + Do() with deferred resp.Body.Close() guard in TestCertFetchClientRejectsLoopback.
  • fmt: remove extra alignment spaces on IPv6 CIDR comments in init().
  • fmt: remove stray blank line between cdr.dev/slog and github.com/coder imports.

Note

This PR was authored by Coder Agents.

Re-land the SSRF hardening for Azure identity certificate fetching
that was reverted in #25273 due to CI failures. This commit includes
the original security improvements plus fixes for the three CI issues.

Security hardening:
- Restrict cert fetches to a host+port allowlist (Microsoft and
  DigiCert on 80/443).
- Route requests through a dedicated http.Client that resolves
  the host once and dials the validated IP directly.
- Reject loopback, private (RFC 1918 / IPv6 ULA), link-local,
  multicast, unspecified, CGNAT, benchmarking, and IPv4-mapped
  IPv6 addresses.
- Cap the certificate response body at 1 MiB.
- Log the underlying error via slog and return a generic detail
  to the caller.
- Add unit tests for the URL allowlist, IP classification, and
  dialer.

CI fixes over original commit (fb3aef1):
- Fix bodyclose lint: use http.NewRequestWithContext + Do() with
  deferred resp.Body.Close() guard in TestCertFetchClientRejectsLoopback.
- Fix fmt: remove extra alignment spaces on IPv6 CIDR comments.
- Fix fmt: remove stray blank line between slog and coder imports.
@jdomeracki-coder jdomeracki-coder changed the title fix(coderd/azureidentity): harden Azure identity certificate fetch fix(coderd): harden Azure identity certificate fetch May 13, 2026
@jdomeracki-coder jdomeracki-coder marked this pull request as ready for review May 13, 2026 10:42
@jdomeracki-coder jdomeracki-coder merged commit 57b11d4 into main May 13, 2026
36 of 37 checks passed
@jdomeracki-coder jdomeracki-coder deleted the harden-azure-cert-fetch branch May 13, 2026 10:51
@github-actions github-actions Bot locked and limited conversation to collaborators May 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants