Skip to content

Commit e47d380

Browse files
committed
fix: prohibit the use of slashes in clone identifiers (#558)
1 parent 72922c9 commit e47d380

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Diff for: engine/internal/srv/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (s *Server) Reload(cfg srvCfg.Config) {
187187

188188
// InitHandlers initializes handler functions of the HTTP server.
189189
func (s *Server) InitHandlers() {
190-
r := mux.NewRouter().StrictSlash(true)
190+
r := mux.NewRouter().StrictSlash(true).UseEncodedPath()
191191

192192
authMW := mw.NewAuth(s.Config.VerificationToken, s.Platform)
193193

Diff for: engine/internal/validator/validator.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package validator
77

88
import (
99
"fmt"
10+
"strings"
1011

1112
"github.com/pkg/errors"
1213
passwordvalidator "github.com/wagslane/go-password-validator"
@@ -34,6 +35,10 @@ func (v Service) ValidateCloneRequest(cloneRequest *types.CloneCreateRequest) er
3435
return errors.New("missing DB password")
3536
}
3637

38+
if cloneRequest.ID != "" && strings.Contains(cloneRequest.ID, "/") {
39+
return errors.New("Clone ID cannot contain slash ('/'). Please choose another ID")
40+
}
41+
3742
if err := passwordvalidator.Validate(cloneRequest.DB.Password, minEntropyBits); err != nil {
3843
return fmt.Errorf("password validation: %w", err)
3944
}

Diff for: engine/internal/validator/validator_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func TestValidationCloneRequestErrors(t *testing.T) {
5555
createRequest: types.CloneCreateRequest{DB: &types.DatabaseRequest{Password: "password"}},
5656
error: "missing DB username",
5757
},
58+
{
59+
createRequest: types.CloneCreateRequest{
60+
DB: &types.DatabaseRequest{Username: "user", Password: "password"},
61+
ID: "test/ID",
62+
},
63+
error: "Clone ID cannot contain slash ('/'). Please choose another ID",
64+
},
5865
}
5966

6067
for _, tc := range testCases {

0 commit comments

Comments
 (0)