mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge 27d5eff771 into 9453c8c0c9
This commit is contained in:
commit
68d71b2e31
3 changed files with 93 additions and 25 deletions
|
|
@ -68,21 +68,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(
|
||||
|
|
|
|||
|
|
@ -14,22 +14,28 @@ let timedoutImdsEndpoints = [];
|
|||
* @returns {void}
|
||||
*/
|
||||
export function tunnelRequest(req, clientSocket, head) {
|
||||
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
||||
try {
|
||||
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
|
||||
|
||||
if (httpsProxy) {
|
||||
// If an HTTPS proxy is set, tunnel the request via the proxy
|
||||
// This is the system proxy, not the safe-chain proxy
|
||||
// The package manager will run via the safe-chain proxy
|
||||
// The safe-chain proxy will then send the request to the system proxy
|
||||
// Typical flow: package manager -> safe-chain proxy -> system proxy -> destination
|
||||
if (httpsProxy) {
|
||||
// If an HTTPS proxy is set, tunnel the request via the proxy
|
||||
// This is the system proxy, not the safe-chain proxy
|
||||
// The package manager will run via the safe-chain proxy
|
||||
// The safe-chain proxy will then send the request to the system proxy
|
||||
// Typical flow: package manager -> safe-chain proxy -> system proxy -> destination
|
||||
|
||||
// There are 2 processes involved in this:
|
||||
// 1. Safe-chain process: has HTTPS_PROXY set to system proxy
|
||||
// 2. Package manager process: has HTTPS_PROXY set to safe-chain proxy
|
||||
// There are 2 processes involved in this:
|
||||
// 1. Safe-chain process: has HTTPS_PROXY set to system proxy
|
||||
// 2. Package manager process: has HTTPS_PROXY set to safe-chain proxy
|
||||
|
||||
tunnelRequestViaProxy(req, clientSocket, head, httpsProxy);
|
||||
} else {
|
||||
tunnelRequestToDestination(req, clientSocket, head);
|
||||
tunnelRequestViaProxy(req, clientSocket, head, httpsProxy);
|
||||
} else {
|
||||
tunnelRequestToDestination(req, clientSocket, head);
|
||||
}
|
||||
} catch (/** @type {any} */ err) {
|
||||
ui.writeError(
|
||||
`Safe-chain: tunnel request failed for ${req.url} : ${err.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue