diff --git a/packages/hoppscotch-common/src/newstore/collections.ts b/packages/hoppscotch-common/src/newstore/collections.ts index c79c79ef3..03b121af9 100644 --- a/packages/hoppscotch-common/src/newstore/collections.ts +++ b/packages/hoppscotch-common/src/newstore/collections.ts @@ -533,6 +533,23 @@ const restCollectionDispatchers = defineDispatchers({ return {} } + // Block self-move: moving a folder to its own location + if (path === destinationPath) { + console.error( + `Cannot move folder to itself. Skipping request to move folder '${path}'.` + ) + return {} + } + + // Block descendant move: moving a folder into itself or its descendants + // This would create a cyclic tree structure + if (destinationPath.startsWith(path + "/")) { + console.error( + `Cannot move folder into its descendant. Destination '${destinationPath}' is inside source '${path}'. Skipping request.` + ) + return {} + } + const target = navigateToFolderWithIndexPath( newState, destinationIndexPaths @@ -1201,6 +1218,23 @@ const gqlCollectionDispatchers = defineDispatchers({ return {} } + // Block self-move: moving a folder to its own location + if (path === destinationPath) { + console.error( + `Cannot move folder to itself. Skipping request to move folder '${path}'.` + ) + return {} + } + + // Block descendant move: moving a folder into itself or its descendants + // This would create a cyclic tree structure + if (destinationPath.startsWith(path + "/")) { + console.error( + `Cannot move folder into its descendant. Destination '${destinationPath}' is inside source '${path}'. Skipping request.` + ) + return {} + } + const target = navigateToFolderWithIndexPath( newState, destinationIndexPaths