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

tls.connect() options ciphers no longer accept null as a valid value in node v15.3.0 #36292

Closed
T1B0 opened this issue Nov 27, 2020 · 15 comments · Fixed by #41170
Closed

tls.connect() options ciphers no longer accept null as a valid value in node v15.3.0 #36292

T1B0 opened this issue Nov 27, 2020 · 15 comments · Fixed by #41170
Labels
tls Issues and PRs related to the tls subsystem.

Comments

@T1B0
Copy link

T1B0 commented Nov 27, 2020

  • Version:

node v15.3.0

  • Platform:

Reproduced on Linux 5.9.0-3-amd64 #1 SMP Debian 5.9.9-1 (2020-11-19) x86_64 GNU/Linux - but probably applicable on all platform

  • Subsystem:

tls.connect() options

What steps will reproduce the bug?

Before version 15.3.0 tls.connect (also accepted by https.request() ) option value null was accepted as falsy value for the cipthers option.
As of version 15.3.0, passing option.ciphers = null throw an error.

case.js (tweaked from https://nodejs.org/api/https.html#https_https_request_options_callback )

const https = require('https');

const options = {
  hostname: 'nodejs.org',
  port: 443,
  path: '/en/',
  ciphers: null,
  method: 'GET'
};

const req = https.request(options, (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (e) => {
  console.error(e);
});

req.end();

You get a connection that end up with 200 OK using this v15.2.1 dockerfile

FROM node:15.2.1-buster-slim

COPY ./case.js ./

CMD node case.js

but it will throw an error with a v15.3.0 dockerfile

FROM node:15.3.0-buster-slim

COPY ./case.js ./

CMD node case.js

How often does it reproduce? Is there a required condition?

throw an error 100% of the time on v15.3.0 with options.ciphers = null

What is the expected behavior?

I have no doubt it is a changing behavior, but i don't know what was the expected behavior of an undocumented cipher option value in the first place either. i just know that it used to work.

What do you see instead?

behavior changed, it now throw an error :

node:internal/validators:123
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "options.ciphers" property must be of type string. Received null
    at new NodeError (node:internal/errors:278:15)
    at validateString (node:internal/validators:123:11)
    at Object.createSecureContext (node:_tls_common:267:5)
    at Object.connect (node:_tls_wrap:1581:48)
    at Agent.createConnection (node:https:129:22)
    at Agent.createSocket (node:_http_agent:323:26)
    at Agent.addRequest (node:_http_agent:274:10)
    at new ClientRequest (node:_http_client:318:16)
    at Object.request (node:https:313:10)
    at Object.<anonymous> (/case.js:11:19) {
  code: 'ERR_INVALID_ARG_TYPE'

Additional information

The point of this report is to warn about this non-obvious breaking behavior change and not to say it's not acceptable/legit api change.

ps: Thanks to @jasnell for encouraging me to write an issue 👍

@T1B0
Copy link
Author

T1B0 commented Nov 27, 2020

cc @spalger for the https://github.com/elastic/elasticsearch-js-legacy/ part ^^

@Trott
Copy link
Member

Trott commented Nov 29, 2020

I did a bisect and the commit that introduced this issue is 35274cb.

@jasnell
Copy link
Member

jasnell commented Nov 29, 2020

Yep, already planning on working on it on Monday.

@Trott
Copy link
Member

Trott commented Nov 29, 2020

Yep, already planning on working on it on Monday.

It's a one-line fix so I hope I'm not ruining your Monday plans/strategy.: #36318

@tmadeira
Copy link

tmadeira commented Dec 1, 2020

Yep, already planning on working on it on Monday.

It's a one-line fix so I hope I'm not ruining your Monday plans/strategy.: #36318

I think the same fix is needed for dhparam !== undefined, crl !== undefined, sessionIdContext !== undefined, pfx !== undefined. Even setting ciphers here I'm getting "Error: Unable to load PFX certificate" in a code that used to work before node v15.3.0.

@Trott Trott closed this as completed in 4a741b8 Dec 2, 2020
@Trott
Copy link
Member

Trott commented Dec 3, 2020

Reopening based on #36292 (comment). /ping @jasnell

@Trott Trott reopened this Dec 3, 2020
@targos targos added the tls Issues and PRs related to the tls subsystem. label Dec 6, 2020
danielleadams pushed a commit that referenced this issue Dec 7, 2020
Allow null along with undefined for cipher value.

Fixes: #36292

PR-URL: #36318
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
cjihrig pushed a commit to cjihrig/node that referenced this issue Dec 8, 2020
Allow null along with undefined for cipher value.

Fixes: nodejs#36292

PR-URL: nodejs#36318
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
ownagedj pushed a commit to magora-labs/rail that referenced this issue Nov 9, 2021
@CallMeLaNN
Copy link
Contributor

Can we look into this. This is the only thing left before I can switch to latest LTS due to Error: Unable to load PFX certificate

The APNS library https://github.com/parse-community/node-apn expect pfx: null if I configure to use pem cert. This is reproduceable in 16.13.1:

http2.connect(`https://api.push.apple.com/`, { cert, key, pfx: null })

The lib/_tls_common.js structure from the PR above probably changed. I guess the remaining fixes should be in this file right?

if (pfx !== undefined) {

@Trott
Copy link
Member

Trott commented Dec 12, 2021

Can we look into this. This is the only thing left before I can switch to latest LTS due to Error: Unable to load PFX certificate

The APNS library https://github.com/parse-community/node-apn expect pfx: null if I configure to use pem cert. This is reproduceable in 16.13.1:

http2.connect(`https://api.push.apple.com/`, { cert, key, pfx: null })

The lib/_tls_common.js structure from the PR above probably changed. I guess the remaining fixes should be in this file right?

if (pfx !== undefined) {

@nodejs/crypto @nodejs/http2 Can anyone comment?

@CallMeLaNN
Copy link
Contributor

I think I can submit PR if null is acceptable.

v14 and latest doc doesn't mentioned specifically either undefined or null.

@mcollina
Copy link
Member

The APNS library https://github.com/parse-community/node-apn expect pfx: null if I configure to use pem cert.

Where does it do this? I could not find a reference to pfx in that library.

I see no problem in allowing null for pfx, go for the PR!

CallMeLaNN added a commit to CallMeLaNN/node that referenced this issue Dec 14, 2021
Allow null along with undefined for pfx value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to pfx

Fixes: nodejs#36292
@CallMeLaNN
Copy link
Contributor

Where does it do this? I could not find a reference to pfx in that library.

https://github.com/parse-community/node-apn/blob/master/doc/provider.markdown
Basically it passes their options to http2.connect(address, options) but somehow options.pfx is always null.

How about dhparam, crl, sessionIdContext as mentioned #36292 (comment)?

I'm not sure of those options, but the pattern is very similar. Let me know if I can include those options in the PR.

@mcollina
Copy link
Member

I would just include them all, thanks.

@fholzer
Copy link

fholzer commented Dec 14, 2021

In case anyone got here looking for a workaround, but for some reason you don't have the luxury of being able to set pfx to undefined: As an alternative you can set pfx to an empty array []. That resolved the issue for me and my elasticsearch client. (So the elasticsearch client options would look like this: { "ssl": { "pfx": [] } })

CallMeLaNN added a commit to CallMeLaNN/node that referenced this issue Dec 15, 2021
Allow null along with undefined for pfx value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to pfx

Fixes: nodejs#36292
CallMeLaNN added a commit to CallMeLaNN/node that referenced this issue Dec 15, 2021
Allow the expected null along with undefined for options value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to options

Fixes: nodejs#36292
@alolis
Copy link

alolis commented Dec 16, 2021

Thanks @fholzer , you saved the day.

nodejs-github-bot pushed a commit that referenced this issue Dec 27, 2021
Allow null along with undefined for pfx value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to pfx

Fixes: #36292

PR-URL: #41170
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
targos pushed a commit that referenced this issue Jan 14, 2022
Allow null along with undefined for pfx value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to pfx

Fixes: #36292

PR-URL: #41170
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 31, 2022
Allow null along with undefined for pfx value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to pfx

Fixes: #36292

PR-URL: #41170
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Linkgoron pushed a commit to Linkgoron/node that referenced this issue Jan 31, 2022
Allow null along with undefined for pfx value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to pfx

Fixes: nodejs#36292

PR-URL: nodejs#41170
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
danielleadams pushed a commit that referenced this issue Feb 1, 2022
Allow null along with undefined for pfx value.

This is to avoid breaking change when upgrading v14 to v16 and
3rd party library passing null to pfx

Fixes: #36292

PR-URL: #41170
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
@fholzer
Copy link

fholzer commented Nov 29, 2022

To anyone still finding this when using the elasticsearch client...

Your options:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants