Skip to content

Commit 75c0376

Browse files
hongyeclaude
andcommitted
docs(permissions): add JSDoc to address CodeRabbit docstring coverage warning
CodeRabbit flagged the PR with "Docstring coverage is 50.00% which is insufficient (threshold 80.00%)". Added JSDoc to: 1. `formatDirectoryList` in pathValidation.ts — the only production function in the changed files that lacked JSDoc. Brief description of the truncation behavior + reference to MAX_DIRS_TO_LIST. 2. Both `describeIfWindows` blocks in pathValidation.test.ts — explain the security rationale of the MinGW-normalization fix and the sandbox-escape regression scenarios. Individual `test()` calls already self-document via their string descriptions. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 93ab1de commit 75c0376

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/utils/permissions/__tests__/pathValidation.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ const describeIfWindows = isWindows ? describe : describe.skip
4848
// The fix runs `posixPathToWindowsPath` on Windows before resolution,
4949
// converting `/c/...` and `/cygdrive/c/...` to their `C:\...` form so the
5050
// validator's path space matches the shell's.
51+
/**
52+
* Tests that `validatePath` normalizes MinGW-style absolute paths
53+
* (`/c/Users/foo`, `/cygdrive/c/Users/foo`) to Windows paths
54+
* (`C:\\Users\\foo`) on Windows. Without this, the validator runs in
55+
* Windows host path space while the Git Bash shell runs in MinGW path
56+
* space, leading to a sandbox-escape class — see the comment block
57+
* at the top of this file for the full security rationale.
58+
*/
5159
describeIfWindows('validatePath MinGW path normalization', () => {
5260
test('converts /c/Users/foo/file.txt to C:\\Users\\foo\\file.txt', () => {
5361
const result = validatePath(
@@ -151,6 +159,16 @@ describeIfWindows('validatePath MinGW path normalization', () => {
151159
// Then we check that `/c/Users/foo/sensitive.txt` is denied with a
152160
// resolvedPath pointing at C:\Users\foo — proving the validator now sees
153161
// the same path the shell will write to.
162+
/**
163+
* Regression tests for the sandbox-escape class the MinGW-normalization
164+
* fix prevents. Without the fix, a MinGW-style path like
165+
* `/c/Users/foo/sensitive.txt` is resolved (by `path.resolve`) against
166+
* the current drive (`D:\c\Users\foo\sensitive.txt`) and compared to
167+
* the allowed-directories list — while Git Bash actually writes to
168+
* `C:\Users\foo\sensitive.txt`. With the fix, both sides of the
169+
* comparison use the same Windows path so a path the shell will write
170+
* to but isn't in any allowed dir is denied.
171+
*/
154172
describeIfWindows('validatePath sandbox escape regression', () => {
155173
test('MinGW path that escapes allowed dirs is denied at correct location', () => {
156174
// Without the fix, this would resolve to `D:\c\Users\foo\sensitive.txt`

src/utils/permissions/pathValidation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export type ResolvedPathCheckResult = PathCheckResult & {
3636
resolvedPath: string
3737
}
3838

39+
/**
40+
* Format a list of working directories for inclusion in permission-prompt
41+
* messages. When the list is short (≤ {@link MAX_DIRS_TO_LIST}) all
42+
* directories are listed; when longer, a truncated form is shown with
43+
* the remaining count.
44+
*/
3945
export function formatDirectoryList(directories: string[]): string {
4046
const dirCount = directories.length
4147

0 commit comments

Comments
 (0)