MCPcopy Create free account
hub / github.com/appleboy/easyssh-proxy / TestShellQuote

Function TestShellQuote

easyssh_test.go:674–693  ·  view source on GitHub ↗

TestShellQuote pins the contract of the helper used to defend the SCP code path against remote command injection. If any of these cases regress, an attacker-controlled target path could execute arbitrary commands on the remote host.

(t *testing.T)

Source from the content-addressed store, hash-verified

672// attacker-controlled target path could execute arbitrary commands on the
673// remote host.
674func TestShellQuote(t *testing.T) {
675 cases := []struct {
676 in, want string
677 }{
678 {"", "''"},
679 {"foo", "'foo'"},
680 {"foo bar", "'foo bar'"},
681 {"foo/bar.txt", "'foo/bar.txt'"},
682 {"foo'bar", `'foo'\''bar'`},
683 {"'", `''\'''`},
684 {"$(rm -rf /)", "'$(rm -rf /)'"},
685 {"`id`", "'`id`'"},
686 {"a;b|c&d", "'a;b|c&d'"},
687 {`"quoted"`, `'"quoted"'`},
688 }
689 for _, c := range cases {
690 got := shellQuote(c.in)
691 assert.Equal(t, c.want, got, "shellQuote(%q)", c.in)
692 }
693}
694
695// TestWriteFileRejectsInvalidTargetName guards the SCP protocol-injection
696// fix: a target filename containing newline/CR/NUL must be rejected before

Callers

nothing calls this directly

Calls 1

shellQuoteFunction · 0.85

Tested by

no test coverage detected