Skip to content

Commit 9bddc73

Browse files
committed
Fix(security): Prevent path traversal in LaunchEditor
The LaunchEditor function was vulnerable to path traversal (G304, CWE-22). The 'fileName' parameter could be manipulated to access files outside the intended local storage root. The fix adds a check to ensure that the resolved path remains within the local storage root, preventing unauthorized file access.
1 parent 353ed37 commit 9bddc73

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

commands/input/input.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"os/exec"
1414
"path/filepath"
15+
"strings"
1516

1617
"github.com/go-git/go-billy/v5/util"
1718

@@ -51,6 +52,9 @@ func LaunchEditor(repo repository.RepoCommonStorage, fileName string) (string, e
5152
// bypass the interface but that's ok: we need that because we are communicating
5253
// the absolute path to an external program
5354
path := filepath.Join(repo.LocalStorage().Root(), fileName)
55+
if !strings.HasPrefix(path, repo.LocalStorage().Root()) {
56+
return "", fmt.Errorf("security: path traversal attempt")
57+
}
5458

5559
cmd, err := startInlineCommand(editor, path)
5660
if err != nil {

0 commit comments

Comments
 (0)