Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/sandbox/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import (
"os"
"os/exec"
"strings"
"testing"
)
Expand Down Expand Up @@ -41,6 +42,33 @@
}
}

// icacls is the one point every deny and cleanup ACL call goes through, so its
// error format is locked in here rather than only through Launch.
func TestWindowsIcaclsWrapsFailureAndReturnsNilOnSuccess(t *testing.T) {
missing := t.TempDir() + `\sg-definitely-missing`
cmd := exec.Command(systemBinary("icacls"), missing, "/deny", `*S-1-1-0:(F)`)

Check failure on line 49 in packages/sandbox/windows_test.go

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/sandbox/windows_test.go#L49

Detected non-static command inside Command.

Check failure on line 49 in packages/sandbox/windows_test.go

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

packages/sandbox/windows_test.go#L49

OS command injection is a critical vulnerability that can lead to a full system compromise as it may allow an adversary to pass in arbitrary commands or arguments to be executed.
captured, commandErr := cmd.CombinedOutput()
if commandErr == nil {
t.Fatalf("icacls on a missing path succeeded, want a failure (output %q)", captured)
}
wantOutput := strings.TrimSpace(string(captured))
if wantOutput == "" {
t.Fatal("icacls on a missing path produced no diagnostic output")
}

err := icacls(missing, "/deny", `*S-1-1-0:(F)`)
if err == nil {
t.Fatal("icacls on a missing path returned nil, want an error")
}
if !strings.HasPrefix(err.Error(), "icacls: ") || !strings.Contains(err.Error(), wantOutput) {
t.Errorf("icacls error = %q, want prefix %q and captured command output %q", err.Error(), "icacls: ", wantOutput)
}

if err := icacls(t.TempDir()); err != nil {
t.Errorf("icacls on an existing directory = %v, want nil", err)
}
}

func TestSystemBinaryFallsBackToBareNameWhenMissing(t *testing.T) {
t.Setenv("SystemRoot", `C:\sg-definitely-not-a-real-root`)
got := systemBinary("icacls")
Expand Down
Loading