mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Gracefully handle network failure during MITM + more logging
This commit is contained in:
parent
4b07619769
commit
6c65fb3f4c
2 changed files with 72 additions and 12 deletions
|
|
@ -67,21 +67,29 @@ function createHttpsServer(hostname, port, interceptor) {
|
|||
return;
|
||||
}
|
||||
|
||||
const pathAndQuery = getRequestPathAndQuery(req.url);
|
||||
const targetUrl = `https://${hostname}${pathAndQuery}`;
|
||||
try {
|
||||
const pathAndQuery = getRequestPathAndQuery(req.url);
|
||||
const targetUrl = `https://${hostname}${pathAndQuery}`;
|
||||
|
||||
const requestInterceptor = await interceptor.handleRequest(targetUrl);
|
||||
const blockResponse = requestInterceptor.blockResponse;
|
||||
const requestInterceptor = await interceptor.handleRequest(targetUrl);
|
||||
const blockResponse = requestInterceptor.blockResponse;
|
||||
|
||||
if (blockResponse) {
|
||||
ui.writeVerbose(`Safe-chain: Blocking request to ${targetUrl}`);
|
||||
res.writeHead(blockResponse.statusCode, blockResponse.message);
|
||||
res.end(blockResponse.message);
|
||||
return;
|
||||
if (blockResponse) {
|
||||
ui.writeVerbose(`Safe-chain: Blocking request to ${targetUrl}`);
|
||||
res.writeHead(blockResponse.statusCode, blockResponse.message);
|
||||
res.end(blockResponse.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Collect request body
|
||||
forwardRequest(req, hostname, port, res, requestInterceptor);
|
||||
} catch (/** @type {any} */ error) {
|
||||
ui.writeError(
|
||||
`Safe-chain: Error handling request for ${req.url}: ${error.message}`
|
||||
);
|
||||
res.writeHead(502, "Bad Gateway");
|
||||
res.end("Bad Gateway: Error handling request");
|
||||
}
|
||||
|
||||
// Collect request body
|
||||
forwardRequest(req, hostname, port, res, requestInterceptor);
|
||||
}
|
||||
|
||||
const server = https.createServer(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue