Skip to content

Commit a3bee13

Browse files
author
陈家名
authored
fix(vfs): reject blank local paths (#1460)
1 parent 6217bd2 commit a3bee13

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

internal/validate/path_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func TestSafeOutputPath_RejectsPathTraversalAndDangerousInput(t *testing.T) {
2626
{"unicode normal", "报告.xlsx", false},
2727
{"dot-dot resolves to cwd", "subdir/..", false},
2828

29+
// ── GIVEN: empty or blank paths → THEN: rejected ──
30+
{"empty path", "", true},
31+
{"blank path", " ", true},
32+
2933
// ── GIVEN: path traversal via .. → THEN: rejected ──
3034
{"dot-dot escape", "../../.ssh/authorized_keys", true},
3135
{"dot-dot mid path", "subdir/../../etc/passwd", true},

internal/vfs/localfileio/path.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func safePath(raw, flagName string) (string, error) {
6060
return "", err
6161
}
6262

63+
if strings.TrimSpace(raw) == "" {
64+
return "", fmt.Errorf("%s must not be empty", flagName)
65+
}
66+
6367
if isAbsolutePath(raw) {
6468
return "", fmt.Errorf("%s must be a relative path within the current directory, got %q (hint: cd to the target directory first, or use a relative path like ./filename)", flagName, raw)
6569
}

internal/vfs/localfileio/path_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func TestSafeOutputPath_RejectsPathTraversalAndDangerousInput(t *testing.T) {
2626
{"unicode normal", "报告.xlsx", false},
2727
{"dot-dot resolves to cwd", "subdir/..", false},
2828

29+
// ── GIVEN: empty or blank paths → THEN: rejected ──
30+
{"empty path", "", true},
31+
{"blank path", " ", true},
32+
2933
// ── GIVEN: path traversal via .. → THEN: rejected ──
3034
{"dot-dot escape", "../../.ssh/authorized_keys", true},
3135
{"dot-dot mid path", "subdir/../../etc/passwd", true},

0 commit comments

Comments
 (0)