package
HTTP Man In The Middle (MITM) Proxy
npm install http-mitm-proxyGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 19 packages.
3.5 MB
Includes dependencies.
The library should work starting Node.js 8.x, but testing is only expected for currently supported LTS versions of Node.js starting Node.js 12.x . use on your own risk with non LTS Node.js versions.
type definitions are now included in this project, no extra steps required.
This example will modify any search results coming from google and replace all the result titles with "Pwned!".
const Proxy = require('http-mitm-proxy').Proxy;
// or using import/module (package.json -> "type": "module")
// import { Proxy } from "http-mitm-proxy";
const proxy = new Proxy();
proxy.onError(function(ctx, err) {
console.error('proxy error:', err);
});
proxy.onRequest(function(ctx, callback) {
if (ctx.clientToProxyRequest.headers.host == 'www.google.com'
&& ctx.clientToProxyRequest.url.indexOf('/search') == 0) {
ctx.use(Proxy.gunzip);
ctx.onResponseData(function(ctx, chunk, callback) {
chunk = Buffer.from(chunk.toString().replace(/<h3.*?<\/h3>/g, '<h3>Pwned!</h3>'));
return callback(null, chunk);
});
}
return callback();
});
console.log('begin listening on 8081')
proxy.listen({port: 8081});You can find more examples in the examples directory
Using node-forge allows the automatic generation of SSL certificates within the proxy. After running your app you will find options.sslCaDir + '/certs/ca.pem' which can be imported to your browser, phone, etc.
Context functions only effect the current request/response. For example you may only want to gunzip requests made to a particular host.
The context available in websocket handlers is a bit different
Example
proxy.listen({ port: 80 });^9.0.1
14.0.3
^3.2.5
3.2.6
^4.3.4
4.4.3
^17.7.2
18.2.0