@aikidosec/safe-chain 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikidosec/safe-chain",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "scripts": {
5
5
  "test": "node --test --experimental-test-module-mocks 'src/**/*.spec.js'",
6
6
  "test:watch": "node --test --watch --experimental-test-module-mocks 'src/**/*.spec.js'",
@@ -5,6 +5,12 @@ import { HttpsProxyAgent } from "https-proxy-agent";
5
5
  export function mitmConnect(req, clientSocket, isAllowed) {
6
6
  const { hostname } = new URL(`http://${req.url}`);
7
7
 
8
+ clientSocket.on("error", () => {
9
+ // NO-OP
10
+ // This can happen if the client TCP socket sends RST instead of FIN.
11
+ // Not subscribing to 'close' event will cause node to throw and crash.
12
+ });
13
+
8
14
  const server = createHttpsServer(hostname, isAllowed);
9
15
 
10
16
  // Establish the connection
@@ -24,6 +24,12 @@ export function tunnelRequest(req, clientSocket, head) {
24
24
  function tunnelRequestToDestination(req, clientSocket, head) {
25
25
  const { port, hostname } = new URL(`http://${req.url}`);
26
26
 
27
+ clientSocket.on("error", () => {
28
+ // NO-OP
29
+ // This can happen if the client TCP socket sends RST instead of FIN.
30
+ // Not subscribing to 'close' event will cause node to throw and crash.
31
+ });
32
+
27
33
  const serverSocket = net.connect(port || 443, hostname, () => {
28
34
  clientSocket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
29
35
  serverSocket.write(head);