Skip to content

Commit c147421

Browse files
authored
Merge commit from fork
1 parent 85e19f1 commit c147421

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

pkg/backend/repo.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ import (
2525
"github.com/charmbracelet/soft-serve/pkg/webhook"
2626
)
2727

28+
func validateImportRemote(remote string) error {
29+
endpoint, err := lfs.NewEndpoint(remote)
30+
if err != nil || endpoint.Host == "" {
31+
return proto.ErrInvalidRemote
32+
}
33+
34+
return nil
35+
}
36+
2837
// CreateRepository creates a new repository.
2938
//
3039
// It implements backend.Backend.
@@ -96,6 +105,11 @@ func (d *Backend) ImportRepository(_ context.Context, name string, user proto.Us
96105
return nil, err
97106
}
98107

108+
remote = utils.Sanitize(remote)
109+
if err := validateImportRemote(remote); err != nil {
110+
return nil, err
111+
}
112+
99113
rp := filepath.Join(d.repoPath(name))
100114

101115
tid := "import:" + name

pkg/proto/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
var (
88
// ErrUnauthorized is returned when the user is not authorized to perform action.
99
ErrUnauthorized = errors.New("unauthorized")
10+
// ErrInvalidRemote is returned when a repository import remote is invalid.
11+
ErrInvalidRemote = errors.New("remote must be a network URL")
1012
// ErrFileNotFound is returned when the file is not found.
1113
ErrFileNotFound = errors.New("file not found")
1214
// ErrRepoNotFound is returned when a repository is not found.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# vi: set ft=conf
2+
3+
[windows] skip 'uses a raw server filesystem path as the import remote'
4+
5+
# start soft serve
6+
exec soft serve &
7+
# wait for SSH server to start
8+
ensureserverrunning SSH_PORT
9+
10+
# create a private repo and a second user
11+
soft repo create secret -p
12+
soft user create user1 --key "$USER1_AUTHORIZED_KEY"
13+
14+
# seed the private repo with content
15+
git clone ssh://localhost:$SSH_PORT/secret secret
16+
mkfile ./secret/SECRET.txt 'top secret'
17+
git -C secret add -A
18+
git -C secret commit -m 'first'
19+
git -C secret push origin HEAD
20+
21+
# user1 cannot read the private repo directly
22+
! usoft repo info secret
23+
stderr 'repository not found'
24+
25+
# user1 also must not be able to import the server-local repo path
26+
! usoft repo import stolen "$DATA_PATH/repos/secret.git" --lfs-endpoint http://example.com
27+
stderr 'remote must be a network URL'
28+
29+
# the failed import must not create a readable repo
30+
! usoft repo info stolen
31+
stderr 'repository not found'
32+
33+
[windows] stopserver
34+
[windows] ! stderr .

0 commit comments

Comments
 (0)