diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 51bb35704..5e7b8e554 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -356,6 +356,7 @@ const handler = async function (argv) { } let currentRequestIndex = 0; + let nJumps = 0; // count the number of jumps to avoid infinite loops while (currentRequestIndex < bruJsons.length) { const iter = bruJsons[currentRequestIndex]; const { bruFilepath, bruJson } = iter; @@ -372,6 +373,11 @@ const handler = async function (argv) { const nextRequestName = result?.nextRequestName; if (nextRequestName) { + nJumps++; + if (nJumps > 10000) { + console.error(chalk.red(`Too many jumps, possible infinite loop`)); + process.exit(1); + } const nextRequestIdx = bruJsons.findIndex((iter) => iter.bruJson.name === nextRequestName); if (nextRequestIdx >= 0) { currentRequestIndex = nextRequestIdx; diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 00ce034e8..3a6170abe 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -673,9 +673,10 @@ const registerNetworkIpc = (mainWindow) => { } let currentRequestIndex = 0; + let nJumps = 0; // count the number of jumps to avoid infinite loops while (currentRequestIndex < folderRequests.length) { - item = folderRequests[currentRequestIndex]; - let nextRequestName = undefined; + const item = folderRequests[currentRequestIndex]; + let nextRequestName; const itemUid = item.uid; const eventData = { collectionUid, @@ -866,6 +867,10 @@ const registerNetworkIpc = (mainWindow) => { }); } if (nextRequestName) { + nJumps++; + if (nJumps > 10000) { + throw new Error('Too many jumps, possible infinite loop'); + } const nextRequestIdx = folderRequests.findIndex((request) => request.name === nextRequestName); if (nextRequestIdx >= 0) { currentRequestIndex = nextRequestIdx;