mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Listen to error events on sockets
This commit is contained in:
parent
7603a29182
commit
a377fd6caa
2 changed files with 12 additions and 0 deletions
|
|
@ -5,6 +5,12 @@ import { HttpsProxyAgent } from "https-proxy-agent";
|
||||||
export function mitmConnect(req, clientSocket, isAllowed) {
|
export function mitmConnect(req, clientSocket, isAllowed) {
|
||||||
const { hostname } = new URL(`http://${req.url}`);
|
const { hostname } = new URL(`http://${req.url}`);
|
||||||
|
|
||||||
|
clientSocket.on("error", () => {
|
||||||
|
// NO-OP
|
||||||
|
// This can happen if the client TCP socket sends RST instead of FIN.
|
||||||
|
// Not subscribing to 'close' event will cause node to throw and crash.
|
||||||
|
});
|
||||||
|
|
||||||
const server = createHttpsServer(hostname, isAllowed);
|
const server = createHttpsServer(hostname, isAllowed);
|
||||||
|
|
||||||
// Establish the connection
|
// Establish the connection
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ export function tunnelRequest(req, clientSocket, head) {
|
||||||
function tunnelRequestToDestination(req, clientSocket, head) {
|
function tunnelRequestToDestination(req, clientSocket, head) {
|
||||||
const { port, hostname } = new URL(`http://${req.url}`);
|
const { port, hostname } = new URL(`http://${req.url}`);
|
||||||
|
|
||||||
|
clientSocket.on("error", () => {
|
||||||
|
// NO-OP
|
||||||
|
// This can happen if the client TCP socket sends RST instead of FIN.
|
||||||
|
// Not subscribing to 'close' event will cause node to throw and crash.
|
||||||
|
});
|
||||||
|
|
||||||
const serverSocket = net.connect(port || 443, hostname, () => {
|
const serverSocket = net.connect(port || 443, hostname, () => {
|
||||||
clientSocket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
clientSocket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
||||||
serverSocket.write(head);
|
serverSocket.write(head);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue