Skip to content

Commit

Permalink
fix bad permission regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-kiselenko committed Nov 2, 2024
1 parent ed62d90 commit ecee8ec
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"log/slog"
"regexp"
"strings"

"smolgit/pkg/config"
Expand Down Expand Up @@ -112,8 +113,11 @@ func (srv *Server) cmdRepo(s ssh.Session, cmd []string) int {

// TODO better permissions check
if user.Permissions != "*" {
if !strings.HasPrefix(repoName[1:], userName) {
slog.Error("wrong repo prefix", "repoName", repoName, "user", user)
r, _ := regexp.Compile(user.Permissions)
repoNamespace := strings.Split(repoName, "/")
ns := strings.Join(repoNamespace[1:len(repoNamespace)-1], "")
if !r.MatchString(ns) {
slog.Error("wrong repo prefix", "repoName", repoName, "ns", ns, "userName", userName, "permission", user.Permissions)
_, _ = io.WriteString(s.Stderr(), "Permission denied\r\n")
return 1
}
Expand Down

0 comments on commit ecee8ec

Please sign in to comment.