publish / publish (push) Successful in 2m53s
The host connector answers filesystem_usage, directory_sizes and old_files on configured hosts over SSH with pinned host keys, dialling through the egress tunnel when confined. The sops engine decrypts with the sops library instead of the CLI, takes its file from settings and an age identity from its secrets.
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"os/exec"
|
|
"testing"
|
|
)
|
|
|
|
// TestLookupInputCannotEscapeItsArgument guards the host connector's only
|
|
// boundary with the remote shell: ssh hands commands to a shell, so a path
|
|
// from the model must reach the command as exactly one argument, whatever it
|
|
// contains, and a path that isn't absolute or carries control characters is
|
|
// refused before any command is built.
|
|
func TestLookupInputCannotEscapeItsArgument(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
path string
|
|
refused bool
|
|
}{
|
|
{name: "plain path", path: "/tmp/runner"},
|
|
{name: "spaces", path: "/tmp/my dir"},
|
|
{name: "single quote breakout", path: "/tmp/x'; printf INJECTED; printf '"},
|
|
{name: "command substitution", path: "/tmp/$(printf INJECTED)`printf INJECTED`"},
|
|
{name: "option lookalike", path: "/-rf"},
|
|
{name: "relative path", path: "tmp", refused: true},
|
|
{name: "newline", path: "/tmp\n; id", refused: true},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p, err := checkPath(tt.path)
|
|
if tt.refused {
|
|
if err == nil {
|
|
t.Fatalf("checkPath(%q) accepted it", tt.path)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := exec.CommandContext(t.Context(), "sh", "-c", "printf '%s' "+quote(p)).Output()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(out) != p {
|
|
t.Fatalf("the shell saw %q, want the single argument %q", out, p)
|
|
}
|
|
})
|
|
}
|
|
}
|