Skip to content

Commit

Permalink
Merge pull request #28 from LiilyZhang/zhangl/invalidCharCheck
Browse files Browse the repository at this point in the history
Issue 1137 - prevent <> in put body
  • Loading branch information
dabooz authored Aug 20, 2019
2 parents a2d357e + fd6363f commit ff53afe
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 93 deletions.
15 changes: 15 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,21 @@ func BlockUntilNoRunningGoRoutines() {
// IsValidName checks if the string only contains letters, digits, and !@#%^*-_.~
var IsValidName = regexp.MustCompile(`^[a-zA-Z0-9|!|@|#|$|^|*|\-|_|.|~]+$`).MatchString

// ValidateDestinationListInput checks if destinationsList contains < or >, to avoid injecting html like tags from user
func ValidateDestinationListInput(destinationsList []string) (bool, SyncServiceError) {
if len(destinationsList) == 0 {
return true, nil
}

for _, destination := range destinationsList {
if strings.ContainsAny(destination, "<") || strings.ContainsAny(destination, ">") {
message := fmt.Sprintf("destinationsList contains unsupported char: < or > (%+v)", destination)
return false, &InvalidRequest{Message: message}
}
}
return true, nil
}

func init() {
Version.Major = 1
Version.Minor = 0
Expand Down
3 changes: 3 additions & 0 deletions core/base/apiModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func UpdateObject(orgID string, objectType string, objectID string, metaData com
if metaData.DestinationsList != nil && metaData.DestType != "" {
return &common.InvalidRequest{Message: "Both destinations list and destination type are specified"}
}
if validatedDestList, _ := common.ValidateDestinationListInput(metaData.DestinationsList); validatedDestList == false {
return &common.InvalidRequest{Message: "Unsupported char <, > in destinationsList."}
}

if metaData.DestinationPolicy != nil {
if metaData.DestType != "" {
Expand Down
5 changes: 4 additions & 1 deletion core/base/apiServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,12 +1291,15 @@ func handleObjectDestinations(orgID string, objectType string, objectID string,
}
var destinationsList []string
err := json.NewDecoder(request.Body).Decode(&destinationsList)
if err == nil {
inputValidated, validateErr := common.ValidateDestinationListInput(destinationsList)
if inputValidated && err == nil {
if err := UpdateObjectDestinations(orgID, objectType, objectID, destinationsList); err == nil {
writer.WriteHeader(http.StatusNoContent)
} else {
communications.SendErrorResponse(writer, err, "", 0)
}
} else if !inputValidated {
communications.SendErrorResponse(writer, validateErr, "Unsupported char in destinationsList. Error: ", http.StatusBadRequest)
} else {
communications.SendErrorResponse(writer, err, "Invalid JSON for update. Error: ", http.StatusBadRequest)
}
Expand Down
Loading

0 comments on commit ff53afe

Please sign in to comment.