Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shellquote to unpack arguments to gitea serv #12624

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Changes from 2 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
33 changes: 18 additions & 15 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"code.gitea.io/gitea/modules/setting"

"github.com/dgrijalva/jwt-go"
"github.com/kballard/go-shellquote"
"github.com/unknwon/com"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -59,14 +60,6 @@ func setup(logPath string, debug bool) {
}
}

func parseCmd(cmd string) (string, string) {
ss := strings.SplitN(cmd, " ", 2)
if len(ss) != 2 {
return "", ""
}
return ss[0], strings.Replace(ss[1], "'/", "'", 1)
}

var (
allowedCommands = map[string]models.AccessMode{
"git-upload-pack": models.AccessModeRead,
Expand Down Expand Up @@ -126,25 +119,35 @@ func runServ(c *cli.Context) error {
return nil
}

verb, args := parseCmd(cmd)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
words, err := shellquote.Split(cmd)
if err != nil {
fail("Error parsing arguments", "Failed to parse arguments: %v", err)
}

if len(words) < 2 {
fail("Too few arguments", "Too few arguments in cmd: %s", cmd)
}

verb := words[0]
repoPath := words[1]
if repoPath[0] == '/' {
repoPath = repoPath[1:]
}

var lfsVerb string
if verb == lfsAuthenticateVerb {
if !setting.LFS.StartServer {
fail("Unknown git command", "LFS authentication request over SSH denied, LFS support is disabled")
}

argsSplit := strings.Split(args, " ")
if len(argsSplit) >= 2 {
args = strings.TrimSpace(argsSplit[0])
lfsVerb = strings.TrimSpace(argsSplit[1])
if len(words) > 2 {
lfsVerb = words[2]
}
}

repoPath := strings.ToLower(strings.Trim(args, "'"))
rr := strings.SplitN(repoPath, "/", 2)
if len(rr) != 2 {
fail("Invalid repository path", "Invalid repository path: %v", args)
fail("Invalid repository path", "Invalid repository path: %v", repoPath)
}

username := strings.ToLower(rr[0])
Expand Down