Skip to content

Fix #9803: pin socket connections to validated DNS addresses - #9913

Open
boredskull wants to merge 1 commit into
SimpleMachines:release-3.0from
boredskull:fix-9803-socket-dns
Open

boredskull wants to merge 1 commit into
SimpleMachines:release-3.0from
boredskull:fix-9803-socket-dns

Conversation

@boredskull

Copy link
Copy Markdown

Description

Addresses #9803 by improving how SMF 3.0 establishes socket connections to external services when DNS responses change between lookups.

This is an alternative implementation to #9861, building upon the same general approach while addressing additional edge cases and improving connection reliability without weakening the existing SSRF protections.

Improvements over #9861

  • Multiple IP address support: Rather than attempting only the first resolved IP address, this implementation attempts additional validated addresses if the initial connection fails.
  • IPv4 and IPv6 support: Handles both address formats without requiring additional methods in the IP class.
  • Empty DNS response handling: Gracefully handles cases where no IP addresses are returned, avoiding undefined array offsets.
  • Shared connection timeout: Distributes the available connection time across candidate addresses, preventing multiple failed attempts from unnecessarily delaying the request.
  • No unpinned fallback: Removes the fallback to hostname-based fsockopen(), which could reintroduce the original DNS mismatch.
  • Explicit TLS verification: Retains the original hostname for SNI and certificate verification, with peer verification enabled and self-signed certificates disallowed.
  • Connection cleanup: Closes superseded socket connections before establishing new ones.
  • Error handling: Clears previous connection errors following a successful connection.
  • Reduced code footprint: Modifies only SocketFetcher.php, without requiring changes to IP.php or Url.php.

Security considerations

The existing isFetchSafe() validation remains in place, and connections are established using addresses returned by SMF's validated DNS cache.

The existing peer IP address and port verification checks are retained.

This approach does not disable SSRF protection, bypass certificate verification or require an additional administrator setting.

Compatibility

  • SMF 3.0
  • HTTP and HTTPS
  • IPv4 and IPv6
  • Existing keep-alive behaviour
  • Existing redirect validation

Testing

Initial isolated regression testing covered:

  • Multiple IP address connection attempts.
  • Empty DNS responses.
  • IPv4 and IPv6 endpoint formatting.
  • Connection timeout handling.
  • TLS verification settings.
  • Rejection of private and unexpected IP addresses.
  • Unexpected port rejection.
  • Keep-alive connection handling.

Live DNS, TLS negotiation and full SMF integration testing are still required.

Summary

The intention is not to replace the underlying approach proposed in #9861, but to build upon it with more robust connection handling, fewer code changes and a fail-closed approach that avoids reintroducing the original issue.

Feedback and further testing are welcome.

Fixes #9803.
Related to #9861.

@github-actions github-actions Bot added the External data Fetching, processing, and using external data label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External data Fetching, processing, and using external data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.1|3.0] url_resolves_to fails due to caching and low TTL

1 participant