Skip to content
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
6 changes: 6 additions & 0 deletions packages/core/src/config/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ describe('Storage – getPlansDir', () => {
);
});

it('allows project subdirectories whose names start with two dots', () => {
expect(Storage.getPlansDir(projectRoot, './..plans')).toBe(
path.join(projectRoot, '..plans'),
);
});

it('expands tilde in configured plansDirectory values', () => {
const projectInHome = path.join(os.homedir(), 'workspace', 'project');
expect(
Expand Down
16 changes: 11 additions & 5 deletions packages/core/src/config/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ const PLANS_DIR_NAME = 'plans';
const DEBUG_DIR_NAME = 'debug';
const ARENA_DIR_NAME = 'arena';

function isResolvedPathWithinDirectory(childPath: string, parentPath: string) {
const relativePath = path.relative(parentPath, childPath);
return (
relativePath === '' ||
(!relativePath.startsWith(`..${path.sep}`) &&
relativePath !== '..' &&
!path.isAbsolute(relativePath))
);
}

export class Storage {
private readonly targetDir: string;

Expand Down Expand Up @@ -233,11 +243,7 @@ export class Storage {
const realParent = Storage.resolvePathThroughExistingAncestor(parentPath);
const realChild = Storage.resolvePathThroughExistingAncestor(childPath);

const relativePath = path.relative(realParent, realChild);
return (
relativePath === '' ||
(!relativePath.startsWith('..') && !path.isAbsolute(relativePath))
);
return isResolvedPathWithinDirectory(realChild, realParent);
}

static assertPathWithinDirectory(
Expand Down
Loading