QA
Intermediate LevelNode JS

How do you configure custom SSL/TLS certificate authorities (ca) for internal corporate microservice HTTPS requests?

❓ Interview Prompt: const agent = new https.Agent({ ca: fs.readFileSync("corporate-ca.crt"), rejectUnauthorized: true }); fetch("https://internal.api", { dispatcher: agent }). Securely trusts internal self-signed certificates without disabling SSL verification.

When Node.js microservices communicate with internal services using self-signed TLS certificates, disabling validation ('rejectUnauthorized: false') creates severe security vulnerabilities!

Security Solution:

Pass custom Certificate Authority ('ca') certificates to 'https.Agent' while keeping 'rejectUnauthorized: true' enabled!

Code Implementation Example

javascript
import https from 'node:https';
import fs from 'node:fs';

const customAgent = new https.Agent({
  ca: fs.readFileSync('internal-ca.crt'),
  rejectUnauthorized: true // Keeps TLS verification ACTIVE!
});

https.get('https://internal-service.local/api', { agent: customAgent }, (res) => {
  console.log('Secure internal HTTPS status:', res.statusCode);
});
💡Configuring custom CA certificates on https.Agent securely.
🎯 Interview Key Takeaway

Pass custom CA certificates to https.Agent instead of disabling TLS validation with rejectUnauthorized: false.

#https.Agent#TLS#Certificates#Security#Intermediate
Back to all Node JS Questions→

More Node JS Interview Questions

Beginner LevelNode JS

How does the Node.js Event Loop work? Explain the 6 execution phases (Timers, Pending, Poll, Check, Close).

Beginner LevelNode JS

What does 'Single-Threaded, Event-Driven, Non-Blocking I/O' mean in Node.js?

Beginner LevelNode JS

What is the difference between process.nextTick() and setImmediate()?