Skip to content

SNI is incorrectly set to IP addresses using the https module #18071

Closed
@rcombs

Description

@rcombs
  • Version: v9.3.0
  • Platform: Darwin MacBook-Pro.localdomain 17.4.0 Darwin Kernel Version 17.4.0: Tue Dec 19 11:20:50 PST 2017; root:xnu-4570.41.2~2/RELEASE_X86_64 x86_64
  • Subsystem: https

Example code:

const https = require('https');
https.get('https://127.0.0.1:8888', (res) => { console.log('foo'); });

If you have a server listening on 8888, it will receive a TLS ClientHello containing a ServerName extension indicating the IPv4 address literal 127.0.0.1. RFC 6066 states:

Literal IPv4 and IPv6 addresses are not permitted in "HostName".

This can cause unexpected results depending on how the server handles invalid or unexpected SNI, which may be different from the no-SNI case (which is what's expected here).

I can imagine about three ways to address this:

  • Modify the string case in https.request to drop the hostname field if it's an IP address
    • This has the benefit of simplicity, but still produces invalid requests if the user parses the URL themselves
  • Modify _tls_wrap.connect to drop the server name if it's an IP address
    • This should handle most accidental cases.
  • Modify TLSSocket.setServername to be a no-op (or set to null) if the passed value is an IP address
    • This handles all cases (short of the user calling into the C++ code directly), but prevents a user from explicitly doing the wrong thing via public API if they want to (not sure if that's considered desirable).

Metadata

Metadata

Assignees

No one assigned

    Labels

    tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions