Skip to content
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

https.createServer accepts any non-falsey values for key and cert #12802

Closed
ramblinjan opened this issue May 2, 2017 · 4 comments
Closed

https.createServer accepts any non-falsey values for key and cert #12802

ramblinjan opened this issue May 2, 2017 · 4 comments
Labels
good first issue Issues that are suitable for first-time contributors. https Issues or PRs related to the https subsystem.

Comments

@ramblinjan
Copy link

ramblinjan commented May 2, 2017

  • Version: v7.4.0
  • Platform: Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
  • Subsystem: https

When using https.createServer, passing a boolean to cert and/or key will not cause an error, but will result in an invalid certificate at runtime. For instance:

require('https').createServer({
  key: true,
  cert: true
// ...

I discovered this with a pretty silly code mistake like:

const key = fs.existsSync('path/to/production/tls.key') || fs.readFileSync('path/to/fallback/tls.key);
const cert = fs.existsSync('path/to/production/tls.cert') || fs.readFileSync('path/to/fallback/tls.cert);

It was certainly user error. However, in the types for the options object, the valid types are listed as:

  • key | <string[]> | | <Buffer[]> | <Object[]>
  • cert | <string[]> | | <Buffer[]>

Then in https.js, there is no typechecking for creating the server, and for outbound requests, non-falsey value for gets concatenated (and therefore cast to a string):

  name += ':';
  if (options.cert)
    name += options.cert;

// ...

  name += ':';
  if (options.key)
    name += options.key;

For invalid types, there could probably be an error thrown rather than issuing a completely invalid certificate. Though it would be overkill to validate certs at runtime rather than time of connection, checking for valid types might be a good idea since there's currently (as far as I can tell) no difference between this mistake and a totally invalid certificate, making it hard to debug. Instead a non-string, non-object (for key), non-buffer should probably be functionally identical to having no certificate.


For SEO purposes, this mistake will likely result in the following error with an in-browser response:
ERR_SSL_VERSION_OR_CIPHER_MISMATCH

@evanlucas
Copy link
Contributor

Possible duplicate of #11978?

@mscdex mscdex added the https Issues or PRs related to the https subsystem. label May 2, 2017
@ramblinjan
Copy link
Author

@evanlucas I'd have to repro it with a different setup to be sure, but I think for null values the browser will report that the certificate is simply missing and declare the site insecure. In this case, the site won't even load because the handshake completely fails and has a ERR_SSL_VERSION_OR_CIPHER_MISMATCH error, which isn't even all that Google-able because that's usually related to using outdated SSL or a client issue. In this specific case, the cert gets treated as "valid," but wrong rather than missing. Point of failure, result, and debug path is totally different from similar issues.

@Trott
Copy link
Member

Trott commented Aug 10, 2017

@nodejs/http

@bnoordhuis bnoordhuis added the good first issue Issues that are suitable for first-time contributors. label Aug 10, 2017
@bnoordhuis
Copy link
Member

Rejecting definitely wrong values is a good idea. I've added the good-first-contribution label.

jimmycann added a commit to jimmycann/node that referenced this issue Aug 13, 2017
When using https.createServer, passing boolean values for `key` and `cert` properties in the options object parameter doesn't throw an error an could lead to potential issues if they're accidentally passed.

This PR aims to throw a reasonable error if a boolean was passed to either of those properties.

Fixes: nodejs#12802
jimmycann added a commit to jimmycann/node that referenced this issue Aug 14, 2017
Taking on board the review from the initial PR, multiple changes have been made.
- Type checking now a whitelist as opposed to only checking for a boolean
- Type checking moved to the underlying `_tls_common` , `tls` and `https` modules now affected
- Arrays are now iterated using `map` instead of `for` for affected sections
-Testing added for the `tls` module

Fixes: nodejs#12802
jimmycann added a commit to jimmycann/node that referenced this issue Aug 16, 2017
Additional changes in line with PR review

- Loosen type checking for buffers using the ArrayBuffer method
- Require pem files using updated fixture access method
- Add tests for ArrayBuffer and DataView types

Fixes: nodejs#12802
jimmycann added a commit to jimmycann/node that referenced this issue Aug 16, 2017
- Change iteration method from map -> forEach

Fixes: nodejs#12802
ghost pushed a commit to ayojs/ayo that referenced this issue Aug 30, 2017
PR-URL: nodejs/node#14807
Fixes: nodejs/node#12802
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
ghost pushed a commit to ayojs/ayo that referenced this issue Aug 30, 2017
PR-URL: nodejs/node#14807
Fixes: nodejs/node#12802
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. https Issues or PRs related to the https subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants