Skip to content

Fix: Enhance path validation to include last opened collections #5123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/bruno-electron/src/ipc/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,21 @@ const envHasSecrets = (environment = {}) => {
return secrets && secrets.length > 0;
};

const validatePathIsInsideCollection = (path) => {
const validatePathIsInsideCollection = (filePath, lastOpenedCollections) => {
const openCollectionPaths = collectionWatcher.getAllWatcherPaths();
const isValid = openCollectionPaths.some((collectionPath) => {
return path.startsWith(collectionPath);
const lastOpenedPaths = lastOpenedCollections ? lastOpenedCollections.getAll() : [];

// Combine both currently watched collections and last opened collections
// todo: remove the lastOpenedPaths from the list
// todo: have a proper way to validate the path without the active watcher logic
const allCollectionPaths = [...new Set([...openCollectionPaths, ...lastOpenedPaths])];

const isValid = allCollectionPaths.some((collectionPath) => {
return filePath.startsWith(collectionPath + path.sep) || filePath === collectionPath;
});

if (!isValid) {
throw new Error(`Path: ${path} should be inside a collection`);
throw new Error(`Path: ${filePath} should be inside a collection`);
}
}

Expand Down Expand Up @@ -247,7 +255,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
if (!validateName(request?.filename)) {
throw new Error(`${request.filename}.bru is not a valid filename`);
}
validatePathIsInsideCollection(pathname);
validatePathIsInsideCollection(pathname, lastOpenedCollections);
const content = await jsonToBruViaWorker(request);
await writeFile(pathname, content);
} catch (error) {
Expand Down