mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Don't repeatedly call isImdsEndpoint
This commit is contained in:
parent
57a0e88fa4
commit
e421414b8a
2 changed files with 9 additions and 5 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
const imdsEndpoints = [
|
const imdsEndpoints = [
|
||||||
"metadata.google.internal",
|
"metadata.google.internal",
|
||||||
"metadata.goog",
|
"metadata.goog",
|
||||||
"169.254.169.254",
|
"169.254.169.254", // AWS, Azure, Oracle Cloud, GCP
|
||||||
];
|
];
|
||||||
|
|
||||||
export function isImdsEndpoint(/** @type {string} */ host) {
|
export function isImdsEndpoint(/** @type {string} */ host) {
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,17 @@ function tunnelRequestToDestination(req, clientSocket, head) {
|
||||||
serverSocket.on("timeout", () => {
|
serverSocket.on("timeout", () => {
|
||||||
timedoutEndpoints.push(hostname);
|
timedoutEndpoints.push(hostname);
|
||||||
// Suppress error logging for IMDS endpoints - timeouts are expected when not in cloud
|
// Suppress error logging for IMDS endpoints - timeouts are expected when not in cloud
|
||||||
if (isImdsEndpoint(hostname)) {
|
if (isImds) {
|
||||||
ui.writeVerbose(
|
ui.writeVerbose(
|
||||||
`Safe-chain: connect to ${hostname}:${port || 443} timed out after ${connectTimeout}ms`
|
`Safe-chain: connect to ${hostname}:${
|
||||||
|
port || 443
|
||||||
|
} timed out after ${connectTimeout}ms`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
ui.writeError(
|
ui.writeError(
|
||||||
`Safe-chain: connect to ${hostname}:${port || 443} timed out after ${connectTimeout}ms`
|
`Safe-chain: connect to ${hostname}:${
|
||||||
|
port || 443
|
||||||
|
} timed out after ${connectTimeout}ms`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
serverSocket.destroy(); // Clean up socket to prevent event loop hanging
|
serverSocket.destroy(); // Clean up socket to prevent event loop hanging
|
||||||
|
|
@ -98,7 +102,7 @@ function tunnelRequestToDestination(req, clientSocket, head) {
|
||||||
});
|
});
|
||||||
|
|
||||||
serverSocket.on("error", (err) => {
|
serverSocket.on("error", (err) => {
|
||||||
if (isImdsEndpoint(hostname)) {
|
if (isImds) {
|
||||||
ui.writeVerbose(
|
ui.writeVerbose(
|
||||||
`Safe-chain: error connecting to ${hostname}:${port} - ${err.message}`
|
`Safe-chain: error connecting to ${hostname}:${port} - ${err.message}`
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue