Skip to content

Commit 2a01238

Browse files
committed
Remove dependency on archived cli/safeexec
The safeexec package was a workaround for a security issue in exec.LookPath on Windows, where the current working directory was searched before PATH entries. This was fixed in Go 1.19 (see golang/go#43724), making safeexec redundant. Since go-gh requires Go 1.25, replace all safeexec.LookPath calls with exec.LookPath from the standard library.
1 parent 55692c6 commit 2a01238

8 files changed

Lines changed: 8 additions & 20 deletions

File tree

gh.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"io"
1313
"os"
1414
"os/exec"
15-
16-
"github.com/cli/safeexec"
1715
)
1816

1917
// Exec invokes a gh command in a subprocess and captures the output and error streams.
@@ -52,7 +50,7 @@ func Path() (string, error) {
5250
if ghExe := os.Getenv("GH_PATH"); ghExe != "" {
5351
return ghExe, nil
5452
}
55-
return safeexec.LookPath("gh")
53+
return exec.LookPath("gh")
5654
}
5755

5856
func run(ctx context.Context, ghExe string, env []string, stdin io.Reader, stdout, stderr io.Writer, args []string) error {

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/charmbracelet/glamour v0.9.2-0.20250319212134-549f544650e3
1111
github.com/charmbracelet/lipgloss v1.1.1-0.20250319133953-166f707985bc
1212
github.com/cli/browser v1.3.0
13-
github.com/cli/safeexec v1.0.0
1413
github.com/cli/shurcooL-graphql v0.0.4
1514
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1615
github.com/henvic/httpretty v0.0.6

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQ
4040
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
4141
github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo=
4242
github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEfBTk=
43-
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
44-
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
4543
github.com/cli/shurcooL-graphql v0.0.4 h1:6MogPnQJLjKkaXPyGqPRXOI2qCsQdqNfUY1QSJu2GuY=
4644
github.com/cli/shurcooL-graphql v0.0.4/go.mod h1:3waN4u02FiZivIV+p1y4d0Jo1jc6BViMA73C+sZo2fk=
4745
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=

internal/git/git.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"os/exec"
7-
8-
"github.com/cli/safeexec"
97
)
108

119
func Exec(args ...string) (stdOut, stdErr bytes.Buffer, err error) {
@@ -18,7 +16,7 @@ func Exec(args ...string) (stdOut, stdErr bytes.Buffer, err error) {
1816
}
1917

2018
func path() (string, error) {
21-
return safeexec.LookPath("git")
19+
return exec.LookPath("git")
2220
}
2321

2422
func run(path string, env []string, args ...string) (stdOut, stdErr bytes.Buffer, err error) {

pkg/auth/auth.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/cli/go-gh/v2/internal/set"
1212
"github.com/cli/go-gh/v2/pkg/config"
13-
"github.com/cli/safeexec"
1413
)
1514

1615
const (
@@ -40,7 +39,7 @@ func TokenForHost(host string) (string, string) {
4039

4140
ghExe := os.Getenv("GH_PATH")
4241
if ghExe == "" {
43-
ghExe, _ = safeexec.LookPath("gh")
42+
ghExe, _ = exec.LookPath("gh")
4443
}
4544

4645
if ghExe != "" {

pkg/browser/browser.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
cliBrowser "github.com/cli/browser"
1212
"github.com/cli/go-gh/v2/pkg/config"
13-
"github.com/cli/safeexec"
1413
"github.com/google/shlex"
1514
)
1615

@@ -65,7 +64,7 @@ func (b *Browser) browse(url string, env []string) error {
6564
if err != nil {
6665
return err
6766
}
68-
launcherExe, err := safeexec.LookPath(launcherArgs[0])
67+
launcherExe, err := exec.LookPath(launcherArgs[0])
6968
if err != nil {
7069
return err
7170
}
@@ -128,8 +127,8 @@ func isPossibleProtocol(u string) (*url.URL, error) {
128127
}
129128

130129
// Disallow URLs that match executables found in the user path.
131-
exec, _ := safeexec.LookPath(u)
132-
if exec != "" {
130+
exe, _ := exec.LookPath(u)
131+
if exe != "" {
133132
return nil, fmt.Errorf("opening executables is unsupported: %s", u)
134133
}
135134

pkg/ssh/ssh.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"os/exec"
88
"strings"
99
"sync"
10-
11-
"github.com/cli/safeexec"
1210
)
1311

1412
type Translator struct {
@@ -57,7 +55,7 @@ func (t *Translator) resolve(hostname string) (string, error) {
5755
if t.sshPath == "" && t.sshPathErr == nil {
5856
lookPath := t.lookPath
5957
if lookPath == nil {
60-
lookPath = safeexec.LookPath
58+
lookPath = exec.LookPath
6159
}
6260
t.sshPath, t.sshPathErr = lookPath("ssh")
6361
}

pkg/ssh/ssh_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import (
99
"testing"
1010

1111
"github.com/MakeNowJust/heredoc"
12-
"github.com/cli/safeexec"
1312
)
1413

1514
func TestTranslator(t *testing.T) {
16-
if _, err := safeexec.LookPath("ssh"); err != nil {
15+
if _, err := exec.LookPath("ssh"); err != nil {
1716
t.Skip("no ssh found on system")
1817
}
1918

0 commit comments

Comments
 (0)