In this lesson, you will learn how to enforce modern protocol versions and robust cipher suites to ensure your Node.js HTTPS termination point remains resilient against cryptographic downgrade attacks.
When you initialize an https.createServer or configure an tls.TLSSocket, Node.js defaults to system-wide settings, which may prioritize compatibility over security. To harden your infrastructure, you must explicitly define the minVersion and ciphers to strip away legacy protocols like TLS 1.0/1.1 and weak encryption algorithms.
Configuring Protocol Versions
Modern TLS demands at least TLS 1.2, though TLS 1.3 is the current gold standard for performance and security. By setting minVersion, you ensure the handshake fails if a client attempts to connect using an outdated, vulnerable protocol:
const https = require('https');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem'),
// Force modern protocols
minVersion: 'TLSv1.2',
maxVersion: 'TLSv1.3',
// Restrict to strong cipher suites
ciphers: [
'ECDHE-ECDSA-AES128-GCM-SHA256',
'ECDHE-RSA-AES128-GCM-SHA256',
'ECDHE-ECDSA-AES256-GCM-SHA384',
'ECDHE-RSA-AES256-GCM-SHA384'
].join(':'),
honorCipherOrder: true
};
https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('Secure connection established.');
}).listen(443);
Why Cipher Ordering Matters
Setting honorCipherOrder: true is a vital hardening step. It forces the server to choose the strongest cipher from the list provided in your configuration, rather than letting the client "negotiate down" to a weaker algorithm that you happen to support for compatibility.
By strictly limiting your cipher list, you prevent the use of CBC (Cipher Block Chaining) mode ciphers—which have historically been prone to padding oracle attacks—in favor of AEAD (Authenticated Encryption with Associated Data) modes like GCM (Galois/Counter Mode). Regularly audit these configurations, as the landscape of cryptographic "strength" shifts; what is considered secure today may require updates tomorrow to defend against emerging computational threats.
Key Takeaway: Secure TLS termination requires an explicit "deny-by-default" stance, enforcing strict minVersion constraints and prioritizing modern, authenticated GCM cipher suites to prevent downgrade attacks.