Skip to content

Commit 9021ba6

Browse files
Fix #531
1 parent ed48da4 commit 9021ba6

3 files changed

Lines changed: 5 additions & 26 deletions

File tree

packages/web/src/features/fileTree/api.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { createLogger } from '@sourcebot/shared';
99
import path from 'path';
1010
import { simpleGit } from 'simple-git';
1111
import { FileTreeItem } from './types';
12-
import { buildFileTree, isPathValid, normalizePath } from './utils';
12+
import { buildFileTree, normalizePath } from './utils';
1313
import { compareFileTreeItems } from './utils';
1414

1515
const logger = createLogger('file-tree');
1616

1717
/**
18-
* Returns the tree of files (blobs) and directories (trees) for a given repository,
19-
* at a given revision.
18+
* Returns a file tree spanning the union of all provided paths for the given
19+
* repo/revision, including intermediate directories needed to connect them
20+
* into a single tree.
2021
*/
2122
export const getTree = async (params: { repoName: string, revisionName: string, paths: string[] }) => sew(() =>
2223
withOptionalAuthV2(async ({ org, prisma }) => {
@@ -35,10 +36,6 @@ export const getTree = async (params: { repoName: string, revisionName: string,
3536
const { path: repoPath } = getRepoPath(repo);
3637

3738
const git = simpleGit().cwd(repoPath);
38-
if (!paths.every(path => isPathValid(path))) {
39-
return notFound();
40-
}
41-
4239
const normalizedPaths = paths.map(path => normalizePath(path));
4340

4441
let result: string = '';
@@ -103,9 +100,6 @@ export const getFolderContents = async (params: { repoName: string, revisionName
103100
const { path: repoPath } = getRepoPath(repo);
104101
const git = simpleGit().cwd(repoPath);
105102

106-
if (!isPathValid(path)) {
107-
return notFound();
108-
}
109103
const normalizedPath = normalizePath(path);
110104

111105
let result: string;

packages/web/src/features/fileTree/utils.test.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from 'vitest';
2-
import { buildFileTree, isPathValid, normalizePath } from './utils';
2+
import { buildFileTree, normalizePath } from './utils';
33

44
test('normalizePath adds a trailing slash and strips leading slashes', () => {
55
expect(normalizePath('/a/b')).toBe('a/b/');
@@ -13,15 +13,6 @@ test('normalizePath returns empty string for root', () => {
1313
expect(normalizePath('/')).toBe('');
1414
});
1515

16-
test('isPathValid rejects traversal and null bytes', () => {
17-
expect(isPathValid('a/../b')).toBe(false);
18-
expect(isPathValid('a/\0b')).toBe(false);
19-
});
20-
21-
test('isPathValid allows normal paths', () => {
22-
expect(isPathValid('a/b')).toBe(true);
23-
});
24-
2516
test('buildFileTree handles a empty flat list', () => {
2617
const flatList: { type: string, path: string }[] = [];
2718
const tree = buildFileTree(flatList);

packages/web/src/features/fileTree/utils.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ export const normalizePath = (path: string): string => {
2121
return normalizedPath;
2222
}
2323

24-
// @note: we don't allow directory traversal
25-
// or null bytes in the path.
26-
export const isPathValid = (path: string) => {
27-
return !path.includes('..') && !path.includes('\0');
28-
}
29-
3024
export const buildFileTree = (flatList: { type: string, path: string }[]): FileTreeNode => {
3125
const root: FileTreeNode = {
3226
name: 'root',

0 commit comments

Comments
 (0)