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
4 changes: 4 additions & 0 deletions packages/rstack/src/setup/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const resolveHooksDir = (hooksDir: string): string | FailedInstallResult => {
);
}

if (resolvedDir.includes('..')) {
Comment thread
chenjiahan marked this conversation as resolved.
return fail('invalid-hooks-directory', 'Git hooks directory must not contain "..".');
}

return resolvedDir;
};

Expand Down
6 changes: 5 additions & 1 deletion packages/rstack/tests/cli/setup/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test('reports missing and repeated hooks directory options', ({ expect }) => {
expect(repeated.stderr).toContain('The --hooks-dir option cannot be specified more than once.');
});

test('rejects empty and absolute hooks directory options', ({ expect }) => {
test('rejects invalid hooks directory options', ({ expect }) => {
const empty = runSetup(['--hooks-dir', '']);
expect(empty.status).toBe(1);
expect(empty.stderr).toContain('Git hooks directory must not be empty.');
Expand All @@ -77,6 +77,10 @@ test('rejects empty and absolute hooks directory options', ({ expect }) => {
expect(absolute.stderr).toContain(
'Git hooks directory must be relative to the current directory.',
);

const parent = runSetup(['--hooks-dir', '../hooks']);
expect(parent.status).toBe(1);
expect(parent.stderr).toContain('Git hooks directory must not contain "..".');
});

test('installs hooks silently without loading Rstack config', ({ execCli, expect }) => {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/en/guide/cli/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ When using a custom directory, add the full command to the `prepare` script in t
}
```

> To prevent Git hook files from being created or overwritten outside the current project through parent directory paths, the path must not contain `..`.
### `--help`

`--help` (or `-h`) displays the command's usage and options.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/zh/guide/cli/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ rs setup --hooks-dir "config/git hooks"
}
```

> 为避免通过父目录路径在当前项目之外创建或覆盖 Git hook 文件,路径中不能包含 `..`。

### `--help`

`--help`(或 `-h`)用于显示命令的用法和选项。
Expand Down