diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-12-21 09:37:48 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-02-08 14:40:30 -0800 |
commit | 09f32d4f845511638ec162be426eeffb51036b6b (patch) | |
tree | 1f628ef91273e37da8bc5f4d901f1a91ba865fa6 /pkg/secureexec | |
parent | 6f0f70bd924b444a5f755046c1da25c0f31e352e (diff) |
add secureexec file for getting around windows checking for a binary first in the current dir
Diffstat (limited to 'pkg/secureexec')
-rw-r--r-- | pkg/secureexec/secureexec_default.go | 11 | ||||
-rw-r--r-- | pkg/secureexec/secureexec_windows.go | 30 |
2 files changed, 41 insertions, 0 deletions
diff --git a/pkg/secureexec/secureexec_default.go b/pkg/secureexec/secureexec_default.go new file mode 100644 index 000000000..1992358ce --- /dev/null +++ b/pkg/secureexec/secureexec_default.go @@ -0,0 +1,11 @@ +// +build !windows + +package secureexec + +import ( + "os/exec" +) + +func Command(name string, args ...string) *exec.Cmd { + return exec.Command(name, args...) +} diff --git a/pkg/secureexec/secureexec_windows.go b/pkg/secureexec/secureexec_windows.go new file mode 100644 index 000000000..537e0bfc1 --- /dev/null +++ b/pkg/secureexec/secureexec_windows.go @@ -0,0 +1,30 @@ +// +build windows + +package secureexec + +import ( + "os/exec" + + "github.com/cli/safeexec" +) + +// calling exec.Command directly on a windows machine poses a security risk due to +// the current directory being searched first before any directories in the PATH +// variable, meaning you might clone a repo that contains a program called 'git' +// which does something malicious when executed. + +// see https://github.com/golang/go/issues/38736 for more context. We'll likely +// be able to just throw out this code and switch to the official solution when it exists. + +// I consider this a minor security concern because you're just as vulnerable if +// you call `git status` from the command line directly but no harm in playing it +// safe. + +func Command(name string, args ...string) *exec.Cmd { + bin, err := safeexec.LookPath(name) + if err != nil { + bin = name + } + + return exec.Command(bin, args...) +} |