mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge pull request #95 from AikidoSec/proxy-socket-check-if-writable
Check if a socket is writable before writing to it
This commit is contained in:
commit
662b26a2d5
2 changed files with 16 additions and 6 deletions
2
.github/workflows/test-on-pr.yml
vendored
2
.github/workflows/test-on-pr.yml
vendored
|
|
@ -101,7 +101,7 @@ jobs:
|
||||||
|
|
||||||
- name: Setup safe-chain
|
- name: Setup safe-chain
|
||||||
run: |
|
run: |
|
||||||
npm i -g @aikidosec/safe-chain
|
npm i -g @aikidosec/safe-chain@1.0.24
|
||||||
safe-chain setup-ci
|
safe-chain setup-ci
|
||||||
|
|
||||||
- name: Install dependencies (root)
|
- name: Install dependencies (root)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ function tunnelRequestToDestination(req, clientSocket, head) {
|
||||||
ui.writeError(
|
ui.writeError(
|
||||||
`Safe-chain: error connecting to ${hostname}:${port} - ${err.message}`
|
`Safe-chain: error connecting to ${hostname}:${port} - ${err.message}`
|
||||||
);
|
);
|
||||||
|
if (clientSocket.writable) {
|
||||||
clientSocket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
clientSocket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,9 +78,13 @@ function tunnelRequestViaProxy(req, clientSocket, head, proxyUrl) {
|
||||||
ui.writeError(
|
ui.writeError(
|
||||||
`Safe-chain: proxy CONNECT failed: ${response.split("\r\n")[0]}`
|
`Safe-chain: proxy CONNECT failed: ${response.split("\r\n")[0]}`
|
||||||
);
|
);
|
||||||
|
if (clientSocket.writable) {
|
||||||
clientSocket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
clientSocket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
||||||
|
}
|
||||||
|
if (proxySocket.writable) {
|
||||||
proxySocket.end();
|
proxySocket.end();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
proxySocket.on("error", (err) => {
|
proxySocket.on("error", (err) => {
|
||||||
|
|
@ -88,11 +94,15 @@ function tunnelRequestViaProxy(req, clientSocket, head, proxyUrl) {
|
||||||
proxy.port || 8080
|
proxy.port || 8080
|
||||||
} - ${err.message}`
|
} - ${err.message}`
|
||||||
);
|
);
|
||||||
|
if (clientSocket.writable) {
|
||||||
clientSocket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
clientSocket.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
clientSocket.on("error", () => {
|
clientSocket.on("error", () => {
|
||||||
|
if (proxySocket.writable) {
|
||||||
proxySocket.end();
|
proxySocket.end();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue