Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Validate user-provided entity versions are url safe (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrogan authored Mar 13, 2023
1 parent a4f1322 commit 7e8433d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/validation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validation

import (
"net/url"
"strconv"
"strings"

Expand All @@ -22,6 +23,9 @@ var entityToResourceType = map[common.Entity]core.ResourceType{
common.LaunchPlan: core.ResourceType_LAUNCH_PLAN,
}

// See https://www.rfc-editor.org/rfc/rfc3986#section-2.2
var uriReservedChars = "!*'();:@&=+$,/?#[]"

func ValidateEmptyStringField(field, fieldName string) error {
if field == "" {
return shared.GetMissingArgumentError(fieldName)
Expand Down Expand Up @@ -132,6 +136,10 @@ func ValidateVersion(version string) error {
if err := ValidateEmptyStringField(version, shared.Version); err != nil {
return err
}
sanitizedVersion := url.QueryEscape(version)
if !strings.EqualFold(sanitizedVersion, version) {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument, "version [%s] must be url safe, cannot contains chars [%s]", version, uriReservedChars)
}
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions flyteadmin/pkg/manager/impl/validation/validation_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validation

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -174,6 +175,14 @@ func TestValidateDescriptionEntityListRequest(t *testing.T) {
func TestValidateVersion(t *testing.T) {
err := ValidateVersion("")
assert.EqualError(t, err, "missing version")

t.Run("url safe versions only", func(t *testing.T) {
assert.NoError(t, ValidateVersion("Foo123"))
for _, reservedChar := range uriReservedChars {
invalidVersion := fmt.Sprintf("foo%c", reservedChar)
assert.NotNil(t, ValidateVersion(invalidVersion))
}
})
}

func TestValidateListTaskRequest(t *testing.T) {
Expand Down

0 comments on commit 7e8433d

Please sign in to comment.