HTTP Man In The Middle (MITM) Proxy

1.1.0 · maintenance · verified Tue Apr 21

http-mitm-proxy is a robust Node.js-based HTTP and HTTPS Man In The Middle (MITM) proxy designed for intercepting, inspecting, and modifying network traffic, including WebSocket communications. It provides granular control over requests and responses through its event-driven API, allowing developers to implement custom filters and handlers. A key feature is its automatic generation of SSL certificates using `node-forge`, which facilitates transparent interception of encrypted HTTPS connections, requiring users to trust a generated root CA certificate. The current stable version is 1.1.0, which was published approximately two years ago. While the library is still widely used and downloaded, its maintenance status is currently considered inactive, with no new releases in the past year and limited recent activity on its GitHub repository. Key differentiators include its pure Node.js implementation, bundled TypeScript definitions, and a modular API for extending functionality with various request and response filters.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes an HTTP MITM proxy on port 8081 and demonstrates how to intercept and modify responses, specifically replacing Google search result titles with 'Pwned!'. It also includes basic error handling. To intercept HTTPS, the generated CA certificate must be trusted by the client.

import { Proxy } from 'http-mitm-proxy';

const proxy = new Proxy();

proxy.onError(function(ctx, err) {
  console.error('Proxy error for URL:', ctx?.clientToProxyRequest?.url || 'N/A', 'Error:', err);
});

proxy.onRequest(function(ctx, callback) {
  // Example: Modify Google search results
  if (ctx.clientToProxyRequest.headers.host === 'www.google.com' && ctx.clientToProxyRequest.url.startsWith('/search')) {
    ctx.use(Proxy.gunzip); // Decompress gzipped responses

    ctx.onResponseData(function(ctx, chunk, callback) {
      // Replace all h3 titles with "Pwned!"
      chunk = Buffer.from(chunk.toString().replace(/<h3.*?<\/h3>/g, '<h3>Pwned!</h3>'));
      return callback(null, chunk);
    });
  }
  return callback();
});

console.log('HTTP MITM Proxy listening on port 8081');
proxy.listen({ port: 8081 });

view raw JSON →