-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
tls: stronger validation for 'servername' in server.addContext #33943
Conversation
If 'servername' is not provided, 'ERR_MISSING_ARGS is thrown. If 'servername' is not a string, 'ERR_INVALID_ARG_TYPE' is thrown. If 'servername' is an IP address, 'ERR_INVALID_ARG_VALUE' is thrown, since literal IPv4 and IPv6 addresses are not permitted in SNI. Fixed API documentation ('hostname' -> 'servername'). Also removed a redundant error 'ERR_TLS_REQUIRED_SERVER_NAME'.
@nodejs/crypto |
For consistency, maybe it would be good to apply these validations to client connections too? Lines 1618 to 1629 in fdf10ad
|
The warning message says it will be ignored in a future version, rather than rejected... |
Me neither. I would leave it as is for now. I can investigate later and open a separate PR for it. |
Codecov Report
@@ Coverage Diff @@
## master #33943 +/- ##
========================================
Coverage 96.68% 96.69%
========================================
Files 204 204
Lines 67657 67795 +138
========================================
+ Hits 65416 65556 +140
+ Misses 2241 2239 -2
Continue to review full report at Codecov.
|
This PR seems to have gotten a little stuck. Is there anything that should be done to move further? |
@@ -1411,7 +1411,19 @@ Server.prototype.setOptions = deprecate(function(options) { | |||
// SNI Contexts High-Level API | |||
Server.prototype.addContext = function(servername, context) { | |||
if (!servername) { | |||
throw new ERR_TLS_REQUIRED_SERVER_NAME(); | |||
throw new ERR_MISSING_ARGS('servername'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it semver-major, I think? (Meaning that it cannot land on any of the active release lines.)
@@ -545,18 +545,19 @@ called: | |||
* `tlsSocket` {tls.TLSSocket} The `tls.TLSSocket` instance from which the | |||
error originated. | |||
|
|||
### `server.addContext(hostname, context)` | |||
### `server.addContext(servername, context)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think hostname
is better. This is how TLS defines a "server name":
struct {
NameType name_type;
select (name_type) {
case host_name: HostName;
} name;
} ServerName;
It is correct that TLS does not allow IP addresses in the HostName
field, but that is not necessarily true for ServerName
. TLS simply doesn't support other NameType
s so far, but it might do so in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the point, but... the extension has never changed and "server name" === "host name server name" in everyone's minds. I personally don't think it's worth it to expose this detail to users, nor have I seen any other API do it.
So I'm personally +1 for naming the parameter servername
and stating things like "Setting the TLS ServerName to an IP address is not permitted", as we currently do.
throw new ERR_INVALID_ARG_TYPE('servername', 'string', servername); | ||
} | ||
|
||
if (net.isIP(servername)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, what happens if servername
is neither an IP nor a DNS hostname?
I'm still not sure about throwing on IP addresses... I suppose it would break some code. |
@mkrawczuk This needs a rebase to resolve the git conflict. |
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
Closing this because it has stalled. Feel free to reopen if this PR is still relevant, or to ping the collaborator who labelled it stalled if you have any questions. |
If 'servername' is not provided, 'ERR_MISSING_ARGS is thrown.
If 'servername' is not a string, 'ERR_INVALID_ARG_TYPE' is thrown.
If 'servername' is an IP address, 'ERR_INVALID_ARG_VALUE' is thrown, since
literal IPv4 and IPv6 addresses are not permitted in SNI.
Fixed API documentation ('hostname' -> 'servername').
Also removed a redundant error 'ERR_TLS_REQUIRED_SERVER_NAME'.
This PR was inspired by: #19988
make -j4 test
(UNIX), orvcbuild test
(Windows) passes