node icon indicating copy to clipboard operation
node copied to clipboard

Node uses an hardcoded list of certificate authorities

Open fir4 opened this issue 10 years ago • 35 comments

I was dumbfounded when I realized that Node uses a statically compiled, manually updated, hardcoded list of certificate authorities, rather than relying on the system's trust store, or even just a directory truststore of its own.

This causes a large amount of problems :

  • Dependancy on the Node community for reactiveness in addition or removal of certificates
  • Dependancy on the Node community in terms of certificate trust
  • Prevents companies and anyone with their own PKI from using their certificates globally
  • Requires support from EVERY node application making use of SSL to include certificates
  • Requires modification of source code if an application doesn't happen to support it
  • Requires modification and rebuilding of Node to remove certificates that wouldn't be trusted by an organisation

Now, I can see no practical use for that. While this is acceptable in a development environment, where you can make changes to your own application, this is outright unusable... and i can't stress enough the security implications for many organisations.

Proposed solutions :

  • Make use of the standard system trust store, like any sensible application
  • Use a dedicated globally installed trust store, allowing user modifications, and why not, handling with npm
  • Dynamically load CAs using relative path, in a way similar to the usage of the node_modules folder

TL;DR: CA Certificates are hardcoded in node. It may be OK for dev, but it sucks big time for ops.

fir4 avatar Dec 07 '15 10:12 fir4

I am sorry, it seems I didn't made clear what my point is. There was absolutely no sarcasm intended in any way.

See: As we can not influence the environments our projects need to run in, we simply can not build upon a foundation which does not cover such cases.

We had to move an entire project to a different language, as it was impossible to make it work using Node inside our clients environment.

xel-x avatar Jul 04 '16 11:07 xel-x

I don't get that attitude. You feel strongly enough to complain about it on the bug tracker, apparently strongly enough to switch to a different language but not strongly enough to spend an hour or two on a pull request. The whole point of open source is that you can change it if you don't like what it does.

bnoordhuis avatar Jul 04 '16 11:07 bnoordhuis

I have proposed a solution and I think it will be more productive if others do the same or make a pull request instead of just bumping the thread.

doodadjs avatar Jul 04 '16 11:07 doodadjs

Had similar issues with this, have internal apps using an internally signed cert. Opted to use https.globalAgent and set an array of CA's which are defined in a config and updated on an env basis.

E.g.

const trustedCa = [
    '/etc/pki/tls/certs/ca-bundle.crt',
    '/path/to/custom/cert.crt'
];

https.globalAgent.options.ca = [];
for (const ca of trustedCa) {
    https.globalAgent.options.ca.push(fs.readFileSync(ca));
}

mwain avatar Aug 08 '16 11:08 mwain

It turns out that https.request module with ca option doesn't support having multiple certificates in pem file. @DuBistKomisch solution solved this problem. I'm using node v4.

jan-swiecki avatar Aug 17 '16 14:08 jan-swiecki

https://github.com/nodejs/node/pull/8334 fixes most of this.

AdamMajer avatar Aug 31 '16 09:08 AdamMajer

@jan-swiecki In https://github.com/nodejs/node/issues/4175#issuecomment-240422257 you mention that

It turns out that https.request module with ca option doesn't support having multiple certificates in pem file

Its not clear if you are talking about a user-land module, but if you are talking about node's https.request() method, I did a some testing, and it supports concatenated PEM certificates in options.ca in node 6.x (which I expected from reading the code), but not node 4.x.

If you can't upgrade, open an issue about it and make the case that this is a feature that should be back-ported to 4 from 6. I'm not sure what the current stance is on back-porting features, but if its low risk, it may be possible.

sam-github avatar Oct 17 '16 19:10 sam-github

Setting https.globalAgent.options.ca works for connections to my own server but causes SSL errors for regular connections (which normally work when https.globalAgent.options.ca isn't set). Is there a way to get https.globalAgent.options.ca to append to the default list of certificates used by node?

SeanHayes avatar Feb 08 '19 04:02 SeanHayes

Not programmatically, but with env configuration it is: https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file

sam-github avatar Feb 09 '19 20:02 sam-github

@mwain just wanted to understand will https.globalAgent.options.ca.push(fs.readFileSync(ca)); override the globally trusted Nodejs certificates (the Mozilla certificates which come bundled with nodejs as default trusted CA) ? and my second concern is will it impact some performance issue?

Looking forward to your reply

Had similar issues with this, have internal apps using an internally signed cert. Opted to use https.globalAgent and set an array of CA's which are defined in a config and updated on an env basis.

E.g.

const trustedCa = [
    '/etc/pki/tls/certs/ca-bundle.crt',
    '/path/to/custom/cert.crt'
];

https.globalAgent.options.ca = [];
for (const ca of trustedCa) {
    https.globalAgent.options.ca.push(fs.readFileSync(ca));
}

nomanmaqsood avatar Aug 12 '21 19:08 nomanmaqsood

Can anyone please explain something I'm not understanding about the rationale of bundling own CA store in Node as opposed to using the system CA store?

I see two reasons why Node might choose to use the Firefox's store:

  • Not have to interface with individual OS's APIs for trust stores
  • Be able to boot bad CAs in response to security-related events

I think Mozilla's reason for bundling the CA store is primarily the latter as described in this article: https://blog.mozilla.org/security/2019/02/14/why-does-mozilla-maintain-our-own-root-certificate-store

But, I do not think this applies to Node? Because since the store is bundled and Node doesn't not have a self-updater, no CA can be booted from an existing Node installation, correct? So if there was a bad CA to be removed, the Node installation at a user's server would have to be updated to the new version that removes the bad CA by updating the bundled store.

If that is the case, is the situation merely that Node bundles the Mozilla CA store so that it doesn't have to implement each OS's APIs for the trust store reading? And since --use-openssl-ca is supported, is that not kind of a moot point now? Could --use-openssl-ca be made the default? What would the downsides of that be? Is it not the default due to backcompat concerns?

Very curious to learn more about this, thank you in advance.

TomasHubelbauer avatar Oct 05 '21 08:10 TomasHubelbauer

since --use-openssl-ca is supported, is that not kind of a moot point now?

@TomasHubelbauer --use-openssl-ca is not supported on Windows since Windows has its own certificate store. But it might be made default elsewhere perhaps.

ustun avatar Jan 15 '22 08:01 ustun

Thank you for sharing don't feel dumb found you can not know everything.

Silcorrea78 avatar Jul 15 '25 13:07 Silcorrea78

This is terrible and should be addressed, NOT closed. Why is --use-openssl-ca still not the default? What is the rationale behind hard-coding vs system compliance.

Also: Stop asking people to put effort and time into patches when the first step is to address the WHY and HOW this came to be, you cannot just rewrite entire software and then having your "patch" rejected because it looks cool.

thoughtsunificator avatar Aug 17 '25 20:08 thoughtsunificator

For macOS and Windows, node recently added --use-system-ca flag.

ustun-rn avatar Aug 18 '25 13:08 ustun-rn