1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
diff --git a/internal/ssh/wish.go b/internal/ssh/wish.go
index 6bdb16748ec5499af03d1f4683800da71eb612ab..64f6be07be25325f7b183186cad75b9bfce16ca6 100644
--- a/internal/ssh/wish.go
+++ b/internal/ssh/wish.go
@@ -63,6 +63,10 @@ // checked for access on a per repo basis for a ssh.Session public key.
// Hooks.Push and Hooks.Fetch will be called on successful completion of
// their commands.
func Middleware(repoDir string, cloneURL string, port int, gh Hooks) wish.Middleware {
+ repoDirAbs, err := filepath.Abs(repoDir)
+ if err != nil {
+ repoDirAbs = repoDir
+ }
return func(sh ssh.Handler) ssh.Handler {
return func(s ssh.Session) {
sess := Session{s: s}
@@ -75,6 +79,11 @@ // repo should be in the form of "repo.git" or "user/repo.git"
repo := strings.TrimSuffix(strings.TrimPrefix(cmd[1], "/"), "/")
repo = filepath.Clean(repo)
if n := strings.Count(repo, "/"); n > 1 {
+ Fatal(s, ErrInvalidRepo)
+ return
+ }
+ // resolved path shouldn't escape repoDir(Abs)
+ if abs := filepath.Join(repoDirAbs, repo); !strings.HasPrefix(abs, repoDirAbs+string(filepath.Separator)) {
Fatal(s, ErrInvalidRepo)
return
}
|