1

I'm trying to setup an HTTPS server that proxies requests to changing targets that also enforce HTTPS. this is because I want to setup an intercepting https proxy, terminate ssl, modify data and send encrypted modifications to target server (or backwards through the response).

Example:

Browser --> myHTTPSProxy(modify request) --> https://targethost.com --> myHTTPSProxy(modify response) --> Browser

This is sample implementation for the task from the node-http-proxy library:

const https = require('https'),
    fs = require('fs'),
    colors = require('colors'),
    httpProxy = require('http-proxy'),
    httpsOpts = {
        key: fs.readFileSync('agent2-key.pem', 'utf8'),
        cert: fs.readFileSync('agent2-cert.pem', 'utf8')
    };

// Create DUMMY HTTPS SRV
https.createServer(httpsOpts, function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.write('hello https\n');
    res.end();
}).listen(3000);

// PROXY
httpProxy.createServer({
    ssl: httpsOpts,
    target: 'https://localhost:3000',
    secure: false
}).listen(8080);

console.log('https proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8080'.yellow);
console.log('https server '.blue + 'started '.green.bold + 'on port '.blue + '3000 '.yellow);

Certificates are also taken from the library, and I tried using valid ones as well that works on a straight https server but no as a proxy.

as a proxy - I get Secure Connection Failed.

TL;DR Question

Does anyone know how to implement a HTTPS proxy server using nodejs?

Similar unresolved posts:

Https proxy server(secure proxy server) in Nodejs with http-proxy is not working

https://github.com/http-party/node-http-proxy/issues/1456

https://github.com/http-party/node-http-proxy/issues/1506

toti
  • 43
  • 1
  • 6
  • Does this answer your question? https://stackoverflow.com/questions/8165570/https-proxy-server-in-node-js – Gilles Heinesch Apr 05 '21 at 12:22
  • thanks @GillesHeinesch , but if I understood correctly they only forward the traffic using this method and don't allow actual modifications of the request pre-sending it or the response pre- receiving it? – toti Apr 05 '21 at 12:28

0 Answers0