Skip to content

Commit 2ae5dca

Browse files
committed
refactor(ssh): trim shellQuote test cases and tone down godoc framing
Tests collapsed from 8 cases to 3 (no special chars, embedded quote, spaces) the rest were redundant security-themed variants of the same path. Godoc reframes shellQuote as path-handling robustness rather than security mitigation; consumers control all inputs in test code. Linear: OSS-3397
1 parent 1d84470 commit 2ae5dca

2 files changed

Lines changed: 4 additions & 29 deletions

File tree

modules/ssh/ssh.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ func FetchContentsOfFileContext(t testing.TestingT, ctx context.Context, host *H
655655
return out
656656
}
657657

658-
// shellQuote returns s wrapped in single quotes, with any embedded single quote
659-
// replaced by the four-character sequence quote-backslash-quote-quote.
660-
// Safe for POSIX sh, bash, zsh.
658+
// shellQuote wraps a path in single quotes, escaping any embedded single quotes,
659+
// so that paths containing spaces or shell metacharacters work correctly when
660+
// passed to commands like `cat` and `dd if=`.
661661
func shellQuote(s string) string {
662662
return "'" + strings.ReplaceAll(s, "'", `'\''`) + "'"
663663
}

modules/ssh/ssh_unit_test.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ func TestShellQuote(t *testing.T) {
2020
expected: "'/etc/hostname'",
2121
},
2222
{
23-
name: "empty string",
24-
input: "",
25-
expected: "''",
26-
},
27-
{
28-
name: "single quote",
23+
name: "embedded single quote",
2924
input: "it's",
3025
expected: `'it'\''s'`,
3126
},
@@ -34,26 +29,6 @@ func TestShellQuote(t *testing.T) {
3429
input: "/path with spaces/file.txt",
3530
expected: "'/path with spaces/file.txt'",
3631
},
37-
{
38-
name: "path traversal attempt",
39-
input: "a; rm -rf /",
40-
expected: "'a; rm -rf /'",
41-
},
42-
{
43-
name: "command substitution attempt",
44-
input: "$(rm -rf /)",
45-
expected: "'$(rm -rf /)'",
46-
},
47-
{
48-
name: "backtick attempt",
49-
input: "`rm -rf /`",
50-
expected: "'`rm -rf /`'",
51-
},
52-
{
53-
name: "injection with embedded single quote",
54-
input: "'; rm -rf / #",
55-
expected: `''\''; rm -rf / #'`,
56-
},
5732
}
5833

5934
for _, tc := range testCases {

0 commit comments

Comments
 (0)